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 *RNG) 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]
}