예제 #1
0
파일: test.py 프로젝트: liujeff9/Blackjack
 def test_score_basic(self):
     hand = ["3 of Spades", "6 of Clubs", "9 of Hearts"]
     score = get_score(hand)
     self.assertEqual(score, 18)
예제 #2
0
파일: test.py 프로젝트: liujeff9/Blackjack
 def test_score_two_aces_jack(self):
     hand = ["A of Diamonds", "J of Hearts", "A of Spades"]
     score = get_score(hand)
     self.assertEqual(score, 12)
예제 #3
0
파일: test.py 프로젝트: liujeff9/Blackjack
 def test_score_bust(self):
     hand = ["K of Spades", "Q of Spades", "2 of Spades"]
     score = get_score(hand)
     self.assertEqual(score, 22)
예제 #4
0
파일: test.py 프로젝트: liujeff9/Blackjack
 def test_score_blackjack(self):
     hand = ["A of Diamonds", "K of Hearts"]
     score = get_score(hand)
     self.assertEqual(score, 21)
예제 #5
0
파일: test.py 프로젝트: liujeff9/Blackjack
 def test_score_three_aces(self):
     hand = ["A of Clubs", "A of Clubs", "A of Hearts"]
     score = get_score(hand)
     self.assertEqual(score, 13)
예제 #6
0
파일: test.py 프로젝트: liujeff9/Blackjack
 def test_score_basic_3(self):
     hand = ["2 of Spades", "5 of Clubs", "8 of Hearts"]
     score = get_score(hand)
     self.assertEqual(score, 15)
예제 #7
0
파일: test.py 프로젝트: liujeff9/Blackjack
 def test_score_basic_2(self):
     hand = ["4 of Spades", "7 of Clubs", "10 of Hearts"]
     score = get_score(hand)
     self.assertEqual(score, 21)
예제 #8
0
def main():
    display_title()
    money = float(input("Starting money: "))
    while money <= 0:
        print("You must start with more than 0!")
        print()
        money = float(input("Starting money: "))
    print()
    play_again = "y"
    while money > 0 and play_again == "y":
        bet_amount = float(input("Bet amount: "))
        while bet_amount <= 0:
            print("Bet amount must be more than 0!")
            print()
            bet_amount = float(input("Bet amount: "))
        while bet_amount > money:
            print("Sorry, you only have ", money)
            print()
            bet_amount = float(input("Bet amount: "))
        print()
        dealer_hand = []
        player_hand = []
        deck = cards.get_deck()
        random.shuffle(deck)
        dealer_hand.append(cards.get_card(deck))
        dealer_hand.append(cards.get_card(deck))
        player_hand.append(cards.get_card(deck))
        player_hand.append(cards.get_card(deck))
        print("Dealer Hand:")
        show_cards(dealer_hand, True)
        print()
        print("Player Hand:")
        show_cards(player_hand, False)
        print()
        hit_or_stand = input("Hit or stand? (hit/stand): ")
        print()
        while hit_or_stand == "hit":
            player_hand.append(cards.get_card(deck))
            print("Player hand:")
            show_cards(player_hand, False)
            print()
            if cards.get_score(player_hand) > 21:
                print("Sorry, your hand is over 21.")
                print()
                break
            hit_or_stand = input("Hit or stand? (hit/stand): ")
            print()
        while cards.get_score(dealer_hand) < 17:
            dealer_hand.append(cards.get_card(deck))
        print("Dealer's hand:")
        show_cards(dealer_hand, False)
        print()
        dealer_score = cards.get_score(dealer_hand)
        player_score = cards.get_score(player_hand)
        print("YOUR POINTS:      ", player_score)
        print("DEALER'S POINTS:  ", dealer_score)
        print()
        result = play_hand(dealer_score, player_score)
        if result.lower() == "blackjack":
            print("Wow! You got a blackjack!")
            money += bet_amount * 1.5
            money = round(money, 2)
        elif result.lower() == "win":
            print("Hooray! You win!")
            money += bet_amount
        elif result.lower() == "push":
            print("You pushed.")
        elif result.lower() == "lose":
            print("Sorry, you lost.")
            money -= bet_amount
        print("Money: ", money)
        print()
        if money > 0:
            play_again = input("Play again? (y/n): ")
            print()

    print("Bye!")