Commit e3923306 by 李楚霏

task-8-if-conditions -- refactor updateQuality

function And refactor updateQualityAfterExpired Fun simply
parent 13c57e5a
import { Item } from "./item";
import { Item } from './item'
export class AgedBrie extends Item{
constructor(sell_in, quality){
super(sell_in, quality);
this.name = 'Aged Brie';
};
constructor(sell_in, quality) {
super(sell_in, quality)
this.name = 'Aged Brie'
}
isAgedBrie() {
return 'Aged Brie';
isAgedBrie() {
return 'Aged Brie'
}
updateQuality(item) {
if (item.quality < 50) {
item.quality = item.quality + 1
}
}
\ No newline at end of file
}
}
import { Item } from "./item";
import { Item } from './item'
export class BackstagePass extends Item{
constructor(sell_in, quality) {
super(sell_in, quality);
this.name = 'Backstage passes to a TAFKAL80ETC concert';
}
isBackStage() {
return 'Backstage passes to a TAFKAL80ETC concert';
constructor(sell_in, quality) {
super(sell_in, quality)
this.name = 'Backstage passes to a TAFKAL80ETC concert'
}
isBackStage() {
return 'Backstage passes to a TAFKAL80ETC concert'
}
updateQuality(item) {
if (item.name === this.isBackStagePass()) {
if (item.quality < 50) {
if (item.sell_in < 11) {
if (item.quality < 50) {
item.quality = item.quality + 1
}
}
if (item.sell_in < 6) {
if (item.quality < 50) {
item.quality = item.quality + 1;
}
}
}
return;
}
}
updateQualityAfterExpired(item) {
if (item.quality < 50) {
item.quality = item.quality + 1
}
}
\ No newline at end of file
}
}
import { Item } from "./item";
import { Item } from './item'
export class Sulfuras extends Item{
constructor(sell_in, quality) {
super(sell_in, quality);
this.name = 'Sulfuras, Hand of Ragnaros';
}
constructor(sell_in, quality) {
super(sell_in, quality)
this.name = 'Sulfuras, Hand of Ragnaros'
}
isSulfuras() {
return 'Sulfuras, Hand of Ragnaros';
}
}
\ No newline at end of file
isSulfuras() {
return 'Sulfuras, Hand of Ragnaros'
}
updateQuality(item) {}
}
......@@ -10,15 +10,15 @@ export class Item {
}
isAgedBrie() {
return 'Aged Brie';
return 'Aged Brie'
}
isSulfuras() {
return 'Sulfuras, Hand of Ragnaros';
return 'Sulfuras, Hand of Ragnaros'
}
isBackStagePass() {
return 'Backstage passes to a TAFKAL80ETC concert';
return 'Backstage passes to a TAFKAL80ETC concert'
}
toString() {
......@@ -26,84 +26,62 @@ export class Item {
}
createBackStagePass(sell_in, quality) {
new BackStagePass('Backstage passes to a TAFKAL80ETC concert', sell_in, quality);
new BackStagePass(
'Backstage passes to a TAFKAL80ETC concert',
sell_in,
quality
)
}
createSulfuras(sell_in, quality) {
new Sulfuras(sell_in, quality);
new Sulfuras(sell_in, quality)
}
createNormalItem(name, sell_in, quality) {
new Item(name, sell_in, quality);
new Item(name, sell_in, quality)
}
createAgedBrie(sell_in, quality) {
new AgedBrie(sell_in, quality);
new AgedBrie(sell_in, quality)
}
_updateItem(item) {
this.updateQualityInOneDay(item);
this.updateSellInInOneDay(item);
this.updateQualityAfterDevaluation(item);
this.updateQuality(item)
this.updateSellIn(item)
this.updateQualityAfterExpired(item)
}
updateQualityInOneDay(item) {
if (item.name != this.isAgedBrie() && item.name != this.isBackStagePass()) {
if (item.quality > 0) {
if (item.name != this.isSulfuras()) {
item.quality = item.quality - 1
}
}
} else {
if (item.quality < 50) {
this.updateQualityAfterExpired(item)
if (item.name == this.isBackStagePass()) {
if (item.sell_in < 11) {
if (item.quality < 50) {
this.updateQualityAfterExpired(item);
}
}
if (item.sell_in < 6) {
if (item.quality < 50) {
this.updateQualityAfterExpired(item);
}
}
}
}
updateQuality(item) {
if (item.quality > 0) {
item.quality = item.quality - 1
}
}
updateSellInInOneDay(item) {
if (item.name != this.isSulfuras()) {
this.decreaseSellIn(item)
updateSellIn(item) {
if (item.name === this.isSulfuras()) {
return
}
this.decreaseSellInOneDay(item)
}
updateQualityAfterDevaluation(item) {
updateQualityAfterExpired(item) {
if (item.sell_in >= 0) {
return
}
if (item.sell_in < 0) {
if (item.name != this.isAgedBrie()) {
if (item.name != this.isBackStagePass()) {
if (item.quality > 0) {
if (item.name != this.isSulfuras()) {
item.quality = item.quality - 1
}
} else {
item.quality = item.quality - item.quality
if (item.name !== this.isAgedBrie()) {
if (item.quality > 0) {
if (item.name !== this.isSulfuras()) {
item.quality = item.quality - 1
}
} else {
if (item.quality < 50) {
this.updateQualityAfterExpired(item);
}
item.quality = item.quality - item.quality
}
}
}
}
decreaseSellIn(item) {
decreaseSellInOneDay(item) {
item.sell_in = item.sell_in - 1
}
updateQualityAfterExpired(item) {
item.quality = item.quality + 1
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment