crushcandydx/main.go
2018-01-29 14:55:05 -07:00

137 lines
2.7 KiB
Go

// main
package main
import (
"fmt"
"strings"
)
func main() {
type Room struct {
name, description string
north, south, west, east string
}
type Player struct {
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" +
"There is a cave to the (w)est.\n" +
"In the distance, you see some sort of box to the (e)ast.",
"none", "none", "none", "chest"},
"chest": {"Chest", "You see a closed chest freezer in front of you.",
"none", "none", "entry", "none"},
}
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
println()
println()
println()
println()
println()
println("Welcome to Crush Candy DX!")
println("Type \"h\" for help!")
println("Enjoy!")
println()
println()
for quit != true {
println(player.loc.description, "\n")
fmt.Print("Enter text: ")
fmt.Scanln(&command[0], &command[1])
command[0] = strings.ToLower(command[0])
command[1] = strings.ToLower(command[1])
switch command[0] {
case "q", "quit", "exit":
print("Are you sure you want to quit? (y/n): ")
fmt.Scanln(&command[0])
if strings.ToLower(command[0]) == "y" {
println("The shame of quiting causes your liver to burst" +
" as you keel over.")
println("RIP")
quit = true
} else {
println("Welcome back from the edge! ")
}
case "h", "help":
print("Commands:\n\n" +
"(h)elp\n" +
"(c)lear\n" +
"(q)uit\n\n" +
"(n)orth\n" +
"(s)outh\n" +
"(e)ast\n" +
"(w)est\n\n" +
"(l)ook\n" +
"(g)et\n" +
"(u)se\n" +
"(i)nventory\n\n")
case "w", "west":
if player.loc.west != "none" {
player.loc = rooms[player.loc.west]
break
}
println("\nYou can't go that way!\n")
case "e", "east":
if player.loc.east != "none" {
player.loc = rooms[player.loc.east]
break
}
println("\nYou can't go that way!\n")
case "n", "north":
if player.loc.north != "none" {
player.loc = rooms[player.loc.north]
break
}
println("\nYou can't go that way!\n")
case "s", "south":
if player.loc.south != "none" {
player.loc = rooms[player.loc.south]
break
}
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")
}
}
}