e95d526266
Fixes #2.
62 lines
1004 B
Go
62 lines
1004 B
Go
package game
|
|
|
|
import (
|
|
"slices"
|
|
|
|
"git.sunturtle.xyz/studio/shotgun/player"
|
|
"git.sunturtle.xyz/studio/shotgun/serve"
|
|
)
|
|
|
|
type Player struct {
|
|
id player.ID
|
|
hp int8
|
|
items [8]Item
|
|
cuffs CuffState
|
|
}
|
|
|
|
func (p *Player) StartRound(hp int8) {
|
|
p.hp = hp
|
|
clear(p.items[:])
|
|
}
|
|
|
|
func (p *Player) StartGroup(rng *RNG, items int) {
|
|
for i := 0; i < items; i++ {
|
|
k := slices.Index(p.items[:], ItemNone)
|
|
if k < 0 {
|
|
break
|
|
}
|
|
p.items[k] = NewItem(rng)
|
|
}
|
|
p.cuffs = Uncuffed
|
|
}
|
|
|
|
func (p *Player) DTO() serve.Player {
|
|
r := serve.Player{
|
|
HP: p.hp,
|
|
Cuffs: p.cuffs != Uncuffed,
|
|
}
|
|
for k, i := range p.items {
|
|
r.Items[k] = i.String()
|
|
}
|
|
return r
|
|
}
|
|
|
|
// Is returns whether the player has the same ID as other.
|
|
// This exists for tests.
|
|
func (p *Player) Is(other *Player) bool {
|
|
return p.id == other.id
|
|
}
|
|
|
|
type CuffState uint8
|
|
|
|
const (
|
|
Uncuffed CuffState = iota
|
|
Cuffed
|
|
CuffedSkip
|
|
)
|
|
|
|
func (c CuffState) NextState() CuffState {
|
|
var m = [...]CuffState{Uncuffed, Uncuffed, Cuffed}
|
|
return m[c]
|
|
}
|