mirror of
https://gitlab.com/EternalWanderer/dice-roller.git
synced 2024-11-28 21:03:51 +01:00
Refactor and colors
This commit is contained in:
parent
1d638fa4bd
commit
67a2ec9a38
47
main.go
47
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue