telnetroulette/gun.go

44 lines
649 B
Go
Raw Normal View History

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