Exemple #1
0
func promptPlayer(d deck.Deck, p *hand.Hand) bool {
	fmt.Print(promptOptions(p))

	// read from the player
	switch getUserInput() {
	case "h":
		c, _ := d.NextCard()
		p.AddCard(c)
		return false
	default: // case "s":
		return true
	}

}
Exemple #2
0
func declareWinner(player, dealer *hand.Hand) {
	fmt.Println("Dealer:", dealer)
	fmt.Println("Player:", player)
	fmt.Println() //formatting

	cmp := player.Compare(dealer)

	switch {
	case player.Busted() && dealer.Busted(): // house rules
		fmt.Println("Dealer wins!")
	case player.Busted():
		fmt.Println("Dealer wins!")
	case dealer.Busted():
		fmt.Println("Player wins!")
	case cmp == 0:
		fmt.Println("Tie!")
	case cmp == 1:
		fmt.Println("Player wins!")
	case cmp == -1:
		fmt.Println("Dealer wins!")
	}
}
Exemple #3
0
func showHands(player, dealer *hand.Hand) {
	fmt.Println("Dealer:", dealer.ShowOneCard())
	fmt.Println("Player:", player)
	fmt.Println() //formatting
}
Exemple #4
0
func dealerPlays(d deck.Deck, h *hand.Hand) {
	for !h.Busted() && h.Value() < 17 { // dealer must hit when <17
		c, _ := d.NextCard()
		h.AddCard(c)
	}
}