Refactor: add handleQuality, handleSellIn of item classes

This commit is contained in:
Gayun00 2023-09-25 23:29:27 +09:00
parent 5d670ac672
commit 77c82c95b3
2 changed files with 21 additions and 5 deletions

View File

@ -9,12 +9,14 @@ export class GildedRose {
} }
handleSellIn(item) { handleSellIn(item) {
//
if (item.name != ITEMS.SURFRAS) { if (item.name != ITEMS.SURFRAS) {
item.sellIn -= 1; item.sellIn -= 1;
} }
if (item.sellIn >= 0) return; if (item.sellIn >= 0) return;
if (item.quality >= 50) return; if (item.quality >= 50) return;
//
switch (item.name) { switch (item.name) {
case ITEMS.BRIE: case ITEMS.BRIE:
item.quality = item.quality + 1; item.quality = item.quality + 1;
@ -29,6 +31,7 @@ export class GildedRose {
} }
handlePassesQuality(item) { handlePassesQuality(item) {
//
if (item.name !== ITEMS.PASSES) return; if (item.name !== ITEMS.PASSES) return;
if (6 <= item.sellIn && item.sellIn < 11) { if (6 <= item.sellIn && item.sellIn < 11) {
item.quality += 1; item.quality += 1;
@ -40,6 +43,7 @@ export class GildedRose {
} }
handleQuality(item) { handleQuality(item) {
//
switch (item.name) { switch (item.name) {
case ITEMS.PASSES: case ITEMS.PASSES:
this.handlePassesQuality(item); this.handlePassesQuality(item);

View File

@ -23,11 +23,12 @@ export class AgedBrie extends Item {
super("Aged Brie", sellIn, quality); super("Aged Brie", sellIn, quality);
} }
handleQuality() { handleQuality() {
// this.quality++;
this.quality++;
} }
handleSellIn() { handleSellIn() {
// this.sellIn--;
} }
} }
@ -37,11 +38,20 @@ export class Passes extends Item {
} }
handleQuality() { handleQuality() {
// this.quality--;
if (6 <= this.sellIn && this.sellIn < 11) {
this.quality += 1;
}
if (this.sellIn < 6) {
this.quality += 2;
}
this.quality++;
} }
handleSellIn() { handleSellIn() {
// this.sellIn--;
} }
} }
@ -50,7 +60,9 @@ export class Surfras extends Item {
super("Sulfuras, Hand of Ragnaros", sellIn, quality); super("Sulfuras, Hand of Ragnaros", sellIn, quality);
} }
handleQuality() { handleQuality() {
// this.quality = 0;
this.quality--;
this.quality++;
} }
handleSellIn() { handleSellIn() {