mirror of
https://gitlab.com/EternalWanderer/dice-roller.git
synced 2024-11-28 21:03:51 +01:00
43 lines
797 B
Go
43 lines
797 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
var surfaces, modifier, diceThrows int
|
|
rand.Seed(time.Now().Unix())
|
|
flag.IntVar(&surfaces, "s", 20, "Specify amount of die surfaces")
|
|
flag.IntVar(&diceThrows, "t", 1, "Specify dice diceThrows")
|
|
flag.IntVar(&modifier, "m", 0, "Stat modifier")
|
|
flag.Parse()
|
|
total := Cast(surfaces, diceThrows)
|
|
if modifier != 0 {
|
|
fmt.Println("Without modifier:", total)
|
|
fmt.Println("With modifier:", total+modifier)
|
|
} else {
|
|
fmt.Println(total)
|
|
}
|
|
}
|
|
|
|
func Cast(dieSurfaces, castAmount int) int {
|
|
var (
|
|
casts []int
|
|
cast, total int
|
|
)
|
|
|
|
for i := 0; i < castAmount; i++ {
|
|
cast = rand.Intn(dieSurfaces) + 1
|
|
casts = append(casts, cast)
|
|
total += cast
|
|
}
|
|
|
|
if castAmount > 1 {
|
|
fmt.Println(casts)
|
|
}
|
|
return total
|
|
}
|