forked from p4tin/GoTextAdv
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommands.go
More file actions
64 lines (63 loc) · 1.81 KB
/
commands.go
File metadata and controls
64 lines (63 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"os"
"strings"
)
func ProcessCommands(player *Character, input string) {
Output("yellow", "======================================================================")
tokens := strings.Fields(input)
if len(tokens) == 0 {
Output("red", "No command received.")
return
}
command := strings.ToLower(tokens[0])
itemName := ""
if len(tokens) > 1 {
itemName = tokens[1]
}
loc := LocationMap[player.CurrentLocation]
switch(command) {
case "go":
fallthrough
case "goto":
if loc.CanGoTo(strings.ToLower(itemName)) {
locName, err := FindLocationName(strings.ToLower(itemName))
if err != nil {
Output("red", "Can't go to " + itemName + " from here.")
} else {
player.CurrentLocation = locName
}
} else {
Output("red", "Can't go to " + itemName + " from here.")
}
case "get":
err, index, itm := FindItemByName(itemName)
//Make sure we do not pick it up twice
if err == nil && itm.ItemInRoom(loc) && !itm.ItemOnPlayer(player) {
player.Items = append(player.Items, index) // Add Item to Player's bag
itm.RemoveItemFromRoom(loc)
} else {
Output("Could not get " + itemName)
}
case "open":
OpenItem(player, itemName)
case "inv":
Output("yellow", "Your Inventory: ")
for _, itm := range player.Items {
Output("yellow", "\t" + Items[itm].Name)
}
case "help":
Output("blue", "Commands:")
Output("blue", "\tgo <Location Name> - Move to the new location")
Output("blue", "\tattack - Attacks opponent(s)")
Output("blue", "\tblock - Block incoming attack")
Output("blue", "\trun - Escape attack")
Output("blue", "\tget <Item Name> - Pick up item")
Output("blue", "\topen <Item Name> - Open an iten if it can be opened")
Output("blue", "\tinv - Show what you are carrying\n\n")
case "quit":
Output("green", "Goodbye...")
os.Exit(0)
default:
}
}