forked from p4tin/GoTextAdv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcharacters.go
73 lines (59 loc) · 1.46 KB
/
characters.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
package main
type Character struct {
Name string
Health int
Evasion int
Alive bool
Speed int
Weap int
Npc bool
Items []int
Welcome string
CurrentLocation string
}
func (p *Character) Equip(w int) {
p.Weap = w
}
func (p *Character) Attack() int {
return Weaps[p.Weap].Fire()
}
type Players []Character
func (slice Players) Len() int {
return len(slice)
}
func (slice Players) Less(i, j int) bool {
return slice[i].Speed > slice[j].Speed //Sort descending
//return slice[i].Speed < slice[j].Speed; //Sort ascending
}
func (slice Players) Swap(i, j int) {
slice[i], slice[j] = slice[j], slice[i]
}
func (p *Character) Play() {
Output(p.Welcome)
for {
Output("blue", LocationMap[p.CurrentLocation].Description)
p.ProcessEvents(LocationMap[p.CurrentLocation].Events)
if p.Health <= 0 {
Output("white", "You are dead, game over!!!")
return
}
Output("blue", "Health:", p.Health)
if len(LocationMap[p.CurrentLocation].Items) > 0 {
Output("yellow", "You can see:")
for _, itm := range LocationMap[p.CurrentLocation].Items {
Outputf("yellow", "\t%s", Items[itm].Name)
}
}
Output("green", "You can go to these places:")
for _, loc := range LocationMap[p.CurrentLocation].Transitions {
Outputf("green", "\t%s", loc)
}
cmd := UserInputln()
ProcessCommands(p, cmd)
}
}
func (p *Character) ProcessEvents(events []string) {
for _, evtName := range events {
p.Health += evts[evtName].ProcessEvent(p)
}
}