dice-roller/main.go
2021-09-16 11:59:45 +02:00

51 lines
920 B
Go

package main
import (
"flag"
"fmt"
"math/rand"
"time"
)
func main() {
var surfaces, modifier, diceThrows, attacks 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.IntVar(&attacks, "a", 1, "Attacks")
flag.Parse()
for i := 0; i < attacks; i++ {
if attacks > 1 {
fmt.Println()
}
Cast(surfaces, diceThrows, modifier)
}
}
func Cast(dieSurfaces, castAmount, modifier 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)
}
if modifier != 0 {
fmt.Println("Without modifier:", total)
fmt.Println("With modifier:", total+modifier)
} else {
fmt.Println(total)
}
}