Skip to content

Commit

Permalink
Update gilded-rose.ts: fixes and refactoring
Browse files Browse the repository at this point in the history
- Added logic for handling conjured items.
- Improved flow of logic in the if else statements.
- Added code comments.
- Other minor refactoring changes.
  • Loading branch information
TeeMee123 authored Jun 25, 2024
1 parent e2abba7 commit 1fb9aaf
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions TypeScript/app/gilded-rose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,61 @@ export class GildedRose {
this.items = items;
}

isItemConjured(itemName: string): boolean {
return itemName.startsWith("Conjured");
}

updateQuality() {
for (let i = 0; i < this.items.length; i++) {
if (this.items[i].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
if (this.items[i].quality > 0) {
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].quality = this.items[i].quality - 1
}
}
} else {
if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1

// Process quality increase exceptions
if (this.items[i].name == 'Aged Brie' || this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') {
if (this.items[i].quality <= 49) {
this.items[i].quality++;
// Process additional potential quality increases for backstage passes
if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') {
if (this.items[i].sellIn < 11) {
if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1
}
if (this.items[i].sellIn <= 10 && this.items[i].quality <= 49) {
this.items[i].quality++;
}
if (this.items[i].sellIn < 6) {
if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1
}
if (this.items[i].sellIn <= 5 && this.items[i].quality <= 49) {
this.items[i].quality++;
}
}
}
} else {
if (this.items[i].quality > 0) {
// Decrease quality except in certain cases
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].quality = this.items[i].quality - 1;
}
}
}

// Decrease 'sell in' value except in certain cases
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].sellIn = this.items[i].sellIn - 1;
let expiryRate = 1;
if(this.isItemConjured(this.items[i].name)) {
expiryRate = 2;
}
this.items[i].sellIn -= expiryRate;
}

// Process additional quality change due to expiry
if (this.items[i].sellIn < 0) {
if (this.items[i].name != 'Aged Brie') {
if (this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
if (this.items[i].quality > 0) {
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].quality = this.items[i].quality - 1
this.items[i].quality--;
}
}
// Process some exceptional cases
} else {
this.items[i].quality = this.items[i].quality - this.items[i].quality
this.items[i].quality = 0;
}
} else {
if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1
if (this.items[i].quality <= 49) {
this.items[i].quality++;
}
}
}
Expand Down

0 comments on commit 1fb9aaf

Please sign in to comment.