dice-roller/main.go

51 lines
920 B
Go
Raw Normal View History

2021-08-23 18:53:20 +02:00
package main
import (
"flag"
"fmt"
"math/rand"
"time"
)
func main() {
2021-09-16 11:59:45 +02:00
var surfaces, modifier, diceThrows, attacks 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-09-16 11:59:45 +02:00
flag.IntVar(&attacks, "a", 1, "Attacks")
2021-08-23 18:53:20 +02:00
flag.Parse()
2021-09-16 11:59:45 +02:00
for i := 0; i < attacks; i++ {
if attacks > 1 {
fmt.Println()
}
Cast(surfaces, diceThrows, modifier)
2021-08-28 12:36:16 +02:00
}
2021-08-23 18:53:20 +02:00
}
2021-09-16 11:59:45 +02:00
func Cast(dieSurfaces, castAmount, modifier 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-09-16 11:59:45 +02:00
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
}