-
Notifications
You must be signed in to change notification settings - Fork 0
/
action_wear.go
53 lines (38 loc) · 971 Bytes
/
action_wear.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
package main
import "gopkg.in/AlecAivazis/survey.v1"
type ActionWear struct {
name string
world *World
}
func createActionWear(w *World) *ActionWear {
action := &ActionWear{name: "одеть", world: w}
return action
}
func (a *ActionWear) GetName() string {
return a.name
}
func (a *ActionWear) IsMatch(name string) bool {
return a.name == name
}
func (a *ActionWear) ExecuteInteractive() string {
player := a.world.Player
name := ""
prompt := &survey.Select{
Message: "Надеть:",
Options: player.Place.getNameItemsNames(),
}
survey.AskOne(prompt, &name, nil)
return a.Execute([]string{name})
}
func (a *ActionWear) Execute(args []string) string {
player := a.world.Player
place := player.Place
if len(args) > 0 {
gameItemName := args[0]
if gameItem, exist := place.getItemByName(gameItemName); exist {
player.Place.removeGameItem(gameItem)
return player.wearGameItem(gameItem)
}
}
return "нечего брать"
}