mirror of
https://gitlab.com/EternalWanderer/dice-roller.git
synced 2025-06-08 06:14:25 +02:00
Got rid of bad color implementation
This commit is contained in:
parent
4d0ab352aa
commit
3afa5fb7db
7 changed files with 78 additions and 53 deletions
28
Coin/Coin.go
28
Coin/Coin.go
|
@ -3,30 +3,44 @@ package Coin
|
|||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitlab.com/EternalWanderer/dice-roller/Colors"
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
var initRandom bool
|
||||
|
||||
func InitRandom(initialised bool) {
|
||||
if initialised {
|
||||
return
|
||||
}
|
||||
rand.Seed(time.Now().Unix())
|
||||
initRandom = true
|
||||
}
|
||||
|
||||
func Toss(castAmount int) {
|
||||
InitRandom(initRandom)
|
||||
yellow := color.New(color.FgYellow).SprintFunc()
|
||||
blue := color.New(color.FgBlue).SprintFunc()
|
||||
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
|
||||
coin = yellow("heads")
|
||||
} else {
|
||||
coin = Colors.ColorBlue + "tails" + Colors.ColorReset
|
||||
coin = blue("tails")
|
||||
}
|
||||
coins = append(coins, coin)
|
||||
}
|
||||
if castAmount > 1 {
|
||||
fmt.Printf("%sTossing %d coins...%s\n", Colors.ColorYellow, castAmount, Colors.ColorReset)
|
||||
color.Yellow("Tossing %d coins...\n", castAmount)
|
||||
} else {
|
||||
fmt.Printf("%sTossing coin...%s\n", Colors.ColorYellow, Colors.ColorReset)
|
||||
color.Yellow("Tossing coin...\n", castAmount)
|
||||
}
|
||||
fmt.Printf("\t%s\n", strings.Trim(fmt.Sprint(coins), "[]"))
|
||||
fmt.Println(fmt.Sprint(coins))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue