Refactor Item type; add get abilities
This commit is contained in:
parent
6d8d64ed58
commit
851dae2107
51
main.go
51
main.go
@ -9,7 +9,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
type Item struct {
|
type Item struct {
|
||||||
name string
|
name, description string
|
||||||
moveable bool
|
moveable bool
|
||||||
openable bool
|
openable bool
|
||||||
}
|
}
|
||||||
@ -21,20 +21,20 @@ func main() {
|
|||||||
|
|
||||||
type Player struct {
|
type Player struct {
|
||||||
loc *Room
|
loc *Room
|
||||||
items map[string]string
|
items map[string]*Item
|
||||||
}
|
}
|
||||||
|
|
||||||
inventory := map[string]string{}
|
inventory := map[string]*Item{}
|
||||||
|
|
||||||
entryItems := map[string]*Item{}
|
entryItems := map[string]*Item{}
|
||||||
chestItems := map[string]*Item{
|
chestItems := map[string]*Item{
|
||||||
"chest": {"chest",
|
"chest": {"chest", "none",
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
caveItems := map[string]*Item{
|
caveItems := map[string]*Item{
|
||||||
"House Key": {"House Key",
|
"key": {"House Key", "It resembles a house key.",
|
||||||
true,
|
true,
|
||||||
false},
|
false},
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ func main() {
|
|||||||
|
|
||||||
player := Player{rooms["entry"], inventory}
|
player := Player{rooms["entry"], inventory}
|
||||||
|
|
||||||
player.items["syringe"] = "A syringe with a missing needle is in your pocket."
|
player.items["syringe"] = &Item{"Syringe", "A syringe with a missing needle is in your pocket.", false, false}
|
||||||
|
|
||||||
var command [2]string
|
var command [2]string
|
||||||
var quit bool = false
|
var quit bool = false
|
||||||
@ -151,10 +151,39 @@ func main() {
|
|||||||
println("")
|
println("")
|
||||||
println("Inventory:\n")
|
println("Inventory:\n")
|
||||||
//Listing items, and looking at them, should be different.
|
//Listing items, and looking at them, should be different.
|
||||||
for k, v := range player.items {
|
for _, v := range player.items {
|
||||||
println(k, " ", v)
|
println(v.name, " ", v.description)
|
||||||
}
|
}
|
||||||
println("")
|
println("")
|
||||||
|
|
||||||
|
case "get":
|
||||||
|
if command[1] == "" {
|
||||||
|
println("")
|
||||||
|
println("Get what? ")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if _, ok := player.loc.items[command[1]]; ok &&
|
||||||
|
player.loc.items[command[1]].moveable == true {
|
||||||
|
println("You grab the", command[1],
|
||||||
|
"and place it in your pocket.")
|
||||||
|
player.items[command[1]] = player.loc.items[command[1]]
|
||||||
|
delete(player.loc.items, command[1])
|
||||||
|
|
||||||
|
if player.loc.name == "Chest" {
|
||||||
|
player.loc.description = "" +
|
||||||
|
"\nYou see an open chest freezer in front of you.\n" +
|
||||||
|
"The freezer is empty\n" +
|
||||||
|
"There is an empty field to the (w)est.\n"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if player.loc.name == "Cave" {
|
||||||
|
player.loc.description = "You are in a dark cave.\n" +
|
||||||
|
"There is an empty field to the (e)ast."
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println("\nI don't see any", command[1], "to get!")
|
||||||
case "open":
|
case "open":
|
||||||
if command[1] == "" {
|
if command[1] == "" {
|
||||||
println("")
|
println("")
|
||||||
@ -168,7 +197,8 @@ func main() {
|
|||||||
if player.loc.name == "Chest" {
|
if player.loc.name == "Chest" {
|
||||||
println("\nYou open the chest")
|
println("\nYou open the chest")
|
||||||
player.loc.items["chest"].openable = false
|
player.loc.items["chest"].openable = false
|
||||||
player.loc.items["steak"] = &Item{"steak", true, false}
|
player.loc.items["steak"] = &Item{"steak", "A rotting disgusting steak. " +
|
||||||
|
"\n You have no idea why you put it in your pocket.", true, false}
|
||||||
player.loc.description = "" +
|
player.loc.description = "" +
|
||||||
"\nYou see an open chest freezer in front of you.\n" +
|
"\nYou see an open chest freezer in front of you.\n" +
|
||||||
"There is a putrid steak in the freezer\n" +
|
"There is a putrid steak in the freezer\n" +
|
||||||
@ -177,7 +207,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
println("I don't know how to open a", command[1])
|
println("\nI don't know how to open a", command[1]+"!")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
println("\nI don't know how to '", command[0], "'\n")
|
println("\nI don't know how to '", command[0], "'\n")
|
||||||
@ -200,6 +230,7 @@ func main() {
|
|||||||
"There is a key on the floor.\n" +
|
"There is a key on the floor.\n" +
|
||||||
"There is an empty field to the (e)ast."
|
"There is an empty field to the (e)ast."
|
||||||
steak_happened = true
|
steak_happened = true
|
||||||
|
delete(player.items, "steak")
|
||||||
}
|
}
|
||||||
if steak_happened == false {
|
if steak_happened == false {
|
||||||
println("Well, it looks like you died! Good luck next time!")
|
println("Well, it looks like you died! Good luck next time!")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user