Refactor and colors

This commit is contained in:
Nox Sluijtman 2022-07-29 12:26:50 +02:00
parent 1d638fa4bd
commit 67a2ec9a38

47
main.go
View file

@ -13,6 +13,17 @@ var (
advantage, disadvantage bool 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() { func main() {
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())
@ -20,17 +31,18 @@ func main() {
switch { switch {
case advantage: case advantage:
fmt.Println("Advantage") fmt.Println(string(ColorGreen), "Rolling with advantage...", string(ColorReset))
fmt.Println(Advantage(SimpleCast(), SimpleCast())) fmt.Println(string(ColorGreen), Advantage(SimpleCast(), SimpleCast()), string(ColorReset))
case disadvantage: case disadvantage:
fmt.Println("Disadvantage") fmt.Println(string(ColorRed), "Rolling with disadvantage...", string(ColorReset))
fmt.Println(Disadvantage(SimpleCast(), SimpleCast())) fmt.Println(string(ColorRed), Disadvantage(SimpleCast(), SimpleCast()), string(ColorReset))
case attacks < 1: case attacks < 1:
fmt.Println("Attack amount cannot be below 1.") fmt.Println("Attack amount cannot be below 1.")
os.Exit(1) os.Exit(1)
case attacks > 1: case attacks > 1:
for i := 0; i < attacks; i++ { for i := 0; i < attacks; i++ {
fmt.Println() fmt.Println()
fmt.Println(string(ColorYellow), "Attack:", i+1, string(ColorReset))
Cast(surfaces, diceThrows) Cast(surfaces, diceThrows)
} }
default: default:
@ -39,13 +51,20 @@ func main() {
} }
func ParseFlags() { func ParseFlags() {
flag.IntVar(&surfaces, "surfaces", 20, "Specify amount of die surfaces") flag.IntVar(&surfaces, "surfaces", 20, "Use to specify die surfaces, does not apply to advantage and disadvantage")
flag.IntVar(&diceThrows, "throws", 1, "Specify dice diceThrows") flag.IntVar(&surfaces, "s", 20, "Use to specify die surfaces, defaults to 20")
flag.IntVar(&modifier, "modifier", 0, "Stat modifier")
flag.IntVar(&attacks, "attacks", 1, "Attacks")
flag.BoolVar(&advantage, "advantage", false, "Advantage") flag.IntVar(&diceThrows, "throws", 1, "Specify amount of dice to cast")
flag.BoolVar(&disadvantage, "disadvantage", false, "Disadvantage") 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() flag.Parse()
} }
@ -63,14 +82,14 @@ func Cast(dieSurfaces, castAmount int) {
} }
if castAmount > 1 { if castAmount > 1 {
fmt.Println(casts) fmt.Println(string(ColorBlue), "\tIndividual rolls:", casts, string(ColorReset))
} }
if modifier != 0 { if modifier != 0 {
fmt.Println("Without modifier:", total) fmt.Println("\tWithout modifier:", total)
fmt.Println("With modifier:", total+modifier) fmt.Println(string(ColorGreen), "\tWith modifier:", total+modifier, string(ColorReset))
} else { } else {
fmt.Println(total) fmt.Println(string(ColorGreen), "\t", total, string(ColorReset))
} }
} }