Add open command
This commit is contained in:
parent
0fc99dbc62
commit
6d8d64ed58
58
main.go
58
main.go
@ -8,8 +8,14 @@ import (
|
||||
|
||||
func main() {
|
||||
|
||||
type Item struct {
|
||||
name string
|
||||
moveable bool
|
||||
openable bool
|
||||
}
|
||||
type Room struct {
|
||||
name, description string
|
||||
items map[string]*Item
|
||||
north, south, west, east string
|
||||
}
|
||||
|
||||
@ -20,17 +26,34 @@ func main() {
|
||||
|
||||
inventory := map[string]string{}
|
||||
|
||||
entryItems := map[string]*Item{}
|
||||
chestItems := map[string]*Item{
|
||||
"chest": {"chest",
|
||||
false,
|
||||
true,
|
||||
},
|
||||
}
|
||||
caveItems := map[string]*Item{
|
||||
"House Key": {"House Key",
|
||||
true,
|
||||
false},
|
||||
}
|
||||
|
||||
/* Pointing to the struct "Room" allows us to directly modify its values */
|
||||
rooms := map[string]*Room{
|
||||
"entry": {"Field", "\nYou find yourself before a mansion to the (n)orth.\n" +
|
||||
"There is a cave to the (w)est.\n" +
|
||||
"In the distance, you see some sort of box to the (e)ast.",
|
||||
entryItems,
|
||||
"none", "none", "cave", "chest"},
|
||||
"chest": {"Chest", "\nYou see a closed chest freezer in front of you.\n" +
|
||||
"There is an empty field to the (w)est.\n",
|
||||
chestItems,
|
||||
"none", "none", "entry", "none"},
|
||||
"cave": {"Cave", "\n A beast of inconevialable horror dwells in this" +
|
||||
" cave and proceds to tear you apart.", "none", "none", "none", "entry"},
|
||||
" cave and proceds to tear you apart.",
|
||||
caveItems,
|
||||
"none", "none", "none", "entry"},
|
||||
}
|
||||
|
||||
player := Player{rooms["entry"], inventory}
|
||||
@ -132,11 +155,42 @@ func main() {
|
||||
println(k, " ", v)
|
||||
}
|
||||
println("")
|
||||
case "open":
|
||||
if command[1] == "" {
|
||||
println("")
|
||||
println("Open what? ")
|
||||
break
|
||||
}
|
||||
|
||||
if _, ok := player.loc.items[command[1]]; ok &&
|
||||
player.loc.items[command[1]].openable == true {
|
||||
|
||||
if player.loc.name == "Chest" {
|
||||
println("\nYou open the chest")
|
||||
player.loc.items["chest"].openable = false
|
||||
player.loc.items["steak"] = &Item{"steak", true, false}
|
||||
player.loc.description = "" +
|
||||
"\nYou see an open chest freezer in front of you.\n" +
|
||||
"There is a putrid steak in the freezer\n" +
|
||||
"There is an empty field to the (w)est.\n"
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
println("I don't know how to open a", command[1])
|
||||
|
||||
default:
|
||||
println("\nI don't know how to '", command[0], "'\n")
|
||||
}
|
||||
|
||||
// Perhaps the below should somehow be attached to the room struct?
|
||||
// Feels silly to check this every time, but I suppose it is fine.
|
||||
// Perhaps something like, instead of these if statements
|
||||
// We run something like room.action() every loop, and stuff like this
|
||||
// here below will be activated.
|
||||
// I guess room.action() would be a seperate function for every room?
|
||||
// Perhaps next game. I think we'll just loop through all these things
|
||||
// time
|
||||
if player.loc.name == "Cave" {
|
||||
if _, ok := player.items["steak"]; ok {
|
||||
println("\n You see a poodle sitting in the cave. You can't stand " +
|
||||
@ -144,7 +198,7 @@ func main() {
|
||||
"out of the cave which the dog happily chases after.")
|
||||
rooms["cave"].description = "You are in a dark cave.\n" +
|
||||
"There is a key on the floor.\n" +
|
||||
"Their is an empty field to the (e)ast."
|
||||
"There is an empty field to the (e)ast."
|
||||
steak_happened = true
|
||||
}
|
||||
if steak_happened == false {
|
||||
|
Loading…
x
Reference in New Issue
Block a user