Commit f8d48a44 by 李楚霏

task-6-subclassing

parent 85e441bf
export class AgedBrie {
isAgedBrie() {
return 'Aged Brie';
}
isSulfuras() {
return 'Sulfuras, Hand of Ragnaros';
}
isBackStage() {
return 'Backstage passes to a TAFKAL80ETC concert';
}
}
\ No newline at end of file
import { AgedBrie } from "./AgedBrie"
describe('AgedBrieTest', () => {
it('foo', () => {
const agedBrie = new AgedBrie();
const string = agedBrie.isAgedBrie();
expect(string).toEqual('Aged Brie');
})
})
\ No newline at end of file
export class BackstagePass {
isAgedBrie() {
return 'Aged Brie';
}
isSulfuras() {
return 'Sulfuras, Hand of Ragnaros';
}
isBackStage() {
return 'Backstage passes to a TAFKAL80ETC concert';
}
}
\ No newline at end of file
import { BackstagePass } from "./BackstagePass";
describe('backstagePassTest', () => {
it('foo', () => {
const agedBrie = new BackstagePass();
const string = agedBrie.isBackStage();
expect(string).toEqual('Backstage passes to a TAFKAL80ETC concert');
})
})
\ No newline at end of file
export class Sulfuras {
isAgedBrie() {
return 'Aged Brie';
}
isSulfuras() {
return 'Sulfuras, Hand of Ragnaros';
}
isBackStage() {
return 'Backstage passes to a TAFKAL80ETC concert';
}
}
\ No newline at end of file
import { Sulfuras } from "./Sulfuras";
describe('SulfurasTest', () => {
it('foo', () => {
const agedBrie = new Sulfuras();
const string = agedBrie.isSulfuras();
expect(string).toEqual('Sulfuras, Hand of Ragnaros');
})
})
\ No newline at end of file
......@@ -2,17 +2,17 @@ import { GildedRose } from './gilded-rose'
import { Item } from './item'
const items = [
new Item('+5 Dexterity Vest', 10, 20), //
new Item('Aged Brie', 2, 0), //
new Item('Elixir of the Mongoose', 5, 7), //
new Item('Sulfuras, Hand of Ragnaros', 0, 80), //
new Item('Sulfuras, Hand of Ragnaros', -1, 80),
new Item('Backstage passes to a TAFKAL80ETC concert', 15, 20),
new Item('Backstage passes to a TAFKAL80ETC concert', 10, 49),
new Item('Backstage passes to a TAFKAL80ETC concert', 5, 49),
new Item('Backstage passes to a TAFKAL80ETC concert', 1, 20),
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),
// this conjured item does not work properly yet
new Item('Conjured Mana Cake', 3, 6),
createNormalItem('Conjured Mana Cake', 3, 6),
]
const app = new GildedRose(items)
......
const backStage = 'Backstage passes to a TAFKAL80ETC concert'
const Sulfuras = 'Sulfuras, Hand of Ragnaros'
const AgedBrie = 'Aged Brie'
export class Item {
name
sell_in
......@@ -12,43 +9,70 @@ 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 Item('Backstage passes to a TAFKAL80ETC concert', sell_in, quality);
}
createSulfuras(sell_in, quality) {
new Item('Sulfuras, Hand of Ragnaros', sell_in, quality);
}
createNormalItem(name, sell_in, quality) {
new Item(name, sell_in, quality);
}
createAgedBrie(sell_in, quality) {
new Item('Aged Brie', sell_in, quality);
}
_updateItem(item) {
if (item.name != AgedBrie && item.name != backStage) {
if (item.name != this.isAgedBrie() && item.name != this.isBackStagePass()) {
if (item.quality > 0) {
if (item.name != Sulfuras) {
if (item.name != this.isSulfuras()) {
item.quality = item.quality - 1
}
}
} else {
if (item.quality < 50) {
item.quality = item.quality + 1
if (
item.name == backStage) {
this.updateQualityAfterExpired(item)
if (item.name == this.isBackStagePass()) {
if (item.sell_in < 11) {
if (item.quality < 50) {
item.quality = item.quality + 1
this.updateQualityAfterExpired(item);
}
}
if (item.sell_in < 6) {
if (item.quality < 50) {
item.quality = item.quality + 1
this.updateQualityAfterExpired(item);
}
}
}
}
}
if (item.name != Sulfuras) {
item.sell_in = item.sell_in - 1
if (item.name != this.isSulfuras()) {
this.decreaseSellIn(item)
}
if (item.sell_in < 0) {
if (item.name != AgedBrie) {
if (item.name != backStage) {
if (item.name != this.isAgedBrie()) {
if (item.name != this.isBackStagePass()) {
if (item.quality > 0) {
if(item.name !=Sulfuras) {
if (item.name != this.isSulfuras()) {
item.quality = item.quality - 1
}
} else {
......@@ -56,10 +80,18 @@ export class Item {
}
} else {
if (item.quality < 50) {
item.quality = item.quality + 1
this.updateQualityAfterExpired(item);
}
}
}
}
}
decreaseSellIn(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