mirror of
https://gitlab.com/EternalWanderer/dice-roller.git
synced 2024-11-28 21:03:51 +01:00
Rewrite of advantage and disadvantage
This commit is contained in:
parent
bed2f3df01
commit
2d560c42a0
23
Dice/Dice.go
23
Dice/Dice.go
|
@ -45,32 +45,25 @@ func Cast(surfaces, diceThrows, modifier int) {
|
|||
}
|
||||
}
|
||||
|
||||
func SimpleCast(modifier int) int {
|
||||
func SimpleCast() int {
|
||||
|
||||
var cast = rand.Intn(20) + 1
|
||||
|
||||
if modifier != 0 {
|
||||
fmt.Println("Without modifier:", cast)
|
||||
}
|
||||
return cast + modifier
|
||||
return cast
|
||||
}
|
||||
|
||||
func Advantage(x, y int) int {
|
||||
fmt.Println("\tx:", x)
|
||||
fmt.Println("\tY:", y)
|
||||
func Advantage(x, y int) (int, int, int) {
|
||||
if x > y {
|
||||
return x
|
||||
return x, x, y
|
||||
} else {
|
||||
return y
|
||||
return y, x, y
|
||||
}
|
||||
}
|
||||
|
||||
func Disadvantage(x, y int) int {
|
||||
fmt.Println("\tx:", x)
|
||||
fmt.Println("\tY:", y)
|
||||
func Disadvantage(x, y int) (int, int, int) {
|
||||
if x < y {
|
||||
return x
|
||||
return x, x, y
|
||||
} else {
|
||||
return y
|
||||
return y, x, y
|
||||
}
|
||||
}
|
||||
|
|
20
main.go
20
main.go
|
@ -41,20 +41,34 @@ func main() {
|
|||
Coin.Toss(diceThrows)
|
||||
|
||||
case advantage:
|
||||
if modifier > 0 {
|
||||
x := Dice.SimpleCast()
|
||||
y := Dice.SimpleCast()
|
||||
result, x_block, y_block := Dice.Advantage(x, y)
|
||||
if modifier != 0 {
|
||||
fmt.Printf("%sRolling 1d20 + %d with advantage...%s\n", Colors.ColorGreen, modifier, Colors.ColorReset)
|
||||
fmt.Printf("\t%s%s%s\n", Colors.ColorYellow, "Without modifier...", Colors.ColorReset)
|
||||
fmt.Printf("\t%s%d%s\t%s %d\t%s %d\n", Colors.ColorGreen, result, Colors.ColorReset, "x:", x_block, "y:", y_block)
|
||||
fmt.Printf("\t%s%s%s\n", Colors.ColorYellow, "With modifier...", Colors.ColorReset)
|
||||
fmt.Printf("\t%s%d%s\t%s %d\t%s %d\n", Colors.ColorGreen, result+modifier, Colors.ColorReset, "x:", x_block+modifier, "y:", y_block+modifier)
|
||||
} else {
|
||||
fmt.Printf("%sRolling 1d20 with advantage...%s\n", Colors.ColorGreen, Colors.ColorReset)
|
||||
fmt.Printf("\t%s%d%s\t%s %d\t%s %d\n", Colors.ColorGreen, result, Colors.ColorReset, "x:", x_block, "y:", y_block)
|
||||
}
|
||||
fmt.Printf("\t%s%d%s\n", Colors.ColorGreen, Dice.Advantage(Dice.SimpleCast(modifier), Dice.SimpleCast(modifier)), Colors.ColorReset)
|
||||
|
||||
case disadvantage:
|
||||
x := Dice.SimpleCast()
|
||||
y := Dice.SimpleCast()
|
||||
result, x_block, y_block := Dice.Disadvantage(x, y)
|
||||
if modifier != 0 {
|
||||
fmt.Printf("%sRolling 1d20 + %d with disadvantage...%s\n", Colors.ColorRed, modifier, Colors.ColorReset)
|
||||
fmt.Printf("\t%s%s%s\n", Colors.ColorYellow, "Without modifier...", Colors.ColorReset)
|
||||
fmt.Printf("\t%s%d%s\t%s %d\t%s %d\n", Colors.ColorRed, result, Colors.ColorReset, "x:", x_block, "y:", y_block)
|
||||
fmt.Printf("\t%s%s%s\n", Colors.ColorYellow, "With modifier...", Colors.ColorReset)
|
||||
fmt.Printf("\t%s%d%s\t%s %d\t%s %d\n", Colors.ColorRed, result+modifier, Colors.ColorReset, "x:", x_block+modifier, "y:", y_block+modifier)
|
||||
} else {
|
||||
fmt.Printf("%sRolling 1d20 with disadvantage...%s\n", Colors.ColorRed, Colors.ColorReset)
|
||||
fmt.Printf("\t%s%d%s\t%s %d\t%s %d\n", Colors.ColorRed, result, Colors.ColorReset, "x:", x_block, "y:", y_block)
|
||||
}
|
||||
fmt.Printf("\t%s%d%s\n", Colors.ColorRed, Dice.Disadvantage(Dice.SimpleCast(modifier), Dice.SimpleCast(modifier)), Colors.ColorReset)
|
||||
|
||||
case attacks > 1:
|
||||
for i := 0; i < attacks; i++ {
|
||||
|
|
Loading…
Reference in a new issue