From 6e6ebd47061d97650eb23ab7edf91f735aecd377 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Tue, 21 Apr 2020 09:08:38 -0400 Subject: [PATCH] added blackjack function to dealersim to call out player has blackjack --- main.py | 4 ++-- utils.py | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 8b3e99e..fb0249e 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ from utils import * -playing = True + def main(): ''' Starts Game @@ -30,4 +30,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/utils.py b/utils.py index ef0a036..bf38015 100644 --- a/utils.py +++ b/utils.py @@ -8,6 +8,8 @@ ''' playing = True + + def blackjack(name: Hand): ''' Lets user know who has Black Jack @@ -15,20 +17,22 @@ def blackjack(name: Hand): print(f'{name.name} has black Jack') print(f'{name.name} Wins') + def bust(name: Hand): ''' Lets user know who hast bust ''' time.sleep(1) print(f"BUST! {name.name} loses") - + + def dealer_sim(deck: Deck, player: Hand, dealer: Hand): ''' After player has made all choices, this function determines if player has blackjack or bust Or runs through the dealers scenerios and deciedes when to hit or Stand. Then returns outcome. ''' if player.count == 21: - return + return blackjack(player) if player.count > 21: return bust(player) else: @@ -64,6 +68,7 @@ def dealer_sim(deck: Deck, player: Hand, dealer: Hand): elif dealer.count == player.count: push(dealer) + def first_hand(player: Hand, dealer: Hand): ''' Shows the first hand with one dealer card not turned over. Evaluates if player has 21 @@ -77,6 +82,7 @@ def first_hand(player: Hand, dealer: Hand): if player.count == 21: blackjack(player) + def hit(deck: Deck, name: Hand): ''' Function draws a card from the deck and addes it to the hand. @@ -85,6 +91,7 @@ def hit(deck: Deck, name: Hand): hit = deck.deal() name.draw_card(hit) + def play_again(): ''' Starts the game over, or lets user end game. @@ -98,6 +105,7 @@ def play_again(): print('Invalid input') play_again() + def play_hand(deck: Deck, name: Hand): ''' This is where the player deciedes to hit or stay @@ -115,6 +123,7 @@ def play_hand(deck: Deck, name: Hand): else: print('Invalid input') + def winner(name): ''' Lets the platey know that the player has won @@ -123,6 +132,7 @@ def winner(name): time.sleep(1) print(f'{name.name} Wins') + def push(name): ''' Calls the out come of the game, when dealer and player have the same count, push is invoked @@ -130,6 +140,7 @@ def push(name): show_hand(name) print('Push, No Winner!') + def show_hand(name: Hand): ''' Function shows the hand specific to the instance of the paramater its given @@ -137,6 +148,7 @@ def show_hand(name: Hand): H = [card for card in name.cards] print(f"{name.name}'s hand:{H}{name.count}") + def reset_deck(player: Hand, dealer: Hand): player.cards = [] dealer.cards = [] @@ -187,4 +199,4 @@ def end_game(): time.sleep(.1) print(" / \ ") time.sleep(.1) - quit() \ No newline at end of file + quit()