-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchoose_action.go
42 lines (35 loc) · 1.27 KB
/
choose_action.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
package main
import "fmt"
func askAboutnextAction() string {
var action string
fmt.Print("Enter number of the next action\n")
fmt.Print("attack: 1\n")
fmt.Print("heal: 2\n")
fmt.Scan(&action)
return action
}
func chooseAction(crossbow, pan, sword Weapon, hero Hero, dragon Dragon, maxHealth int, action string) (Hero, Dragon, Weapon, Weapon, Weapon) {
var weapon Weapon
switch action {
case "1":
chooseWeapon := chooseWeapon()
weapon, crossbow, pan = usingWeapon(crossbow, pan, sword, chooseWeapon)
chance := chanceToAttack()
successfulAttack := heroSuccessfullyAttack(weapon.missChance, chance)
dragon.health, weapon, crossbow, pan, sword = heroAttack(hero, dragon, crossbow, pan, sword, weapon, successfulAttack)
case "2":
fmt.Println(hero.health, maxHealth)
if hero.health < maxHealth {
hero.health = heroHeal(hero, maxHealth)
} else {
fmt.Printf("Sorry, but you cant heal your hero, because HP is max. Please, choose another action\n")
action = askAboutnextAction()
chooseAction(crossbow, pan, sword, hero, dragon, maxHealth, action)
}
default:
fmt.Printf("Please, choose the correct action\n")
action = askAboutnextAction()
chooseAction(crossbow, pan, sword, hero, dragon, maxHealth, action)
}
return hero, dragon, crossbow, pan, sword
}