2022-08-19 10:15:31 +02:00
|
|
|
package Coin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"strings"
|
2022-08-19 10:52:53 +02:00
|
|
|
"time"
|
2022-08-19 10:15:31 +02:00
|
|
|
|
|
|
|
"gitlab.com/EternalWanderer/dice-roller/Colors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Toss(castAmount int) {
|
2022-08-19 10:52:53 +02:00
|
|
|
rand.Seed(time.Now().Unix())
|
2022-08-19 10:15:31 +02:00
|
|
|
var (
|
|
|
|
coins []string
|
|
|
|
coin string
|
|
|
|
coinState int
|
|
|
|
)
|
|
|
|
for i := 0; i < castAmount; i++ {
|
|
|
|
coinState = rand.Intn(2)
|
|
|
|
if coinState == 0 {
|
|
|
|
coin = Colors.ColorYellow + "heads" + Colors.ColorReset
|
|
|
|
} else {
|
|
|
|
coin = Colors.ColorBlue + "tails" + Colors.ColorReset
|
|
|
|
}
|
|
|
|
coins = append(coins, coin)
|
|
|
|
}
|
|
|
|
if castAmount > 1 {
|
|
|
|
fmt.Printf("%sTossing %d coins...%s\n", Colors.ColorYellow, castAmount, Colors.ColorReset)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("%sTossing coin...%s\n", Colors.ColorYellow, Colors.ColorReset)
|
|
|
|
}
|
|
|
|
fmt.Printf("\t%s\n", strings.Trim(fmt.Sprint(coins), "[]"))
|
|
|
|
}
|