mirror of
https://gitlab.com/EternalWanderer/dice-roller.git
synced 2024-11-28 21:03:51 +01:00
More refactor and string formatting
This commit is contained in:
parent
852bd4c906
commit
06c27a2e3e
62
main.go
62
main.go
|
@ -16,12 +16,13 @@ var (
|
|||
type Color string
|
||||
|
||||
const (
|
||||
ColorBlack Color = "\u001b[30m"
|
||||
ColorRed = "\u001b[31m"
|
||||
ColorGreen = "\u001b[32m"
|
||||
ColorYellow = "\u001b[33m"
|
||||
ColorBlue = "\u001b[34m"
|
||||
ColorReset = "\u001b[0m"
|
||||
ColorBlack Color = "\u001b[30m"
|
||||
ColorRed = "\u001b[31m"
|
||||
ColorGreen = "\u001b[32m"
|
||||
ColorYellow = "\u001b[33m"
|
||||
ColorBlue = "\u001b[34m"
|
||||
ColorMagenta = "\u001b[35m"
|
||||
ColorReset = "\u001b[0m"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -31,22 +32,31 @@ func main() {
|
|||
|
||||
switch {
|
||||
case advantage:
|
||||
fmt.Println(string(ColorGreen), "Rolling with advantage...", string(ColorReset))
|
||||
fmt.Println(string(ColorGreen), Advantage(SimpleCast(), SimpleCast()), string(ColorReset))
|
||||
if modifier != 0 {
|
||||
fmt.Printf("%sRolling 1d20 + %d with advantage...%s\n", Color(ColorGreen), modifier, Color(ColorReset))
|
||||
} else {
|
||||
fmt.Printf("%sRolling 1d20 with advantage...%s\n", Color(ColorGreen), Color(ColorReset))
|
||||
}
|
||||
fmt.Printf("\t%s%d%s\n", Color(ColorGreen), Advantage(SimpleCast(), SimpleCast()), Color(ColorReset))
|
||||
|
||||
case disadvantage:
|
||||
fmt.Println(string(ColorRed), "Rolling with disadvantage...", string(ColorReset))
|
||||
fmt.Println(string(ColorRed), Disadvantage(SimpleCast(), SimpleCast()), string(ColorReset))
|
||||
if modifier != 0 {
|
||||
fmt.Printf("%sRolling 1d20 + %d with disadvantage...%s\n", Color(ColorRed), modifier, Color(ColorReset))
|
||||
} else {
|
||||
fmt.Printf("%sRolling 1d20 with disadvantage...%s\n", Color(ColorRed), Color(ColorReset))
|
||||
}
|
||||
fmt.Printf("\t%s%d%s\n", Color(ColorRed), Disadvantage(SimpleCast(), SimpleCast()), Color(ColorReset))
|
||||
|
||||
case attacks < 1:
|
||||
fmt.Println("Attack amount cannot be below 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))
|
||||
fmt.Printf("%sAttack %d:%s\n", Color(ColorBlue), i+1, Color(ColorReset))
|
||||
Cast(surfaces, diceThrows)
|
||||
}
|
||||
default:
|
||||
|
||||
Cast(surfaces, diceThrows)
|
||||
}
|
||||
}
|
||||
|
@ -82,21 +92,21 @@ func Cast(dieSurfaces, castAmount int) {
|
|||
total += cast
|
||||
}
|
||||
|
||||
if castAmount > 1 {
|
||||
fmt.Println(string(ColorBlue), "\tIndividual rolls:", casts, string(ColorReset))
|
||||
}
|
||||
|
||||
if modifier != 0 {
|
||||
fmt.Printf("%sRolling %dd%d + %d...\n%s", ColorYellow, diceThrows, surfaces, modifier, ColorReset)
|
||||
} else {
|
||||
fmt.Printf("%sRolling %dd%d...\n%s", ColorYellow, diceThrows, surfaces, ColorReset)
|
||||
}
|
||||
|
||||
if castAmount > 1 {
|
||||
fmt.Println(Color(ColorMagenta), "\tIndividual rolls:", casts, Color(ColorReset))
|
||||
}
|
||||
|
||||
if modifier != 0 {
|
||||
fmt.Println("\tWithout modifier:", total)
|
||||
fmt.Println(string(ColorGreen), "\tWith modifier:", total+modifier, string(ColorReset))
|
||||
fmt.Println(Color(ColorGreen), "\tWith modifier:", total+modifier, Color(ColorReset))
|
||||
} else {
|
||||
fmt.Println(string(ColorGreen), "\t", total, string(ColorReset))
|
||||
fmt.Println(Color(ColorGreen), "\t", total, Color(ColorReset))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,13 +114,15 @@ func SimpleCast() int {
|
|||
|
||||
var cast = rand.Intn(20) + 1
|
||||
|
||||
fmt.Println("Without modifier:", cast)
|
||||
if modifier != 0 {
|
||||
fmt.Println("Without modifier:", cast)
|
||||
}
|
||||
return cast + modifier
|
||||
}
|
||||
|
||||
func Advantage(x, y int) int {
|
||||
fmt.Println("x:", x)
|
||||
fmt.Println("Y:", y)
|
||||
fmt.Println("\tx:", x)
|
||||
fmt.Println("\tY:", y)
|
||||
if x > y {
|
||||
return x
|
||||
} else {
|
||||
|
@ -119,8 +131,8 @@ func Advantage(x, y int) int {
|
|||
}
|
||||
|
||||
func Disadvantage(x, y int) int {
|
||||
fmt.Println("x:", x)
|
||||
fmt.Println("Y:", y)
|
||||
fmt.Println("\tx:", x)
|
||||
fmt.Println("\tY:", y)
|
||||
if x < y {
|
||||
return x
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue