mirror of
https://gitlab.com/EternalWanderer/dice-roller.git
synced 2025-06-08 06:14:25 +02:00
Proper refactor
This commit is contained in:
parent
6fb022aa7d
commit
b4e0356ef5
4 changed files with 135 additions and 110 deletions
76
Dice/Dice.go
Normal file
76
Dice/Dice.go
Normal file
|
@ -0,0 +1,76 @@
|
|||
package Dice
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
|
||||
"gitlab.com/EternalWanderer/dice-roller/Colors"
|
||||
)
|
||||
|
||||
var (
|
||||
surfaces, diceThrows, modidier int
|
||||
)
|
||||
|
||||
func Cast(surfaces, diceThrows, modifier int) {
|
||||
var (
|
||||
casts []int
|
||||
cast, total int
|
||||
)
|
||||
|
||||
for i := 0; i < diceThrows; i++ {
|
||||
cast = rand.Intn(surfaces) + 1
|
||||
casts = append(casts, cast)
|
||||
total += cast
|
||||
}
|
||||
|
||||
switch {
|
||||
case modifier != 0:
|
||||
fmt.Printf("%sRolling %dd%d + %d...\n%s", Colors.ColorYellow, diceThrows, surfaces, modifier, Colors.ColorReset)
|
||||
default:
|
||||
fmt.Printf("%sRolling %dd%d...\n%s", Colors.ColorYellow, diceThrows, surfaces, Colors.ColorReset)
|
||||
}
|
||||
|
||||
if diceThrows > 1 {
|
||||
fmt.Println(Colors.ColorMagenta, "\tIndividual rolls:",
|
||||
strings.Trim(fmt.Sprint(casts), "[]"),
|
||||
Colors.ColorReset)
|
||||
}
|
||||
|
||||
if modifier != 0 {
|
||||
fmt.Println("\tWithout modifier:", total)
|
||||
fmt.Println(Colors.ColorGreen, "\tWith modifier:", total+modifier, Colors.ColorReset)
|
||||
} else {
|
||||
fmt.Printf("%s\t%d%s\n", Colors.ColorGreen, total, Colors.ColorReset)
|
||||
}
|
||||
}
|
||||
|
||||
func SimpleCast(modifier int) int {
|
||||
|
||||
var cast = rand.Intn(20) + 1
|
||||
|
||||
if modifier != 0 {
|
||||
fmt.Println("Without modifier:", cast)
|
||||
}
|
||||
return cast + modifier
|
||||
}
|
||||
|
||||
func Advantage(x, y int) int {
|
||||
fmt.Println("\tx:", x)
|
||||
fmt.Println("\tY:", y)
|
||||
if x > y {
|
||||
return x
|
||||
} else {
|
||||
return y
|
||||
}
|
||||
}
|
||||
|
||||
func Disadvantage(x, y int) int {
|
||||
fmt.Println("\tx:", x)
|
||||
fmt.Println("\tY:", y)
|
||||
if x < y {
|
||||
return x
|
||||
} else {
|
||||
return y
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue