telnetroulette/gun.go
2024-06-09 11:02:18 +02:00

44 lines
649 B
Go

package main
import "math/rand"
type gun struct {
doubled bool
magazine []bool
}
func (g *gun) shoot(target *client) int {
shot := 2
if len(g.magazine) == 0 {
return shot
}
shot = 0
if g.magazine[len(g.magazine)-1] {
shot = 1
if g.doubled {
target.HP -= 2
} else {
target.HP -= 1
}
target.send("\a\a")
target.match.send("")
}
g.rack()
g.doubled = false
return shot
}
func (g *gun) rack() {
g.magazine = g.magazine[:len(g.magazine)-1]
}
func (g *gun) reload(count int) []bool {
g.magazine = make([]bool, count)
for i := 0; i < count; i++ {
g.magazine[i] = rand.Int63()&(1<<62) == 0
}
return g.magazine
}