diff --git a/Solutions/DSMdongly/game-shop/part-1/pkg/windows_amd64/game-shop/item.a b/Solutions/DSMdongly/game-shop/part-1/pkg/windows_amd64/game-shop/item.a new file mode 100644 index 0000000..c03aeee Binary files /dev/null and b/Solutions/DSMdongly/game-shop/part-1/pkg/windows_amd64/game-shop/item.a differ diff --git a/Solutions/DSMdongly/game-shop/part-1/src/game-shop/item/item.go b/Solutions/DSMdongly/game-shop/part-1/src/game-shop/item/item.go new file mode 100644 index 0000000..8ea87c2 --- /dev/null +++ b/Solutions/DSMdongly/game-shop/part-1/src/game-shop/item/item.go @@ -0,0 +1,29 @@ +package item + +import ( + "fmt" +) + +type Item struct { + Name string + Description string + Weight int + Value int +} + +func NewItem(nme string, dsc string, wgt int, val int) *Item { + return &Item{ + Name: nme, + Description: dsc, + Weight: wgt, + Value: val, + } +} + +func (ite Item) Describe() { + fmt.Println() + fmt.Printf("Name = %s\n", ite.Name) + fmt.Printf("Description = %s\n", ite.Description) + fmt.Printf("Weight = %d lbs\n", ite.Weight) + fmt.Printf("Value = %d gold coins\n", ite.Value) +} diff --git a/Solutions/DSMdongly/game-shop/part-1/src/game-shop/main.go b/Solutions/DSMdongly/game-shop/part-1/src/game-shop/main.go new file mode 100644 index 0000000..a3a2bea --- /dev/null +++ b/Solutions/DSMdongly/game-shop/part-1/src/game-shop/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "game-shop/item" +) + +func main() { + swd := item.NewItem("Excalibur", "The legendary sword of King Arthur", 12, 1024) + swd.Describe() + + arm := item.NewItem("Steel Armor", "Protective covering made by steel", 15, 805) + arm.Describe() +} diff --git a/Solutions/DSMdongly/game-shop/part-2/pkg/windows_amd64/game-shop/item.a b/Solutions/DSMdongly/game-shop/part-2/pkg/windows_amd64/game-shop/item.a new file mode 100644 index 0000000..afde148 Binary files /dev/null and b/Solutions/DSMdongly/game-shop/part-2/pkg/windows_amd64/game-shop/item.a differ diff --git a/Solutions/DSMdongly/game-shop/part-2/src/game-shop/item/armor.go b/Solutions/DSMdongly/game-shop/part-2/src/game-shop/item/armor.go new file mode 100644 index 0000000..2171b66 --- /dev/null +++ b/Solutions/DSMdongly/game-shop/part-2/src/game-shop/item/armor.go @@ -0,0 +1,20 @@ +package item + +import "fmt" + +type Armor struct { + Item + Defense int +} + +func NewArmor(nme string, dsc string, wgt int, val int, def int) *Armor { + return &Armor{ + Item: *NewItem(nme, dsc, wgt, val), + Defense: def, + } +} + +func (arm Armor) Describe() { + arm.Item.Describe() + fmt.Printf("Defense = %d\n", arm.Defense) +} diff --git a/Solutions/DSMdongly/game-shop/part-2/src/game-shop/item/item.go b/Solutions/DSMdongly/game-shop/part-2/src/game-shop/item/item.go new file mode 100644 index 0000000..b9f69db --- /dev/null +++ b/Solutions/DSMdongly/game-shop/part-2/src/game-shop/item/item.go @@ -0,0 +1,27 @@ +package item + +import "fmt" + +type Item struct { + Name string + Description string + Weight int + Value int +} + +func NewItem(nme string, dsc string, wgt int, val int) *Item { + return &Item{ + Name: nme, + Description: dsc, + Weight: wgt, + Value: val, + } +} + +func (ite Item) Describe() { + fmt.Println() + fmt.Printf("Name = %s\n", ite.Name) + fmt.Printf("Description = %s\n", ite.Description) + fmt.Printf("Weight = %d lbs\n", ite.Weight) + fmt.Printf("Value = %d gold coins\n", ite.Value) +} diff --git a/Solutions/DSMdongly/game-shop/part-2/src/game-shop/item/weapon.go b/Solutions/DSMdongly/game-shop/part-2/src/game-shop/item/weapon.go new file mode 100644 index 0000000..26c24f8 --- /dev/null +++ b/Solutions/DSMdongly/game-shop/part-2/src/game-shop/item/weapon.go @@ -0,0 +1,20 @@ +package item + +import "fmt" + +type Weapon struct { + Item + Damage int +} + +func NewWeapon(nme string, dsc string, wgt int, val int, dmg int) *Weapon { + return &Weapon{ + Item: *NewItem(nme, dsc, wgt, val), + Damage: dmg, + } +} + +func (wep Weapon) Describe() { + wep.Item.Describe() + fmt.Printf("Damage = %d\n", wep.Damage) +} diff --git a/Solutions/DSMdongly/game-shop/part-2/src/game-shop/main.go b/Solutions/DSMdongly/game-shop/part-2/src/game-shop/main.go new file mode 100644 index 0000000..44fa38e --- /dev/null +++ b/Solutions/DSMdongly/game-shop/part-2/src/game-shop/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "game-shop/item" +) + +func main() { + wep := item.NewWeapon("Excalibur", "The legendary sword of King Arthur", 12, 1024, 24) + wep.Describe() + + arm := item.NewArmor("Steel Armor", "Protective covering made by steel", 15, 805, 18) + arm.Describe() +} diff --git a/Solutions/DSMdongly/game-shop/part-3/pkg/windows_amd64/game-shop/item.a b/Solutions/DSMdongly/game-shop/part-3/pkg/windows_amd64/game-shop/item.a new file mode 100644 index 0000000..f2eb68e Binary files /dev/null and b/Solutions/DSMdongly/game-shop/part-3/pkg/windows_amd64/game-shop/item.a differ diff --git a/Solutions/DSMdongly/game-shop/part-3/pkg/windows_amd64/game-shop/shop.a b/Solutions/DSMdongly/game-shop/part-3/pkg/windows_amd64/game-shop/shop.a new file mode 100644 index 0000000..a79aea3 Binary files /dev/null and b/Solutions/DSMdongly/game-shop/part-3/pkg/windows_amd64/game-shop/shop.a differ diff --git a/Solutions/DSMdongly/game-shop/part-3/src/game-shop/item/armor.go b/Solutions/DSMdongly/game-shop/part-3/src/game-shop/item/armor.go new file mode 100644 index 0000000..2171b66 --- /dev/null +++ b/Solutions/DSMdongly/game-shop/part-3/src/game-shop/item/armor.go @@ -0,0 +1,20 @@ +package item + +import "fmt" + +type Armor struct { + Item + Defense int +} + +func NewArmor(nme string, dsc string, wgt int, val int, def int) *Armor { + return &Armor{ + Item: *NewItem(nme, dsc, wgt, val), + Defense: def, + } +} + +func (arm Armor) Describe() { + arm.Item.Describe() + fmt.Printf("Defense = %d\n", arm.Defense) +} diff --git a/Solutions/DSMdongly/game-shop/part-3/src/game-shop/item/item.go b/Solutions/DSMdongly/game-shop/part-3/src/game-shop/item/item.go new file mode 100644 index 0000000..b9f69db --- /dev/null +++ b/Solutions/DSMdongly/game-shop/part-3/src/game-shop/item/item.go @@ -0,0 +1,27 @@ +package item + +import "fmt" + +type Item struct { + Name string + Description string + Weight int + Value int +} + +func NewItem(nme string, dsc string, wgt int, val int) *Item { + return &Item{ + Name: nme, + Description: dsc, + Weight: wgt, + Value: val, + } +} + +func (ite Item) Describe() { + fmt.Println() + fmt.Printf("Name = %s\n", ite.Name) + fmt.Printf("Description = %s\n", ite.Description) + fmt.Printf("Weight = %d lbs\n", ite.Weight) + fmt.Printf("Value = %d gold coins\n", ite.Value) +} diff --git a/Solutions/DSMdongly/game-shop/part-3/src/game-shop/item/potion.go b/Solutions/DSMdongly/game-shop/part-3/src/game-shop/item/potion.go new file mode 100644 index 0000000..69e6ffb --- /dev/null +++ b/Solutions/DSMdongly/game-shop/part-3/src/game-shop/item/potion.go @@ -0,0 +1,23 @@ +package item + +import "fmt" + +type Potion struct { + Item + Type string + Capacity int +} + +func NewPotion(nme string, dsc string, wgt int, val int, typ string, cap int) *Potion { + return &Potion{ + Item: *NewItem(nme, dsc, wgt, val), + Type: typ, + Capacity: cap, + } +} + +func (pot Potion) Describe() { + pot.Item.Describe() + fmt.Printf("Type = %s\n", pot.Type) + fmt.Printf("Capacity = %d\n", pot.Capacity) +} diff --git a/Solutions/DSMdongly/game-shop/part-3/src/game-shop/item/weapon.go b/Solutions/DSMdongly/game-shop/part-3/src/game-shop/item/weapon.go new file mode 100644 index 0000000..26c24f8 --- /dev/null +++ b/Solutions/DSMdongly/game-shop/part-3/src/game-shop/item/weapon.go @@ -0,0 +1,20 @@ +package item + +import "fmt" + +type Weapon struct { + Item + Damage int +} + +func NewWeapon(nme string, dsc string, wgt int, val int, dmg int) *Weapon { + return &Weapon{ + Item: *NewItem(nme, dsc, wgt, val), + Damage: dmg, + } +} + +func (wep Weapon) Describe() { + wep.Item.Describe() + fmt.Printf("Damage = %d\n", wep.Damage) +} diff --git a/Solutions/DSMdongly/game-shop/part-3/src/game-shop/main.go b/Solutions/DSMdongly/game-shop/part-3/src/game-shop/main.go new file mode 100644 index 0000000..c5b90b9 --- /dev/null +++ b/Solutions/DSMdongly/game-shop/part-3/src/game-shop/main.go @@ -0,0 +1,87 @@ +package main + +import ( + "fmt" + "game-shop/item" + "game-shop/shop" + "log" + "strconv" + "time" +) + +func main() { + esh := InitEquipmentShop() + psh := InitPotionShop() + +SHOP_SELECTION: + for { + fmt.Println() + fmt.Println("Shop Select") + fmt.Println() + fmt.Println("1. Weapon/Armor Shop") + fmt.Println("2. Potion Shop") + fmt.Println("3. Exit") + fmt.Println() + + buf := "" + fmt.Scanln(&buf) + + flg, err := strconv.Atoi(buf) + + if err != nil { + log.Fatal(err) + } + + switch flg { + case 1: + fmt.Println() + fmt.Println("Welcome to Weapon/Armor Shop!") + fmt.Println() + + time.Sleep(time.Millisecond * 500) + esh.ShowItemList() + + break + case 2: + fmt.Println() + fmt.Println("Welcome to Potion Shop!") + fmt.Println() + + time.Sleep(time.Millisecond * 500) + psh.ShowItemList() + + break + case 3: + break SHOP_SELECTION + default: + fmt.Println() + fmt.Println("Invalid number! Try again.") + + continue SHOP_SELECTION + } + } +} + +func InitEquipmentShop() *shop.Shop { + eqps := make([]shop.Item, 0) + eqps = append(eqps, item.NewWeapon("Sword", "Medium DMG", 3, 10, 10)) + eqps = append(eqps, item.NewWeapon("Cap", "Light Armor", 1, 5, 5)) + eqps = append(eqps, item.NewWeapon("Gloves", "Light Armor", 1, 5, 5)) + eqps = append(eqps, item.NewWeapon("Axe", "High DMG", 5, 15, 15)) + eqps = append(eqps, item.NewWeapon("Boots", "Light Armor", 1, 5, 5)) + + esh := shop.NewShop("Weapon/Armor Shop", eqps) + return esh +} + +func InitPotionShop() *shop.Shop { + pots := make([]shop.Item, 0) + pots = append(pots, item.NewPotion("Small Health Potion", "Recovery 100 HP", 2, 5, "Health", 100)) + pots = append(pots, item.NewPotion("Small Mana Potion", "Recovery 50 MP", 1, 30, "Mana", 50)) + pots = append(pots, item.NewPotion("Medium Health Potion", "Recovery 200 HP", 4, 120, "Health", 200)) + pots = append(pots, item.NewPotion("Small Health Potion", "Recovery 100 MP", 2, 75, "Mana", 100)) + pots = append(pots, item.NewPotion("Large Health Potion", "Recovery 300 HP", 6, 200, "Health", 300)) + + psh := shop.NewShop("Potion Shop", pots) + return psh +} diff --git a/Solutions/DSMdongly/game-shop/part-3/src/game-shop/shop/shop.go b/Solutions/DSMdongly/game-shop/part-3/src/game-shop/shop/shop.go new file mode 100644 index 0000000..b3b1622 --- /dev/null +++ b/Solutions/DSMdongly/game-shop/part-3/src/game-shop/shop/shop.go @@ -0,0 +1,23 @@ +package shop + +type Item interface { + Describe() +} + +type Shop struct { + Name string + Items []Item +} + +func NewShop(nme string, ites []Item) *Shop { + return &Shop{ + Name: nme, + Items: ites, + } +} + +func (shp Shop) ShowItemList() { + for _, ite := range shp.Items { + ite.Describe() + } +}