Rewrite of advantage and disadvantage

This commit is contained in:
Nox Sluijtman 2022-08-19 15:19:53 +02:00
parent bed2f3df01
commit 2d560c42a0
2 changed files with 25 additions and 18 deletions

View file

@ -45,32 +45,25 @@ func Cast(surfaces, diceThrows, modifier int) {
} }
} }
func SimpleCast(modifier int) int { func SimpleCast() int {
var cast = rand.Intn(20) + 1 var cast = rand.Intn(20) + 1
if modifier != 0 { return cast
fmt.Println("Without modifier:", cast)
}
return cast + modifier
} }
func Advantage(x, y int) int { func Advantage(x, y int) (int, int, int) {
fmt.Println("\tx:", x)
fmt.Println("\tY:", y)
if x > y { if x > y {
return x return x, x, y
} else { } else {
return y return y, x, y
} }
} }
func Disadvantage(x, y int) int { func Disadvantage(x, y int) (int, int, int) {
fmt.Println("\tx:", x)
fmt.Println("\tY:", y)
if x < y { if x < y {
return x return x, x, y
} else { } else {
return y return y, x, y
} }
} }

20
main.go
View file

@ -41,20 +41,34 @@ func main() {
Coin.Toss(diceThrows) Coin.Toss(diceThrows)
case advantage: 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("%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 { } else {
fmt.Printf("%sRolling 1d20 with advantage...%s\n", Colors.ColorGreen, Colors.ColorReset) 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: case disadvantage:
x := Dice.SimpleCast()
y := Dice.SimpleCast()
result, x_block, y_block := Dice.Disadvantage(x, y)
if modifier != 0 { if modifier != 0 {
fmt.Printf("%sRolling 1d20 + %d with disadvantage...%s\n", Colors.ColorRed, modifier, Colors.ColorReset) 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 { } else {
fmt.Printf("%sRolling 1d20 with disadvantage...%s\n", Colors.ColorRed, Colors.ColorReset) 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: case attacks > 1:
for i := 0; i < attacks; i++ { for i := 0; i < attacks; i++ {