mirror of
https://gitlab.com/EternalWanderer/dice-roller.git
synced 2024-11-29 05:13:50 +01:00
Added advantage and disatvantage options
This commit is contained in:
parent
b45c2ab92b
commit
986f3cc01e
65
main.go
65
main.go
|
@ -4,25 +4,50 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
surfaces, modifier, diceThrows, attacks int
|
||||||
|
advantage, disadvantage bool
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var surfaces, modifier, diceThrows, attacks int
|
|
||||||
|
|
||||||
rand.Seed(time.Now().Unix())
|
rand.Seed(time.Now().Unix())
|
||||||
flag.IntVar(&surfaces, "s", 20, "Specify amount of die surfaces")
|
ParseFlags()
|
||||||
flag.IntVar(&diceThrows, "t", 1, "Specify dice diceThrows")
|
|
||||||
flag.IntVar(&modifier, "m", 0, "Stat modifier")
|
|
||||||
flag.IntVar(&attacks, "a", 1, "Attacks")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case advantage:
|
||||||
|
fmt.Println("Advantage")
|
||||||
|
fmt.Println(Advantage(SimpleCast(), SimpleCast()))
|
||||||
|
case disadvantage:
|
||||||
|
fmt.Println("Disadvantage")
|
||||||
|
fmt.Println(Disadvantage(SimpleCast(), SimpleCast()))
|
||||||
|
case attacks < 1:
|
||||||
|
fmt.Println("Attack amount cannot be below 1.")
|
||||||
|
os.Exit(1)
|
||||||
|
case attacks > 1:
|
||||||
for i := 0; i < attacks; i++ {
|
for i := 0; i < attacks; i++ {
|
||||||
if attacks > 1 {
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
|
||||||
Cast(surfaces, diceThrows, modifier)
|
Cast(surfaces, diceThrows, modifier)
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
Cast(surfaces, diceThrows, modifier)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.BoolVar(&advantage, "advantage", false, "Advantage")
|
||||||
|
flag.BoolVar(&disadvantage, "disadvantage", false, "Disadvantage")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Cast(dieSurfaces, castAmount, modifier int) {
|
func Cast(dieSurfaces, castAmount, modifier int) {
|
||||||
|
@ -48,3 +73,27 @@ func Cast(dieSurfaces, castAmount, modifier int) {
|
||||||
fmt.Println(total)
|
fmt.Println(total)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SimpleCast() int {
|
||||||
|
return rand.Intn(20) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func Advantage(x, y int) int {
|
||||||
|
fmt.Println("x:", x)
|
||||||
|
fmt.Println("Y:", y)
|
||||||
|
if x > y {
|
||||||
|
return x
|
||||||
|
} else {
|
||||||
|
return y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Disadvantage(x, y int) int {
|
||||||
|
fmt.Println("x:", x)
|
||||||
|
fmt.Println("Y:", y)
|
||||||
|
if x < y {
|
||||||
|
return x
|
||||||
|
} else {
|
||||||
|
return y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue