telnetroulette/gun.go

46 lines
717 B
Go
Raw Normal View History

2024-06-08 13:52:22 +02:00
package main
import "math/rand"
type Gun struct {
doubled bool
magazine []bool
}
// fire
2024-06-08 23:23:20 +02:00
func (g Gun) Shoot(target *Client) (int, []bool) {
shot := 2
if len(g.magazine) == 0 {
return shot, g.magazine
}
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-08 23:23:20 +02:00
target.send("\a")
target.match.Send("")
2024-06-08 13:52:22 +02:00
}
2024-06-08 23:23:20 +02:00
g.magazine = g.Rack()
2024-06-08 13:52:22 +02:00
g.doubled = false
2024-06-08 23:23:20 +02:00
return shot, g.magazine
}
func (g Gun) Rack() []bool {
g.magazine = g.magazine[:len(g.magazine)-1]
return g.magazine
2024-06-08 13:52:22 +02:00
}
2024-06-08 23:23:20 +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-08 23:23:20 +02:00
g.magazine[i] = rand.Intn(6) <= 2
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
}