-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (60 loc) · 946 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"math/rand"
"os"
"strconv"
"strings"
"time"
)
func init() {
// populate initial board
for i := 0; i < MAX; i++ {
board[i] = Flap{i + 1, true}
}
}
func main() {
// infinite loop until 'q' or '0' is entered
for {
displayBoard()
roll()
flipdown(choice())
}
}
func displayBoard() {
for _, flap := range board {
fmt.Print(flap)
}
fmt.Println()
}
func flipdown(num string) {
for i := 0; i < MAX; i++ {
s := strconv.Itoa(i + 1)
if strings.Contains(num, s) {
board[i].IsUp = false
}
}
}
func roll() {
rand.Seed(time.Now().UnixNano())
d1 := rand.Intn(6) + 1
d2 := rand.Intn(6) + 1
fmt.Println(d1, d2)
}
func choice() (num string) {
fmt.Printf("? ")
fmt.Scanln(&num)
if "q" == num || "0" == num {
fmt.Println("Score:", getScore())
os.Exit(0)
}
return
}
func getScore() (score int) {
for _, flap := range board {
if flap.IsUp {
score += flap.Number
}
}
return
}