stuff
This commit is contained in:
parent
240b0339bf
commit
17580f6fd4
1 changed files with 21 additions and 20 deletions
43
blackjack.py
43
blackjack.py
|
@ -22,7 +22,7 @@ def make_card(vs, style):
|
||||||
|
|
||||||
suit = vs[1] + ' '
|
suit = vs[1] + ' '
|
||||||
|
|
||||||
# request text render of glyph but can break some fonts
|
# request text render of preceeding glyph but can break some fonts
|
||||||
# suit += '\uFE0E'
|
# suit += '\uFE0E'
|
||||||
|
|
||||||
deck = '''\
|
deck = '''\
|
||||||
|
@ -68,13 +68,13 @@ def make_card(vs, style):
|
||||||
|
|
||||||
if style == 'deck':
|
if style == 'deck':
|
||||||
return deck
|
return deck
|
||||||
if style == 'card_rest':
|
elif style == 'card_rest':
|
||||||
return card_rest
|
return card_rest
|
||||||
if style == 'hidden_part':
|
elif style == 'hidden_part':
|
||||||
return hidden_part
|
return hidden_part
|
||||||
if style == 'hidden_rest':
|
elif style == 'hidden_rest':
|
||||||
return hidden_rest
|
return hidden_rest
|
||||||
if style == 'card_part':
|
elif style == 'card_part':
|
||||||
return card_part
|
return card_part
|
||||||
|
|
||||||
def generate_deck(n_decks):
|
def generate_deck(n_decks):
|
||||||
|
@ -134,7 +134,6 @@ def score_hand(player):
|
||||||
def player_score(player):
|
def player_score(player):
|
||||||
card_scores = score_hand(player)
|
card_scores = score_hand(player)
|
||||||
|
|
||||||
|
|
||||||
if sum(card_scores) < 11:
|
if sum(card_scores) < 11:
|
||||||
if 1 in card_scores:
|
if 1 in card_scores:
|
||||||
index = card_scores.index(1)
|
index = card_scores.index(1)
|
||||||
|
@ -154,7 +153,6 @@ def main():
|
||||||
|
|
||||||
gameover = 'Error'
|
gameover = 'Error'
|
||||||
|
|
||||||
# 1-8 decks
|
|
||||||
if len(play_deck) < 4:
|
if len(play_deck) < 4:
|
||||||
play_deck = generate_deck(num_decks)
|
play_deck = generate_deck(num_decks)
|
||||||
|
|
||||||
|
@ -171,33 +169,35 @@ def main():
|
||||||
|
|
||||||
if user_input.lower() == 'q':
|
if user_input.lower() == 'q':
|
||||||
gameover = 'q'
|
gameover = 'q'
|
||||||
kill = True
|
|
||||||
game_active = False
|
|
||||||
break
|
|
||||||
|
|
||||||
if user_input.lower() == 'r':
|
|
||||||
game_active = False
|
game_active = False
|
||||||
|
|
||||||
if user_input.lower() == 'h':
|
elif user_input.lower() == 'r':
|
||||||
|
game_active = False
|
||||||
|
|
||||||
|
elif user_input.lower() == 'h':
|
||||||
draw_card('Player')
|
draw_card('Player')
|
||||||
|
|
||||||
if user_input.lower() == 's':
|
elif user_input.lower() == 's':
|
||||||
game_active = False
|
game_active = False
|
||||||
|
|
||||||
|
if player_score('Dealer') == 21:
|
||||||
|
gameover = 'Dealer has blackjack!'
|
||||||
|
break
|
||||||
|
|
||||||
while player_score('Dealer') < 17:
|
while player_score('Dealer') < 17:
|
||||||
draw_card('Dealer')
|
draw_card('Dealer')
|
||||||
|
|
||||||
if player_score('Dealer') > 21:
|
if player_score('Dealer') > 21:
|
||||||
gameover = 'Dealer Bust!'
|
gameover = 'Dealer Bust!'
|
||||||
break
|
|
||||||
if player_score('Dealer') == player_score('Player'):
|
elif player_score('Dealer') == player_score('Player'):
|
||||||
gameover = 'Push.'
|
gameover = 'Push.'
|
||||||
break
|
|
||||||
if player_score('Dealer') > player_score('Player'):
|
elif player_score('Dealer') > player_score('Player'):
|
||||||
gameover = 'House wins.'
|
gameover = 'House wins.'
|
||||||
break
|
|
||||||
if player_score('Dealer') < player_score('Player'):
|
elif player_score('Dealer') < player_score('Player'):
|
||||||
gameover = 'You win!'
|
gameover = 'You win!'
|
||||||
break
|
|
||||||
|
|
||||||
if player_score('Player') > 21:
|
if player_score('Player') > 21:
|
||||||
gameover = 'Bust!'
|
gameover = 'Bust!'
|
||||||
|
@ -211,6 +211,7 @@ num_decks = input('How many decks? (1-8): ')
|
||||||
while kill == False:
|
while kill == False:
|
||||||
main()
|
main()
|
||||||
if gameover == 'q':
|
if gameover == 'q':
|
||||||
|
kill = True
|
||||||
break
|
break
|
||||||
show_board()
|
show_board()
|
||||||
user_input = input(gameover + '\nPlay again? [Y/n] ')
|
user_input = input(gameover + '\nPlay again? [Y/n] ')
|
||||||
|
|
Loading…
Add table
Reference in a new issue