shotgun/game/item.go

68 lines
1.1 KiB
Go

package game
type item int8
const (
itemNone item = iota
itemLens
itemCig
itemBeer
itemCuff
itemKnife
)
func newItem(rng *xoshiro) item {
return item(rng.Intn(5)) + 1
}
func (i item) apply(g *Match) bool {
switch i {
case itemNone:
return false
case itemLens:
// Lenses are always used, even if they have no effect.
g.action = actLens
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.
}
g.action = actCig
return true
case itemBeer:
g.popShell()
g.action = actBeer
if g.Empty() {
g.action = actBeerGameEnd
g.NextGame()
}
return true
case itemCuff:
opp := g.Opponent()
if opp.cuffs != uncuffed {
return false
}
g.action = actCuff
opp.cuffs = cuffedSkip
return true
case itemKnife:
if g.damage != 1 {
return false
}
g.action = actKnife
g.damage = 2
return true
default:
panic("shotgun: unknown item")
}
}
var itemNames = [...]string{"", "🔍", "🚬", "🍺", "👮", "🔪"}
func (i item) String() string {
return itemNames[i]
}