create constants

This commit is contained in:
Christos Giannouris 2022-11-14 13:42:04 +01:00
parent fcdbd79e23
commit 8c0a90a544
2 changed files with 23 additions and 14 deletions

View File

@ -1,3 +1,5 @@
import CNST from "./util/constants";
export class Item { export class Item {
name: string; name: string;
sellIn: number; sellIn: number;
@ -19,46 +21,47 @@ export class GildedRose {
updateQuality() { updateQuality() {
for (let i = 0; i < this.items.length; i++) { 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 ([CNST.AGED_BRIE, CNST.BCST_TAF].includes(this.items[i].name)) {
if (this.items[i].quality > 0) { if (this.items[i].quality > 0) {
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { if (this.items[i].name != CNST.SULFURAS) {
this.items[i].quality = this.items[i].quality - 1 this.items[i].quality = this.items[i].quality - 1;
} }
} }
} else { } else {
if (this.items[i].quality < 50) { if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1 this.items[i].quality = this.items[i].quality + 1;
if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') { if (this.items[i].name == CNST.BCST_TAF) {
if (this.items[i].sellIn < 11) { if (this.items[i].sellIn < 11) {
if (this.items[i].quality < 50) { if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1 this.items[i].quality = this.items[i].quality + 1;
} }
} }
if (this.items[i].sellIn < 6) { if (this.items[i].sellIn < 6) {
if (this.items[i].quality < 50) { if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1 this.items[i].quality = this.items[i].quality + 1;
} }
} }
} }
} }
} }
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { if (this.items[i].name != CNST.SULFURAS) {
this.items[i].sellIn = this.items[i].sellIn - 1; this.items[i].sellIn = this.items[i].sellIn - 1;
} }
if (this.items[i].sellIn < 0) { if (this.items[i].sellIn < 0) {
if (this.items[i].name != 'Aged Brie') { if (this.items[i].name != CNST.AGED_BRIE) {
if (this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') { if (this.items[i].name != CNST.BCST_TAF) {
if (this.items[i].quality > 0) { if (this.items[i].quality > 0) {
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { if (this.items[i].name != CNST.SULFURAS) {
this.items[i].quality = this.items[i].quality - 1 this.items[i].quality = this.items[i].quality - 1;
} }
} }
} else { } else {
this.items[i].quality = this.items[i].quality - this.items[i].quality this.items[i].quality =
this.items[i].quality - this.items[i].quality;
} }
} else { } else {
if (this.items[i].quality < 50) { if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1 this.items[i].quality = this.items[i].quality + 1;
} }
} }
} }

View File

@ -0,0 +1,6 @@
const AGED_BRIE = "Aged Brie";
const BCST_TAF = "Backstage passes to a TAFKAL80ETC concert";
const SULFURAS = "Sulfuras, Hand of Ragnaros";
const SULFURAS_HAND = "Sulfuras, Hand of Ragnaros";
export default { AGED_BRIE, BCST_TAF, SULFURAS, SULFURAS_HAND };