mirror of
https://gitlab.com/EternalWanderer/dice-roller.git
synced 2025-06-08 06:14:25 +02:00
Moved rng back to where needed and rewrote some thing to make it actually work it this time
This commit is contained in:
parent
2d560c42a0
commit
1e57a27bcf
2 changed files with 34 additions and 11 deletions
20
Dice/Dice.go
20
Dice/Dice.go
|
@ -4,15 +4,26 @@ import (
|
|||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitlab.com/EternalWanderer/dice-roller/Colors"
|
||||
)
|
||||
|
||||
var (
|
||||
surfaces, diceThrows, modidier int
|
||||
initRandom bool
|
||||
)
|
||||
|
||||
func InitRandom(initialised bool) {
|
||||
if initialised {
|
||||
return
|
||||
}
|
||||
rand.Seed(time.Now().Unix())
|
||||
initRandom = true
|
||||
}
|
||||
|
||||
func Cast(surfaces, diceThrows, modifier int) {
|
||||
InitRandom(initRandom)
|
||||
var (
|
||||
casts []int
|
||||
cast, total int
|
||||
|
@ -46,13 +57,16 @@ func Cast(surfaces, diceThrows, modifier int) {
|
|||
}
|
||||
|
||||
func SimpleCast() int {
|
||||
InitRandom(initRandom)
|
||||
|
||||
var cast = rand.Intn(20) + 1
|
||||
|
||||
return cast
|
||||
}
|
||||
|
||||
func Advantage(x, y int) (int, int, int) {
|
||||
func Advantage() (int, int, int) {
|
||||
x := SimpleCast()
|
||||
y := SimpleCast()
|
||||
if x > y {
|
||||
return x, x, y
|
||||
} else {
|
||||
|
@ -60,7 +74,9 @@ func Advantage(x, y int) (int, int, int) {
|
|||
}
|
||||
}
|
||||
|
||||
func Disadvantage(x, y int) (int, int, int) {
|
||||
func Disadvantage() (int, int, int) {
|
||||
x := SimpleCast()
|
||||
y := SimpleCast()
|
||||
if x < y {
|
||||
return x, x, y
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue