Added way to roll multiple attacks

This commit is contained in:
Azathoth 2021-09-16 11:59:45 +02:00
parent 322f706e4d
commit b45c2ab92b
2 changed files with 18 additions and 9 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
dice-roller dice-roller
.idea

26
main.go
View file

@ -8,22 +8,24 @@ import (
) )
func main() { func main() {
var surfaces, modifier, diceThrows int var surfaces, modifier, diceThrows, attacks int
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())
flag.IntVar(&surfaces, "s", 20, "Specify amount of die surfaces") flag.IntVar(&surfaces, "s", 20, "Specify amount of die surfaces")
flag.IntVar(&diceThrows, "t", 1, "Specify dice diceThrows") flag.IntVar(&diceThrows, "t", 1, "Specify dice diceThrows")
flag.IntVar(&modifier, "m", 0, "Stat modifier") flag.IntVar(&modifier, "m", 0, "Stat modifier")
flag.IntVar(&attacks, "a", 1, "Attacks")
flag.Parse() flag.Parse()
total := Cast(surfaces, diceThrows)
if modifier != 0 { for i := 0; i < attacks; i++ {
fmt.Println("Without modifier:", total) if attacks > 1 {
fmt.Println("With modifier:", total+modifier) fmt.Println()
} else { }
fmt.Println(total) Cast(surfaces, diceThrows, modifier)
} }
} }
func Cast(dieSurfaces, castAmount int) int { func Cast(dieSurfaces, castAmount, modifier int) {
var ( var (
casts []int casts []int
cast, total int cast, total int
@ -38,5 +40,11 @@ func Cast(dieSurfaces, castAmount int) int {
if castAmount > 1 { if castAmount > 1 {
fmt.Println(casts) fmt.Println(casts)
} }
return total
if modifier != 0 {
fmt.Println("Without modifier:", total)
fmt.Println("With modifier:", total+modifier)
} else {
fmt.Println(total)
}
} }