From 8076cb6b15c22f29df46a85fd1ba698d9670a35d Mon Sep 17 00:00:00 2001 From: Adam <24621027+WhiteDopeOnPunk@users.noreply.github.com> Date: Tue, 27 Dec 2022 23:47:12 -0500 Subject: [PATCH] ui handle all ui --- blackjack.py | 23 +++++++++-------------- src/{display.py => io.py} | 12 ++++++++++++ 2 files changed, 21 insertions(+), 14 deletions(-) rename src/{display.py => io.py} (91%) diff --git a/blackjack.py b/blackjack.py index 5d47e69..be0e156 100644 --- a/blackjack.py +++ b/blackjack.py @@ -1,10 +1,10 @@ from src.deck import Deck -from src.display import CLI +from src.io import CLI from src.gamemaster import GameMaster def main(): global kill - global display + global ui global num_decks global deck game = GameMaster() @@ -17,7 +17,7 @@ def main(): player = game.player while game.active: - display.update(game) + ui.update(game) if game.active: user_input = input(str(deck.count()) + ' cards left in deck.\n[H]it or [S]tand? ') @@ -38,14 +38,13 @@ def main(): game.active = False while dealer.score(game) < 17: dealer.hand.append(deck.draw()) - - display.update(game) + ui.update(game) kill = False -display = CLI() -display.intro() +ui = CLI() +ui.intro() -num_decks = input('How many decks? (1-8): ') +num_decks = ui.get_decks() if num_decks == 'q': kill = True @@ -53,9 +52,5 @@ deck = Deck(num_decks) while not kill: main() - user_input = input('Play again? [Y/n] ') - match user_input.lower(): - case 'n': - kill = True - case 'q': - kill = True + if not ui.play_again(): + kill = True diff --git a/src/display.py b/src/io.py similarity index 91% rename from src/display.py rename to src/io.py index 075ffc3..11f6ff9 100644 --- a/src/display.py +++ b/src/io.py @@ -109,3 +109,15 @@ o8YooP' 8 .oPYo. .oPYo. 8 .o 8 .oPYo. .oPYo. 8 .o self.print_hand(player, game) if not game.active: print(game.score()) + + def get_decks(self): + return input('How many decks? (1-8): ') + + def play_again(self): + match input('Play again? [Y/n] ').lower(): + case 'n': + return False + case 'q': + return False + case _: + return True