Commit 24efc7bd by 李楚霏

task-9-整理子类函数;消除不需要的参数

parent e3923306
import { Item } from './item'
export class AgedBrie extends Item{
export class AgedBrie extends Item {
constructor(sell_in, quality) {
super(sell_in, quality)
this.name = 'Aged Brie'
}
isAgedBrie() {
return 'Aged Brie'
}
updateQuality(item) {
if (item.quality < 50) {
item.quality = item.quality + 1
}
}
updateQualityAfterExpired(item) {
return
}
isAgedBire() {
return true
}
}
import { AgedBrie } from "./AgedBrie"
describe('AgedBrieTest', () => {
it('foo', () => {
const agedBrie = new AgedBrie(2, 0);
const string = agedBrie.isAgedBrie();
expect(string).toEqual('Aged Brie');
})
})
\ No newline at end of file
......@@ -7,11 +7,12 @@ export class BackstagePass extends Item{
}
isBackStage() {
return 'Backstage passes to a TAFKAL80ETC concert'
return true
}
updateQuality(item) {
if (item.name === this.isBackStagePass()) {
if (item.quality < 50) {
if (item.quality >= 50) {
return
}
if (item.sell_in < 11) {
if (item.quality < 50) {
item.quality = item.quality + 1
......@@ -19,11 +20,8 @@ export class BackstagePass extends Item{
}
if (item.sell_in < 6) {
if (item.quality < 50) {
item.quality = item.quality + 1;
}
}
item.quality = item.quality + 1
}
return;
}
}
updateQualityAfterExpired(item) {
......
import { BackstagePass } from "./BackstagePass";
describe('backstagePassTest', () => {
it('foo', () => {
const agedBrie = new BackstagePass(15, 20);
const string = agedBrie.isBackStage();
expect(string).toEqual('Backstage passes to a TAFKAL80ETC concert');
})
})
\ No newline at end of file
......@@ -7,7 +7,13 @@ export class Sulfuras extends Item{
}
isSulfuras() {
return 'Sulfuras, Hand of Ragnaros'
return true
}
updateQuality(item) {}
updateQualityAfterExpired(item) {
return
}
updateSellIn(item) {
return
}
}
import { Sulfuras } from "./Sulfuras";
describe('SulfurasTest', () => {
it('foo', () => {
const agedBrie = new Sulfuras(-1, 80);
const string = agedBrie.isSulfuras();
expect(string).toEqual('Sulfuras, Hand of Ragnaros');
})
})
\ No newline at end of file
import { GildedRose } from './gilded-rose'
import { Item } from './item'
import { AgedBrie } from './AgedBrie'
import { Sulfuras } from './Sulfuras'
import { BackstagePass } from './BackstagePass'
const items = [
createNormalItem('+5 Dexterity Vest', 10, 20),
createAgedBrie(2, 0),
createNormalItem('Elixir of the Mongoose', 5, 7),
createSulfuras(0, 80),
createSulfuras(-1, 80),
createBackStagePass(15, 20),
createBackStagePass(10, 49),
createBackStagePass(5, 49),
createBackStagePass(1, 20),
new Item('+5 Dexterity Vest', 10, 20),
new AgedBrie(2, 0),
new Item('Elixir of the Mongoose', 5, 7),
new Sulfuras(0, 80),
new Sulfuras(-1, 80),
new BackstagePass(15, 20),
new BackstagePass(10, 49),
new BackstagePass(5, 49),
new BackstagePass(1, 20),
// this conjured item does not work properly yet
createNormalItem('Conjured Mana Cake', 3, 6),
new Item('Conjured Mana Cake', 3, 6),
]
const app = new GildedRose(items)
......
......@@ -7,63 +7,7 @@ export class GildedRose {
update_quality() {
for (const item of this.items) {
item._updateItem(item);
item.passOneDay()
}
}
// update_quality() {
// for (const item of this.items) {
// if (
// item.name != 'Aged Brie' &&
// item.name != 'Backstage passes to a TAFKAL80ETC concert'
// ) {
// if (item.quality > 0) {
// if (item.name != 'Sulfuras, Hand of Ragnaros') {
// item.quality = item.quality - 1
// }
// }
// } else {
// if (item.quality < 50) {
// item.quality = item.quality + 1
// if (
// item.name == 'Backstage passes to a TAFKAL80ETC concert'
// ) {
// 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
// }
// }
// }
// }
// }
// if (item.name != 'Sulfuras, Hand of Ragnaros') {
// item.sell_in = item.sell_in - 1
// }
// if (item.sell_in < 0) {
// if (item.name != 'Aged Brie') {
// if (
// item.name != 'Backstage passes to a TAFKAL80ETC concert'
// ) {
// if (item.quality > 0) {
// if (item.name != 'Sulfuras, Hand of Ragnaros') {
// item.quality = item.quality - 1
// }
// }
// } else {
// item.quality =
// item.quality - item.quality
// }
// } else {
// if (item.quality < 50) {
// item.quality = item.quality + 1
// }
// }
// }
// }
// }
}
......@@ -9,79 +9,38 @@ export class Item {
this.quality = quality
}
isAgedBrie() {
return 'Aged Brie'
}
isSulfuras() {
return 'Sulfuras, Hand of Ragnaros'
}
isBackStagePass() {
return 'Backstage passes to a TAFKAL80ETC concert'
}
toString() {
return `${this.name}, ${this.sell_in}, ${this.quality}`
}
createBackStagePass(sell_in, quality) {
new BackStagePass(
'Backstage passes to a TAFKAL80ETC concert',
sell_in,
quality
)
passOneDay() {
this.updateQuality()
this.updateSellIn()
this.updateQualityAfterExpired()
}
createSulfuras(sell_in, quality) {
new Sulfuras(sell_in, quality)
updateQuality() {
if (this.quality > 0) {
this.quality = this.quality - 1
}
createNormalItem(name, sell_in, quality) {
new Item(name, sell_in, quality)
}
createAgedBrie(sell_in, quality) {
new AgedBrie(sell_in, quality)
}
_updateItem(item) {
this.updateQuality(item)
this.updateSellIn(item)
this.updateQualityAfterExpired(item)
updateSellIn() {
this.decreaseSellInOneDay()
}
updateQuality(item) {
if (item.quality > 0) {
item.quality = item.quality - 1
}
}
updateSellIn(item) {
if (item.name === this.isSulfuras()) {
updateQualityAfterExpired() {
if (this.sell_in >= 0) {
return
}
this.decreaseSellInOneDay(item)
}
updateQualityAfterExpired(item) {
if (item.sell_in >= 0) {
if (this.quality <= 0) {
this.quality = 0
return
}
if (item.sell_in < 0) {
if (item.name !== this.isAgedBrie()) {
if (item.quality > 0) {
if (item.name !== this.isSulfuras()) {
item.quality = item.quality - 1
}
} else {
item.quality = item.quality - item.quality
}
}
}
this.quality = this.quality - 1
}
decreaseSellInOneDay(item) {
item.sell_in = item.sell_in - 1
decreaseSellInOneDay() {
this.sell_in = this.sell_in - 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