-
Notifications
You must be signed in to change notification settings - Fork 0
Add logic for Conjured Mana Cake #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1c364d8
975df00
9d61329
504123d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,50 +19,52 @@ export class GildedRose { | |
|
|
||
| updateQuality() { | ||
| for (let i = 0; i < this.items.length; i++) { | ||
| if (this.items[i].name === 'Sulfuras, Hand of Ragnaros') { | ||
| if (this.items[i].name === "Sulfuras, Hand of Ragnaros") { | ||
| continue; | ||
| } | ||
|
|
||
| this.items[i].sellIn = this.items[i].sellIn - 1; | ||
|
|
||
| if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') { | ||
| if (this.items[i].sellIn < 0) { | ||
| this.items[i].quality = 0 | ||
| continue; | ||
| } | ||
| switch (this.items[i].name) { | ||
| case "Backstage passes to a TAFKAL80ETC concert": | ||
| if (this.items[i].sellIn < 0) { | ||
| this.items[i].quality = 0; | ||
| break; | ||
| } | ||
|
|
||
| if (this.items[i].sellIn >= 10) { | ||
| this.items[i].quality = this.items[i].quality + 1 | ||
| } | ||
| else if (this.items[i].sellIn >= 5) { | ||
| this.items[i].quality = this.items[i].quality + 2 | ||
| } | ||
| else { | ||
| this.items[i].quality = this.items[i].quality + 3 | ||
| } | ||
| if (this.items[i].sellIn >= 10) { | ||
| this.items[i].quality = this.items[i].quality + 1; | ||
| } else if (this.items[i].sellIn >= 5) { | ||
| this.items[i].quality = this.items[i].quality + 2; | ||
| } else { | ||
| this.items[i].quality = this.items[i].quality + 3; | ||
| } | ||
|
|
||
| if (this.items[i].quality > 50) { | ||
| this.items[i].quality = 50 | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
|
|
||
| if (this.items[i].name === 'Aged Brie') { | ||
| if (this.items[i].sellIn < 0) { | ||
| this.items[i].quality = Math.min(this.items[i].quality + 2, 50); | ||
| } | ||
| else { | ||
| this.items[i].quality = Math.min(this.items[i].quality + 1, 50); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| if (this.items[i].sellIn < 0) { | ||
| this.items[i].quality = Math.max(0, this.items[i].quality - 2); | ||
| } | ||
| else { | ||
| this.items[i].quality = Math.max(0, this.items[i].quality - 1); | ||
| if (this.items[i].quality > 50) { | ||
| this.items[i].quality = 50; | ||
| } | ||
| break; | ||
| case "Aged Brie": | ||
| if (this.items[i].sellIn < 0) { | ||
| this.items[i].quality = Math.min(this.items[i].quality + 2, 50); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could pull out values like 50 here into well-named consts to increase clarity and reduce risk of typos |
||
| } else { | ||
| this.items[i].quality = Math.min(this.items[i].quality + 1, 50); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could create a helper function for clamping values so don't need to repeatedly use |
||
| } | ||
| break; | ||
| case "Conjured Mana Cake": | ||
| if (this.items[i].sellIn < 0) { | ||
| this.items[i].quality = Math.max(0, this.items[i].quality - 4); | ||
| } else { | ||
| this.items[i].quality = Math.max(0, this.items[i].quality - 2); | ||
| } | ||
| break; | ||
| default: | ||
| if (this.items[i].sellIn < 0) { | ||
| this.items[i].quality = Math.max(0, this.items[i].quality - 2); | ||
| } else { | ||
| this.items[i].quality = Math.max(0, this.items[i].quality - 1); | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| return this.items; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could consider doing something like
for (const item of this.items)and then referring toitemso you don't have to keep repeatingthis.items[i]