-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.go
41 lines (35 loc) · 902 Bytes
/
player.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
package main
var names = []string{"Alice", "Bob", "Chloe", "Daphne", "Eric", "Franck", "George", "Hans", "Ines", "Jules", "Klaus", "Lawrence"}
const fed = 0
const hungry = 1
const starving = 2
// Player represent a person playing in the game
type Player struct {
name string // The player name, used as identifier
foodStatus int // Wether this player is fed, hungry or starving
alive bool // wether this player is dead or not
}
func (p *Player) lunch(hasLunch bool) {
if hasLunch {
p.foodStatus = fed
} else {
p.foodStatus++
}
if p.foodStatus > starving {
p.alive = false
}
}
func (p *Player) getFoodStatusAsString() string {
switch p.foodStatus {
case fed:
return "fed"
case hungry:
return "hungry"
case starving:
return "starving"
}
return "unknown"
}
func newPlayer(rank int) Player {
return Player{name: names[rank], foodStatus: fed, alive: true}
}