63 lines
939 B
Go
63 lines
939 B
Go
package game
|
|
|
|
type Item int8
|
|
|
|
const (
|
|
ItemNone Item = iota
|
|
ItemLens
|
|
ItemCig
|
|
ItemBeer
|
|
ItemCuff
|
|
ItemKnife
|
|
)
|
|
|
|
func NewItem(rng *RNG) Item {
|
|
return Item(rng.Intn(5)) + 1
|
|
}
|
|
|
|
func (i Item) Apply(g *Match) bool {
|
|
switch i {
|
|
case ItemNone:
|
|
return false
|
|
case ItemLens:
|
|
if g.reveal {
|
|
return false
|
|
}
|
|
g.reveal = true
|
|
return true
|
|
case ItemCig:
|
|
cur := g.CurrentPlayer()
|
|
if cur.hp < g.hp {
|
|
cur.hp++
|
|
// Cigs are always used, even if they have no effect.
|
|
}
|
|
return true
|
|
case ItemBeer:
|
|
g.popShell()
|
|
if g.Empty() {
|
|
g.NextGame()
|
|
}
|
|
return true
|
|
case ItemCuff:
|
|
opp := g.Opponent()
|
|
if opp.cuffs != Uncuffed {
|
|
return false
|
|
}
|
|
opp.cuffs = Cuffed
|
|
return true
|
|
case ItemKnife:
|
|
if g.damage != 1 {
|
|
return false
|
|
}
|
|
g.damage = 2
|
|
return true
|
|
default:
|
|
panic("shotgun: unknown item")
|
|
}
|
|
}
|
|
|
|
func (i Item) String() string {
|
|
s := [...]string{"", "🔍", "🚬", "🍺", "👮", "🔪"}
|
|
return s[i]
|
|
}
|