blacker jacks
This commit is contained in:
parent
d015932f42
commit
a37278e937
2 changed files with 28 additions and 20 deletions
47
blackjack.py
47
blackjack.py
|
@ -16,45 +16,52 @@ def main():
|
||||||
dealer = game.dealer
|
dealer = game.dealer
|
||||||
player = game.player
|
player = game.player
|
||||||
|
|
||||||
|
|
||||||
while game.active:
|
while game.active:
|
||||||
screen.update(game)
|
screen.update(game)
|
||||||
if player.blackjack():
|
if player.blackjack():
|
||||||
game.active = False
|
game.active = False
|
||||||
print('Blackjack!')
|
print('Blackjack!')
|
||||||
|
break
|
||||||
|
|
||||||
if game.active:
|
if game.active:
|
||||||
user_input = input(str(deck.count()) + ' cards left in deck.\n[H]it or [S]tand? ')
|
user_input = input(str(deck.count()) + ' cards left in deck.\n[H]it or [S]tand? ')
|
||||||
|
|
||||||
if not user_input:
|
match user_input.lower():
|
||||||
user_input = 's'
|
case 'y':
|
||||||
|
|
||||||
match user_input.lower():
|
|
||||||
case 'y':
|
|
||||||
game.active = False
|
|
||||||
case 'q':
|
|
||||||
game.active = False
|
|
||||||
kill = True
|
|
||||||
case 'n':
|
|
||||||
game.active = False
|
|
||||||
case 'h':
|
|
||||||
player.hand.append(deck.draw())
|
|
||||||
if player.bust(game):
|
|
||||||
game.active = False
|
game.active = False
|
||||||
case 's':
|
case 'q':
|
||||||
game.active = False
|
game.active = False
|
||||||
while dealer.score(game) < 17:
|
kill = True
|
||||||
dealer.hand.append(deck.draw())
|
case 'n':
|
||||||
|
game.active = False
|
||||||
|
case 'h':
|
||||||
|
player.hand.append(deck.draw())
|
||||||
|
if player.bust(game):
|
||||||
|
game.active = False
|
||||||
|
case 's':
|
||||||
|
game.active = False
|
||||||
|
while dealer.score(game) < 17:
|
||||||
|
dealer.hand.append(deck.draw())
|
||||||
|
|
||||||
|
|
||||||
screen.update(game)
|
screen.update(game)
|
||||||
|
|
||||||
if not game.active:
|
if not game.active:
|
||||||
game.score()
|
game.score()
|
||||||
user_input = input('Play again? [Y/n] ')
|
|
||||||
|
|
||||||
kill = False
|
kill = False
|
||||||
screen = Screen()
|
screen = Screen()
|
||||||
|
|
||||||
print(screen.intro)
|
print(screen.intro)
|
||||||
|
|
||||||
num_decks = input('How many decks? (1-8): ')
|
num_decks = input('How many decks? (1-8): ')
|
||||||
deck = Deck(num_decks)
|
deck = Deck(num_decks)
|
||||||
|
|
||||||
while not kill:
|
while not kill:
|
||||||
main()
|
main()
|
||||||
|
user_input = input('Play again? [Y/n] ')
|
||||||
|
match user_input.lower():
|
||||||
|
case 'n':
|
||||||
|
kill = True
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ class Deck:
|
||||||
return len(self.cards)
|
return len(self.cards)
|
||||||
|
|
||||||
def shuffle(self, n_decks):
|
def shuffle(self, n_decks):
|
||||||
|
self.cards = []
|
||||||
n_decks = 1 if not n_decks or n_decks not in '12345678' else n_decks
|
n_decks = 1 if not n_decks or n_decks not in '12345678' else n_decks
|
||||||
n_decks = int(n_decks)
|
n_decks = int(n_decks)
|
||||||
n_decks = 8 if n_decks > 8 else n_decks
|
n_decks = 8 if n_decks > 8 else n_decks
|
||||||
|
|
Loading…
Add table
Reference in a new issue