blackjack/blackjack.py

55 lines
1.2 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:
2022-12-28 02:11:08 -05:00
match ui.player_move(deck).lower():
2022-12-22 19:15:38 -05:00
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()
2022-12-28 23:37:53 -05:00
print(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