2021-08-23 18:53:20 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2021-08-28 12:36:16 +02:00
|
|
|
var surfaces, modifier, diceThrows int
|
2021-08-23 18:53:20 +02:00
|
|
|
rand.Seed(time.Now().Unix())
|
2021-08-23 23:19:01 +02:00
|
|
|
flag.IntVar(&surfaces, "s", 20, "Specify amount of die surfaces")
|
2021-08-28 12:36:16 +02:00
|
|
|
flag.IntVar(&diceThrows, "t", 1, "Specify dice diceThrows")
|
|
|
|
flag.IntVar(&modifier, "m", 0, "Stat modifier")
|
2021-08-23 18:53:20 +02:00
|
|
|
flag.Parse()
|
2021-08-28 12:36:16 +02:00
|
|
|
total := Cast(surfaces, diceThrows)
|
|
|
|
if modifier != 0 {
|
|
|
|
fmt.Println("Without modifier:", total)
|
|
|
|
fmt.Println("With modifier:", total+modifier)
|
|
|
|
} else {
|
|
|
|
fmt.Println(total)
|
|
|
|
}
|
2021-08-23 18:53:20 +02:00
|
|
|
}
|
|
|
|
|
2021-08-28 12:36:16 +02:00
|
|
|
func Cast(dieSurfaces, castAmount int) int {
|
2021-08-23 18:53:20 +02:00
|
|
|
var (
|
|
|
|
casts []int
|
|
|
|
cast, total int
|
|
|
|
)
|
|
|
|
|
|
|
|
for i := 0; i < castAmount; i++ {
|
|
|
|
cast = rand.Intn(dieSurfaces) + 1
|
|
|
|
casts = append(casts, cast)
|
|
|
|
total += cast
|
|
|
|
}
|
2021-08-23 23:19:01 +02:00
|
|
|
|
|
|
|
if castAmount > 1 {
|
|
|
|
fmt.Println(casts)
|
|
|
|
}
|
2021-08-28 12:36:16 +02:00
|
|
|
return total
|
2021-08-23 18:53:20 +02:00
|
|
|
}
|