-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
72 lines (66 loc) · 2.08 KB
/
main.go
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
65
66
67
68
69
70
71
72
/*
*****************************************************
* © 2019 Stefano Peris <xenonlab.develop@gmail.com> *
*****************************************************
*
* Released under the GNU/GPL 3.0 license
*
* github: <https://github.com/XenonLab-Studio/GoZork>
*
*
* :'######::::'#######::'########::'#######::'########::'##:::'##:
* ##... ##::'##.... ##:..... ##::'##.... ##: ##.... ##: ##::'##::
* ##:::..::: ##:::: ##::::: ##::: ##:::: ##: ##:::: ##: ##:'##:::
* ##::'####: ##:::: ##:::: ##:::: ##:::: ##: ########:: #####::::
* ##::: ##:: ##:::: ##::: ##::::: ##:::: ##: ##.. ##::: ##. ##:::
* ##::: ##:: ##:::: ##:: ##:::::: ##:::: ##: ##::. ##:: ##:. ##::
* . ######:::. #######:: ########:. #######:: ##:::. ##: ##::. ##:
* :......:::::.......:::........:::.......:::..:::::..::..::::..::
*
* Textual adventure written in golang inspired by "Zork I"
*/
package main
import (
"bufio"
"os"
)
// sort by string length:
// https://mmcgrana.github.io/2012/09/go-by-example-sort-by-function.html
type ByLength []string
func (s ByLength) Len() int {
return len(s)
}
func (s ByLength) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s ByLength) Less(i, j int) bool {
return len(s[i]) < len(s[j])
}
var verbAliasMap = map[string][]string{
"GO NORTH": {"N", "NORTH"},
"GO SOUTH": {"S", "SOUTH"},
"GO WEST": {"W", "WEST"},
"GO EAST": {"E", "EAST"},
"GO IN": {"IN", "INSIDE", "ENTER"},
"GO OUT": {"OUT", "OUTSIDE", "LEAVE"},
"GO UP": {"UP"},
"GO DOWN": {"DOWN"},
"LOOK AT": {"EXAMINE", "INSPECT", "X"},
"LOOK UNDER": {"LOOK BENEATH", "LOOK BELOW"},
"TAKE": {"PICK UP", "GET"},
"DROP": {"THROW"},
"INVENTORY": {"I"},
"WAIT": {"Z"},
}
func main() {
// everything goes through this buffered read/writer which
// would make it very easy to plug this onto a telnet server.
console := bufio.NewReadWriter(
bufio.NewReader(os.Stdin),
bufio.NewWriter(os.Stdout))
player := Player{console: console, maxPoints: 11}
start, trollroom := NewGameWorld()
player.room = start
player.trollai.Init(trollroom, &player)
player.Run()
}