-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (61 loc) · 1.2 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
package main
import (
"errors"
"fmt"
"github.com/business-phil/gorena/combatant"
"github.com/manifoldco/promptui"
)
func main() {
namePrompt := promptui.Prompt{
Label: "What is your name? ",
Validate: func(input string) error {
if input == "" {
return errors.New("Must enter name")
}
return nil
},
}
name, err := namePrompt.Run()
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("Welcome, %s\n", name)
player := &combatant.Combatant{
Name: name,
MaxHp: 50,
CurrentHp: 50,
MaxDamage: 8,
}
opponent := &combatant.Combatant{
Name: "Opponent",
MaxHp: 30,
CurrentHp: 30,
MaxDamage: 10,
}
actionPrompt := promptui.Select{
Label: "What will you do? ",
Items: []string{"Attack", "Heal"},
}
for player.CurrentHp > 0 && opponent.CurrentHp > 0 {
_, result, err := actionPrompt.Run()
if err != nil {
fmt.Println(err)
return
}
if result == "Attack" {
_, opponentIsDead := player.Attack(opponent)
if opponentIsDead {
fmt.Println("You win!!")
return
}
} else if result == "Heal" {
player.Heal()
}
_, playerIsDead := opponent.Attack(player)
if playerIsDead {
fmt.Println("You lose!!")
return
}
}
}