From 67a2ec9a3832833cef24e961ffec79896d65622f Mon Sep 17 00:00:00 2001 From: Azathoth Date: Fri, 29 Jul 2022 12:26:50 +0200 Subject: [PATCH] Refactor and colors --- main.go | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index c3b35c8..54ab9cf 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,17 @@ var ( advantage, disadvantage bool ) +type Color string + +const ( + ColorBlack Color = "\u001b[30m" + ColorRed = "\u001b[31m" + ColorGreen = "\u001b[32m" + ColorYellow = "\u001b[33m" + ColorBlue = "\u001b[34m" + ColorReset = "\u001b[0m" +) + func main() { rand.Seed(time.Now().Unix()) @@ -20,17 +31,18 @@ func main() { switch { case advantage: - fmt.Println("Advantage") - fmt.Println(Advantage(SimpleCast(), SimpleCast())) + fmt.Println(string(ColorGreen), "Rolling with advantage...", string(ColorReset)) + fmt.Println(string(ColorGreen), Advantage(SimpleCast(), SimpleCast()), string(ColorReset)) case disadvantage: - fmt.Println("Disadvantage") - fmt.Println(Disadvantage(SimpleCast(), SimpleCast())) + fmt.Println(string(ColorRed), "Rolling with disadvantage...", string(ColorReset)) + fmt.Println(string(ColorRed), Disadvantage(SimpleCast(), SimpleCast()), string(ColorReset)) case attacks < 1: fmt.Println("Attack amount cannot be below 1.") os.Exit(1) case attacks > 1: for i := 0; i < attacks; i++ { fmt.Println() + fmt.Println(string(ColorYellow), "Attack:", i+1, string(ColorReset)) Cast(surfaces, diceThrows) } default: @@ -39,13 +51,20 @@ func main() { } func ParseFlags() { - flag.IntVar(&surfaces, "surfaces", 20, "Specify amount of die surfaces") - flag.IntVar(&diceThrows, "throws", 1, "Specify dice diceThrows") - flag.IntVar(&modifier, "modifier", 0, "Stat modifier") - flag.IntVar(&attacks, "attacks", 1, "Attacks") + flag.IntVar(&surfaces, "surfaces", 20, "Use to specify die surfaces, does not apply to advantage and disadvantage") + flag.IntVar(&surfaces, "s", 20, "Use to specify die surfaces, defaults to 20") - flag.BoolVar(&advantage, "advantage", false, "Advantage") - flag.BoolVar(&disadvantage, "disadvantage", false, "Disadvantage") + flag.IntVar(&diceThrows, "throws", 1, "Specify amount of dice to cast") + flag.IntVar(&diceThrows, "c", 1, "Specify amount of dice to cast") + + flag.IntVar(&modifier, "modifier", 0, "Add modifier to result of rolls") + flag.IntVar(&modifier, "m", 0, "Add modifier to result of rolls") + + flag.IntVar(&attacks, "attacks", 1, "Roll a set rules multiple times, does not apply to advantage and disadvantage") + flag.IntVar(&attacks, "a", 1, "Roll a set rules multiple times, does not apply to advantage and disadvantage") + + flag.BoolVar(&advantage, "advantage", false, "Roll with advantage") + flag.BoolVar(&disadvantage, "disadvantage", false, "Roll with disadvantage") flag.Parse() } @@ -63,14 +82,14 @@ func Cast(dieSurfaces, castAmount int) { } if castAmount > 1 { - fmt.Println(casts) + fmt.Println(string(ColorBlue), "\tIndividual rolls:", casts, string(ColorReset)) } if modifier != 0 { - fmt.Println("Without modifier:", total) - fmt.Println("With modifier:", total+modifier) + fmt.Println("\tWithout modifier:", total) + fmt.Println(string(ColorGreen), "\tWith modifier:", total+modifier, string(ColorReset)) } else { - fmt.Println(total) + fmt.Println(string(ColorGreen), "\t", total, string(ColorReset)) } }