diff --git a/main.go b/main.go index 23da963..07a9de6 100644 --- a/main.go +++ b/main.go @@ -14,10 +14,12 @@ func main() { } type Player struct { - loc *Room - // items inventory + loc *Room + items map[string]string } + inventory := map[string]string{} + /* Pointing to the struct "Room" allows us to directly modify its values */ rooms := map[string]*Room{ "entry": {"Field", "You find yourself before a mansion to the (n)orth.\n" + @@ -28,7 +30,9 @@ func main() { "none", "none", "entry", "none"}, } - player := Player{rooms["entry"]} + player := Player{rooms["entry"], inventory} + + player.items["syringe"] = "A syringe with a missing needle is in your pocket." var command [2]string var quit bool = false @@ -79,7 +83,8 @@ func main() { "(l)ook\n" + "(g)et\n" + - "(u)se\n\n") + "(u)se\n" + + "(i)nventory\n\n") case "w", "west": if player.loc.west != "none" { @@ -113,6 +118,15 @@ func main() { } println("\nYou can't go that way!\n") + case "i", "inventory": + println("") + println("Inventory:\n") + //Listing items, and looking at them, should be different. + for k, v := range player.items { + println(k, " ", v) + } + println("") + default: println("\nI don't know how to '", command[0], "'\n")