mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-10-13 17:49:25 +00:00
separate files based on feedback
This commit is contained in:
1 parent
eb9b46e34d
commit
d73f961089
5 files changed
+51
-48
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package gilded_rose
|
||||
|
||||
Item :: struct {
|
||||
name: string,
|
||||
sell_in: i32,
|
||||
quality: i32,
|
||||
}
|
||||
|
||||
update_quality :: proc(inventory: []Item) {
|
||||
for &item in inventory {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import GildedRose "./core"
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
import "core:slice"
|
||||
import "core:strconv"
|
||||
|
||||
main :: proc() {
|
||||
days := 2
|
||||
if num_of_days, arg_ok := slice.get(os.args, 1); arg_ok {
|
||||
if val, ok := strconv.parse_int(num_of_days); ok && val > 0 {
|
||||
days = val
|
||||
} else {
|
||||
fmt.eprintf("Please enter a number greater than 0\n")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
items := []GildedRose.Item {
|
||||
{"+5 Dexterity Vest", 10, 20},
|
||||
{"Aged Brie", 2, 0},
|
||||
{"Elixir of the Mongoose", 5, 7},
|
||||
{"Sulfuras, Hand of Ragnaros", 0, 80},
|
||||
{"Sulfuras, Hand of Ragnaros", -1, 80},
|
||||
{"Backstage passes to a TAFKAL80ETC concert", 15, 20},
|
||||
{"Backstage passes to a TAFKAL80ETC concert", 10, 49},
|
||||
{"Backstage passes to a TAFKAL80ETC concert", 5, 49},
|
||||
// This Conjured item does not work properly yet
|
||||
{"Conjured Mana Cake", 3, 6},
|
||||
}
|
||||
|
||||
fmt.println("OMGHAI!")
|
||||
|
||||
for day in 0 ..= days {
|
||||
day_line := fmt.tprint("-------- day", day, "--------")
|
||||
fmt.println(day_line)
|
||||
fmt.println("name, sellIn, quality")
|
||||
for item in items {
|
||||
item_line := fmt.tprint(item.name, item.sell_in, item.quality, sep = ", ")
|
||||
fmt.println(item_line)
|
||||
}
|
||||
fmt.println()
|
||||
GildedRose.update_quality(items)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user