Skip to content

Commit

Permalink
added blackjack function to dealersim to call out player has blackjack
Browse files Browse the repository at this point in the history
  • Loading branch information
jlat07 committed Apr 21, 2020
1 parent 57a6ee2 commit 6e6ebd4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from utils import *

playing = True

def main():
'''
Starts Game
Expand Down Expand Up @@ -30,4 +30,4 @@ def main():


if __name__ == '__main__':
main()
main()
18 changes: 15 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,31 @@
'''
playing = True


def blackjack(name: Hand):
'''
Lets user know who has Black Jack
'''
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:
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -123,20 +132,23 @@ 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
'''
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
'''
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 = []
Expand Down Expand Up @@ -187,4 +199,4 @@ def end_game():
time.sleep(.1)
print(" / \ ")
time.sleep(.1)
quit()
quit()

0 comments on commit 6e6ebd4

Please sign in to comment.