blackjack/blackjack.py

69 lines
1.6 KiB
Python
Raw Normal View History

2022-12-22 04:58:31 -05:00
from src.deck import Deck
from src.screen import Screen
from src.gamemaster import GameMaster
2022-12-20 23:51:27 -05:00
def main():
2022-12-22 04:58:31 -05:00
global kill
global screen
global num_decks
2022-12-22 18:30:42 -05:00
global deck
2022-12-22 04:58:31 -05:00
game = GameMaster()
2022-12-20 23:51:27 -05:00
for player in game.players:
for _ in range(2):
player.hand.append(deck.draw())
2022-12-22 04:58:31 -05:00
dealer = game.dealer
player = game.player
2022-12-20 23:51:27 -05:00
while game.active:
2022-12-22 18:30:42 -05:00
screen.update(game)
2022-12-22 22:32:15 -05:00
if player.blackjack(game):
2022-12-22 18:30:42 -05:00
game.active = False
print('Blackjack!')
2022-12-22 19:15:38 -05:00
break
2022-12-22 04:58:31 -05:00
2022-12-20 23:51:27 -05:00
if game.active:
user_input = input(str(deck.count()) + ' cards left in deck.\n[H]it or [S]tand? ')
2022-12-22 04:58:31 -05:00
2022-12-22 19:15:38 -05:00
match user_input.lower():
case 'y':
game.active = False
case 'q':
game.active = False
kill = True
case 'n':
2022-12-22 18:30:42 -05:00
game.active = False
2022-12-22 19:15:38 -05:00
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())
2022-12-20 23:51:27 -05:00
2022-12-22 19:15:38 -05:00
screen.update(game)
2022-12-22 04:58:31 -05:00
if not game.active:
2022-12-22 18:30:42 -05:00
game.score()
2022-12-22 19:15:38 -05:00
2022-12-22 04:58:31 -05:00
kill = False
screen = Screen()
2022-12-22 19:15:38 -05:00
2022-12-22 18:30:42 -05:00
print(screen.intro)
2022-12-22 19:15:38 -05:00
2022-12-22 04:58:31 -05:00
num_decks = input('How many decks? (1-8): ')
2022-12-22 22:32:15 -05:00
if num_decks == 'q':
kill = True
2022-12-22 18:30:42 -05:00
deck = Deck(num_decks)
2022-12-22 19:15:38 -05:00
2022-12-22 04:58:31 -05:00
while not kill:
main()
2022-12-22 19:15:38 -05:00
user_input = input('Play again? [Y/n] ')
match user_input.lower():
case 'n':
kill = True
2022-12-22 22:32:15 -05:00
case 'q':
kill = True