shotgun/game/item.go

107 lines
1.8 KiB
Go
Raw Normal View History

2024-01-20 22:06:56 -06:00
package game
2024-04-07 15:14:57 -05:00
import "math/rand/v2"
type item int8
2024-01-20 22:06:56 -06:00
const (
itemNone item = iota
itemLens
itemCig
itemBeer
itemCuff
itemKnife
itemAdrenaline
itemPhone
itemInverter
itemPill
2024-01-20 22:06:56 -06:00
)
2024-04-07 15:14:57 -05:00
func newItem() item {
return item(rand.IntN(9)) + 1
2024-01-20 22:06:56 -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()
if opp.cuffs != uncuffed {
return false
}
g.action = actCuff
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
case itemAdrenaline:
g.action = actAdrenaline
// TODO(zeph): implement
return true
case itemPhone:
g.action = actPhone
// TODO(zeph): implement
return true
case itemInverter:
g.action = actInverter
g.shells[0] = !g.shells[0]
return true
case itemPill:
cur := g.CurrentPlayer()
if rand.Uint64() <= (1<<65)/5 {
g.action = actPillsHeal
cur.hp = min(cur.hp+2, g.hp)
} else {
g.action = actPillsHurt
cur.hp--
}
return true
default:
panic("shotgun: unknown item")
}
}
2024-01-21 00:47:12 -06:00
var itemNames = [...]string{
itemNone: "",
itemLens: "🔍",
itemCig: "🚬",
itemBeer: "🍺",
itemCuff: "👮",
itemKnife: "🔪",
itemAdrenaline: "💉",
itemPhone: "📱",
itemInverter: "🧲",
itemPill: "💊",
}
func (i item) String() string {
return itemNames[i]
2024-01-21 00:47:12 -06:00
}