shotgun/game/item.go

68 lines
1.1 KiB
Go
Raw Normal View History

2024-01-20 22:06:56 -06:00
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
}
2024-01-28 12:42:42 -06:00
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
2024-01-21 04:16:48 -06:00
g.reveal = true
return true
case ItemCig:
cur := g.CurrentPlayer()
2024-01-21 04:16:48 -06:00
if cur.hp < g.hp {
cur.hp++
2024-01-21 18:41:43 -06:00
// Cigs are always used, even if they have no effect.
}
g.action = actCig
2024-01-21 18:41:43 -06:00
return true
case ItemBeer:
2024-01-28 12:42:42 -06:00
g.popShell()
g.action = actBeer
if g.Empty() {
g.action = actBeerGameEnd
2024-01-28 12:42:42 -06:00
g.NextGame()
}
return true
case ItemCuff:
opp := g.Opponent()
2024-01-21 04:16:48 -06:00
if opp.cuffs != Uncuffed {
return false
}
g.action = actCuff
2024-02-03 13:42:56 -06:00
opp.cuffs = CuffedSkip
return true
case ItemKnife:
2024-01-21 04:16:48 -06:00
if g.damage != 1 {
return false
}
g.action = actKnife
2024-01-21 04:16:48 -06:00
g.damage = 2
return true
default:
panic("shotgun: unknown item")
}
}
2024-01-21 00:47:12 -06:00
var itemNames = [...]string{"", "🔍", "🚬", "🍺", "👮", "🔪"}
2024-01-21 00:47:12 -06:00
func (i Item) String() string {
return itemNames[i]
2024-01-21 00:47:12 -06:00
}