-
Notifications
You must be signed in to change notification settings - Fork 0
/
phase.go
60 lines (55 loc) · 1.04 KB
/
phase.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
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func askHit() bool {
fmt.Println("hit? y/n")
input := bufio.NewScanner(os.Stdin)
input.Scan()
fmt.Println("----------------------------")
ans := input.Text()
if ans == "y" {
return true
}
fmt.Println("call")
return false
}
func setup(p, dl *player, dc deck) {
dl.hit(dc)
p.hit(dc)
p.renderHand()
dl.renderHand()
}
func hitOrCall(p, dl *player, dc deck, hit bool) string {
if hit {
p.hit(dc)
if p.score() > 21 {
fmt.Printf("%v\n", p.score())
} else {
dl.renderHand()
p.renderHand()
hitOrCall(p, dl, dc, askHit())
}
}
return strconv.Itoa(p.score())
}
func result(p, dl *player, dc deck) {
for dls := 0; dls < 17; {
dl.hit(dc)
dls = dl.score()
}
p.renderHand()
dl.renderHand()
fmt.Print("RESULT: ")
bj := 21
if (p.score() > bj && dl.score() > bj) || (p.score() > bj && dl.score() <= bj) || (p.score() < dl.score()) {
fmt.Println("YOU LOSE")
} else if p.score() <= bj && p.score() == dl.score() {
fmt.Println("DRAW")
} else {
fmt.Println("YOU WIN!")
}
}