From b45c2ab92b118c0333d34fdd547225b7b09bf7b6 Mon Sep 17 00:00:00 2001 From: Azathoth Date: Thu, 16 Sep 2021 11:59:45 +0200 Subject: [PATCH] Added way to roll multiple attacks --- .gitignore | 1 + main.go | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 7270fec..3decc75 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ dice-roller +.idea diff --git a/main.go b/main.go index 6a44894..8e002e1 100644 --- a/main.go +++ b/main.go @@ -8,22 +8,24 @@ import ( ) func main() { - var surfaces, modifier, diceThrows int + 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() - total := Cast(surfaces, diceThrows) - if modifier != 0 { - fmt.Println("Without modifier:", total) - fmt.Println("With modifier:", total+modifier) - } else { - fmt.Println(total) + + for i := 0; i < attacks; i++ { + if attacks > 1 { + fmt.Println() + } + Cast(surfaces, diceThrows, modifier) } } -func Cast(dieSurfaces, castAmount int) int { +func Cast(dieSurfaces, castAmount, modifier int) { var ( casts []int cast, total int @@ -38,5 +40,11 @@ func Cast(dieSurfaces, castAmount int) int { if castAmount > 1 { fmt.Println(casts) } - return total + + if modifier != 0 { + fmt.Println("Without modifier:", total) + fmt.Println("With modifier:", total+modifier) + } else { + fmt.Println(total) + } }