add new items and handle the easy ones

For #17.
This commit is contained in:
Branden J Brown 2024-04-07 16:04:38 -05:00
parent 29a14960f4
commit c8db9d1959
4 changed files with 57 additions and 6 deletions

View File

@ -17,6 +17,11 @@ const (
actBeer // note prev indicates whether the shell was live
actCuff
actKnife
actAdrenaline
actPhone
actInverter
actPillsHeal
actPillsHurt
actDealerConcedes // dealer concedes
actChallengerConcedes // challenger concedes

View File

@ -19,13 +19,18 @@ func _() {
_ = x[actBeer-8]
_ = x[actCuff-9]
_ = x[actKnife-10]
_ = x[actDealerConcedes-11]
_ = x[actChallengerConcedes-12]
_ = x[actAdrenaline-11]
_ = x[actPhone-12]
_ = x[actInverter-13]
_ = x[actPillsHeal-14]
_ = x[actPillsHurt-15]
_ = x[actDealerConcedes-16]
_ = x[actChallengerConcedes-17]
}
const _action_name = "StartShootGameEndBeerGameEndChallengerWinsDealerWinsLensCigBeerCuffKnifeDealerConcedesChallengerConcedes"
const _action_name = "StartShootGameEndBeerGameEndChallengerWinsDealerWinsLensCigBeerCuffKnifeAdrenalinePhoneInverterPillsHealPillsHurtDealerConcedesChallengerConcedes"
var _action_index = [...]uint8{0, 5, 10, 17, 28, 42, 52, 56, 59, 63, 67, 72, 86, 104}
var _action_index = [...]uint8{0, 5, 10, 17, 28, 42, 52, 56, 59, 63, 67, 72, 82, 87, 95, 104, 113, 127, 145}
func (i action) String() string {
if i >= action(len(_action_index)-1) {

View File

@ -11,10 +11,14 @@ const (
itemBeer
itemCuff
itemKnife
itemAdrenaline
itemPhone
itemInverter
itemPill
)
func newItem() item {
return item(rand.IntN(5)) + 1
return item(rand.IntN(9)) + 1
}
func (i item) apply(g *Match) bool {
@ -57,12 +61,45 @@ func (i item) apply(g *Match) bool {
g.action = actKnife
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")
}
}
var itemNames = [...]string{"", "🔍", "🚬", "🍺", "👮", "🔪"}
var itemNames = [...]string{
itemNone: "",
itemLens: "🔍",
itemCig: "🚬",
itemBeer: "🍺",
itemCuff: "👮",
itemKnife: "🔪",
itemAdrenaline: "💉",
itemPhone: "📱",
itemInverter: "🧲",
itemPill: "💊",
}
func (i item) String() string {
return itemNames[i]

View File

@ -13,6 +13,10 @@ func TestItemStrings(t *testing.T) {
{itemBeer, "🍺"},
{itemCuff, "👮"},
{itemKnife, "🔪"},
{itemAdrenaline, "💉"},
{itemPhone, "📱"},
{itemInverter, "🧲"},
{itemPill, "💊"},
}
for _, c := range cases {
got := c.item.String()