telnetroulette/gun.go
2024-06-08 23:23:20 +02:00

46 lines
717 B
Go

package main
import "math/rand"
type Gun struct {
doubled bool
magazine []bool
}
// fire
func (g Gun) Shoot(target *Client) (int, []bool) {
shot := 2
if len(g.magazine) == 0 {
return shot, g.magazine
}
shot = 0
if g.magazine[len(g.magazine)-1] {
shot = 1
if g.doubled {
target.HP -= 2
} else {
target.HP -= 1
}
target.send("\a")
target.match.Send("")
}
g.magazine = g.Rack()
g.doubled = false
return shot, g.magazine
}
func (g Gun) Rack() []bool {
g.magazine = g.magazine[:len(g.magazine)-1]
return g.magazine
}
func (g Gun) Reload(count int) []bool {
g.magazine = make([]bool, count)
for i := 0; i < count; i++ {
g.magazine[i] = rand.Intn(6) <= 2
}
return g.magazine
}