second
This commit is contained in:
parent
9e9723ba50
commit
eb2ccf643d
70
main.go
70
main.go
@ -9,32 +9,42 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
type Room struct {
|
type Room struct {
|
||||||
name, description string
|
name, description string
|
||||||
|
north, south, west, east string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Player struct {
|
type Player struct {
|
||||||
location string
|
loc *Room
|
||||||
// items inventory
|
// items inventory
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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" +
|
||||||
"There is a cave to the (w)est.\n" +
|
"There is a cave to the (w)est.\n" +
|
||||||
"In the distance, you see some sort of box to the (e)ast."},
|
"In the distance, you see some sort of box to the (e)ast.",
|
||||||
"chest": {"Chest", "You see a closed chest freezer in front of you."},
|
"none", "none", "none", "chest"},
|
||||||
|
"chest": {"Chest", "You see a closed chest freezer in front of you.",
|
||||||
|
"none", "none", "entry", "none"},
|
||||||
}
|
}
|
||||||
println(rooms["chest"])
|
|
||||||
|
|
||||||
/*
|
player := Player{rooms["entry"]}
|
||||||
|
|
||||||
cmd := exec.Command("clear")
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Run()
|
|
||||||
*/
|
|
||||||
|
|
||||||
var command [2]string
|
var command [2]string
|
||||||
var quit bool = false
|
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 {
|
for quit != true {
|
||||||
|
println(player.loc.description, "\n")
|
||||||
fmt.Print("Enter text: ")
|
fmt.Print("Enter text: ")
|
||||||
|
|
||||||
fmt.Scanln(&command[0], &command[1])
|
fmt.Scanln(&command[0], &command[1])
|
||||||
@ -43,7 +53,7 @@ func main() {
|
|||||||
command[1] = strings.ToLower(command[1])
|
command[1] = strings.ToLower(command[1])
|
||||||
|
|
||||||
switch command[0] {
|
switch command[0] {
|
||||||
case "q", "quit":
|
case "q", "quit", "exit":
|
||||||
print("Are you sure you want to quit? (y/n): ")
|
print("Are you sure you want to quit? (y/n): ")
|
||||||
fmt.Scanln(&command[0])
|
fmt.Scanln(&command[0])
|
||||||
if strings.ToLower(command[0]) == "y" {
|
if strings.ToLower(command[0]) == "y" {
|
||||||
@ -69,10 +79,42 @@ func main() {
|
|||||||
|
|
||||||
"(l)ook\n" +
|
"(l)ook\n" +
|
||||||
"(g)et\n" +
|
"(g)et\n" +
|
||||||
"(u)se)\n")
|
"(u)se\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")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
println("I don't know how to '", command[0], "'")
|
println("\nI don't know how to '", command[0], "'\n")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user