mirror of
https://gitlab.com/EternalWanderer/dice-roller.git
synced 2025-06-08 06:14:25 +02:00
Proper refactor
This commit is contained in:
parent
6fb022aa7d
commit
b4e0356ef5
4 changed files with 135 additions and 110 deletions
32
Coin/Coin.go
Normal file
32
Coin/Coin.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package Coin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
|
||||
"gitlab.com/EternalWanderer/dice-roller/Colors"
|
||||
)
|
||||
|
||||
func Toss(castAmount int) {
|
||||
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), "[]"))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue