-
Notifications
You must be signed in to change notification settings - Fork 0
/
action_walk.go
57 lines (40 loc) · 1009 Bytes
/
action_walk.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
package main
import "gopkg.in/AlecAivazis/survey.v1"
func createActionWalk(w *World) *ActionWalk {
action := &ActionWalk{name: "идти", world: w}
return action
}
type ActionWalk struct {
name string
world *World
}
func (a *ActionWalk) GetName() string {
return a.name
}
func (a *ActionWalk) IsMatch(name string) bool {
return a.name == name
}
func (a *ActionWalk) ExecuteInteractive() string {
player := a.world.Player
name := ""
prompt := &survey.Select{
Message: "Идти:",
Options: player.Place.ExitsNames(),
}
survey.AskOne(prompt, &name, nil)
return a.Execute([]string{name})
}
func (a *ActionWalk) Execute(args []string) string {
world := a.world
if len(args) > 0 {
placeName := args[0]
for _, door := range world.Player.Place.Exits {
if door.destination.Name() == placeName {
world.Player.Place = door.destination
return world.Player.Place.EnteringMessage()
}
}
return "нет пути в " + placeName
}
return "некуда идти"
}