forked from starlightromero/go-cards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (51 loc) · 1.08 KB
/
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
package main
import (
"fmt"
"strings"
)
func main() {
cards := newDeck()
blackjack := 21
n := 1
for n < 10 {
cards.shuffle()
n++
}
hand := cards.dealTwo()
hand.print()
handValue := hand.value()
fmt.Println("You're at ", handValue)
fmt.Println("Hit or Stay?")
var input string
fmt.Scanln(&input)
for strings.ToLower(input) == "hit" {
newCard := cards.dealOne()
hand = append(hand, newCard...)
hand.print()
handValue := hand.value()
fmt.Println("You're at ", handValue)
if handValue > 21 {
fmt.Printf("You went over %v. You lose!", blackjack)
break
} else if handValue == blackjack {
fmt.Printf("You got %v. You win!", blackjack)
break
}
fmt.Println("Hit or Stay?")
fmt.Scanln(&input)
}
handValue = hand.value()
if handValue < blackjack {
fmt.Println("You got", handValue)
aiHand := play(cards)
aiHandValue := aiHand.value()
fmt.Println("The AI got", aiHandValue)
if aiHandValue > handValue {
fmt.Println("You loose!")
} else if aiHandValue < handValue {
fmt.Println("You win!")
} else {
fmt.Println("No one won...")
}
}
}