Add inventory
This commit is contained in:
parent
2bebc944cb
commit
f2fde37ec8
20
main.go
20
main.go
@ -15,9 +15,11 @@ func main() {
|
|||||||
|
|
||||||
type Player struct {
|
type Player struct {
|
||||||
loc *Room
|
loc *Room
|
||||||
// items inventory
|
items map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inventory := map[string]string{}
|
||||||
|
|
||||||
/* Pointing to the struct "Room" allows us to directly modify its values */
|
/* Pointing to the struct "Room" allows us to directly modify its values */
|
||||||
rooms := map[string]*Room{
|
rooms := map[string]*Room{
|
||||||
"entry": {"Field", "You find yourself before a mansion to the (n)orth.\n" +
|
"entry": {"Field", "You find yourself before a mansion to the (n)orth.\n" +
|
||||||
@ -28,7 +30,9 @@ func main() {
|
|||||||
"none", "none", "entry", "none"},
|
"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 command [2]string
|
||||||
var quit bool = false
|
var quit bool = false
|
||||||
@ -79,7 +83,8 @@ func main() {
|
|||||||
|
|
||||||
"(l)ook\n" +
|
"(l)ook\n" +
|
||||||
"(g)et\n" +
|
"(g)et\n" +
|
||||||
"(u)se\n\n")
|
"(u)se\n" +
|
||||||
|
"(i)nventory\n\n")
|
||||||
|
|
||||||
case "w", "west":
|
case "w", "west":
|
||||||
if player.loc.west != "none" {
|
if player.loc.west != "none" {
|
||||||
@ -113,6 +118,15 @@ func main() {
|
|||||||
}
|
}
|
||||||
println("\nYou can't go that way!\n")
|
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:
|
default:
|
||||||
println("\nI don't know how to '", command[0], "'\n")
|
println("\nI don't know how to '", command[0], "'\n")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user