Created
September 4, 2020 17:33
-
-
Save HectorBlisS/1e7f1bd9d0a0dc72db0f20f3107f993e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import GildedRose | |
let items = [ | |
Item(name: "+5 Dexterity Vest", sellIn: 10, quality: 20), | |
Item(name: "Aged Brie", sellIn: 2, quality: 0), | |
Item(name: "Elixir of the Mongoose", sellIn: 5, quality: 7), | |
Item(name: "Sulfuras, Hand of Ragnaros", sellIn: 0, quality: 80), | |
Item(name: "Sulfuras, Hand of Ragnaros", sellIn: -1, quality: 80), | |
Item(name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 15, quality: 20), | |
Item(name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 10, quality: 49), | |
Item(name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 5, quality: 49), | |
// this conjured item does not work properly yet | |
Item(name: "Conjured Mana Cake", sellIn: 3, quality: 6)] | |
let app = GildedRose(items: items); | |
// All items have a SellIn value which denotes the number of days we have to sell the item | |
func checkForSellIn() { | |
var missed = [] | |
for var i = 0; i < items!.count ; ++i { | |
if(items[i].sellIn == nil){ | |
print("--- missing sellIn found on \(item[i].name) ---") | |
missed.append(item[i]) | |
} | |
} | |
return missed | |
} | |
// All items have a Quality value which denotes how valuable the item is | |
func checkForQuality() { | |
var missed = [] | |
for var i = 0; i < items!.count ; ++i { | |
if(items[i].quality == nil){ | |
print("--- missing quality found on \(item[i].name) ---") | |
missed.append(item[i]) | |
} | |
} | |
return missed | |
} | |
// At the end of each day our system lowers both values for every item | |
func lowAtEndOfDay() { | |
for var i = 0; i < items!.count ; ++i { | |
if(items[i].quality != nil && items[i].sellIn != nil){ | |
print("--- lowing in \(item[i].name) ---") | |
// At the end of each day our system lowers both values for every item | |
decideHowToLow(items[i]) | |
handleLowSellIn(items[i]) | |
} | |
} | |
} | |
func handleLowSellIn(item) { | |
item.sellIn -= 1 | |
} | |
func decideHowToLow() { | |
if(item.name.contains("Conjured")){ | |
handleLowQuality(item, 2) | |
return | |
}else { | |
handleLowQuality(item, 1) | |
} | |
} | |
func handleLowQuality(item, lowValue) { | |
if(item.name === "Aged Brie") { | |
item.quality += lowValue | |
return | |
} | |
if(item.quality>49 || item.name == "Sulfuras") { | |
return | |
} | |
if(item.quality == "Backstage passes") { | |
if( item.sellIn < 1 ){ | |
item.quality = 0 | |
} | |
else if(item.sellIn < 6){ | |
item.quality += (lowValue + 2) | |
} | |
else if(item.sellIn < 11){ | |
item.quality += (lowValue + 1) | |
}else { | |
item.quality -= lowValue | |
} | |
} | |
if(item.sellIn<0) { | |
item.quality -= (lowValue + 1) | |
} | |
if(item.quality < 1) { | |
item.quality = 0 | |
}else{ | |
item.quality -= lowValue | |
} | |
} | |
for i in 0..<days { | |
print("-------- day \(i) --------"); | |
print("name, sellIn, quality"); | |
for item in items { | |
print(item); | |
} | |
print(""); | |
app.updateQuality(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment