-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (58 loc) · 1.54 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
73
74
75
76
package main
import (
"github.com/abrl91/monsterslayer/actions"
"github.com/abrl91/monsterslayer/interaction"
)
var currentRound = 0
var gameRounds = []interaction.RoundData{}
func main() {
startGame()
winner := ""
for winner == "" {
winner = executeRound()
}
endGame(winner)
}
func startGame() {
interaction.PrintGreetings()
}
// return the winner
func executeRound() string {
currentRound++
isSpecialRound := currentRound%3 == 0
interaction.ShowAvailableActions(isSpecialRound)
userChoice := interaction.GetPlayerChoice(isSpecialRound)
var playerAttackDamage int
var playerHealValue int
var monsterAttackDamage int
if userChoice == "ATTACK" {
playerAttackDamage = actions.AttackMonster(false)
} else if userChoice == "HEAL" {
playerHealValue = actions.HealPlayer()
} else {
// SPECIAL_ATTACK
playerAttackDamage = actions.AttackMonster(true)
}
monsterAttackDamage = actions.AttackPlayer()
playerHealth, monsterHealth := actions.GetHealthState()
roundData := interaction.RoundData{
Action: userChoice,
PlayerHealth: playerHealth,
MonsterHealth: monsterHealth,
PlayerAttackDamage: playerAttackDamage,
PlayerHealValue: playerHealValue,
MonsterAttackDamage: monsterAttackDamage,
}
interaction.PrintRoundStatistics(&roundData)
gameRounds = append(gameRounds, roundData)
if playerHealth <= 0 {
return "MONSTER"
} else if monsterHealth <= 0 {
return "PLAYER"
}
return ""
}
func endGame(winner string) {
interaction.DeclareWinner(winner)
interaction.WriteLogFile(&gameRounds)
}