blackjack/blackjack.py

57 lines
1.3 KiB
Python
Raw Normal View History

2022-12-22 04:58:31 -05:00
from src.deck import Deck
2022-12-27 23:47:12 -05:00
from src.io import CLI
2022-12-22 04:58:31 -05:00
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
2022-12-27 23:47:12 -05:00
global ui
2022-12-22 04:58:31 -05:00
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-27 23:47:12 -05:00
ui.update(game)
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-27 23:47:12 -05:00
ui.update(game)
2022-12-22 19:15:38 -05:00
2022-12-22 04:58:31 -05:00
kill = False
2022-12-27 23:47:12 -05:00
ui = CLI()
ui.intro()
2022-12-22 19:15:38 -05:00
2022-12-27 23:47:12 -05:00
num_decks = ui.get_decks()
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-27 23:47:12 -05:00
if not ui.play_again():
kill = True