From fa1805043a7c15e8c14185f5f5c93cc3690e215b Mon Sep 17 00:00:00 2001 From: Adam <24621027+WhiteDopeOnPunk@users.noreply.github.com> Date: Tue, 27 Dec 2022 22:55:15 -0500 Subject: [PATCH] CLI should handle all printing --- blackjack.py | 19 ++++++------------- src/{screen.py => display.py} | 15 +++++++++++---- src/gamemaster.py | 9 ++++----- 3 files changed, 21 insertions(+), 22 deletions(-) rename src/{screen.py => display.py} (93%) diff --git a/blackjack.py b/blackjack.py index 44d08f3..5d47e69 100644 --- a/blackjack.py +++ b/blackjack.py @@ -1,10 +1,10 @@ from src.deck import Deck -from src.screen import Screen +from src.display import CLI from src.gamemaster import GameMaster def main(): global kill - global screen + global display global num_decks global deck game = GameMaster() @@ -17,11 +17,7 @@ def main(): player = game.player while game.active: - screen.update(game) - if player.blackjack(game): - game.active = False - print('Blackjack!') - break + display.update(game) if game.active: user_input = input(str(deck.count()) + ' cards left in deck.\n[H]it or [S]tand? ') @@ -43,14 +39,11 @@ def main(): while dealer.score(game) < 17: dealer.hand.append(deck.draw()) - screen.update(game) - if not game.active: - game.score() + display.update(game) kill = False -screen = Screen() - -print(screen.intro) +display = CLI() +display.intro() num_decks = input('How many decks? (1-8): ') if num_decks == 'q': diff --git a/src/screen.py b/src/display.py similarity index 93% rename from src/screen.py rename to src/display.py index f254e3a..075ffc3 100644 --- a/src/screen.py +++ b/src/display.py @@ -1,4 +1,4 @@ -class Screen: +class CLI: def __init__(self): self.title = '''\ @@ -12,8 +12,6 @@ o8YooP' 8 .oPYo. .oPYo. 8 .o 8 .oPYo. .oPYo. 8 .o :::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::''' - self.clear = '\033c' - self.intro = self.clear + self.title self.deck = '''\ ┌────────┐┐┐┐┐┐ │░░░░░░░░││││││ @@ -95,10 +93,19 @@ o8YooP' 8 .oPYo. .oPYo. 8 .o 8 .oPYo. .oPYo. 8 .o carriage += chunk print(carriage) + def clear(self): + print('\033c') + + def intro(self): + self.clear() + print(self.title) + def update(self, game): - print(self.clear) + self.clear() print(self.title) for player in game.players: print(' '+player.name,'''\ Score:''', player.score(game)) self.print_hand(player, game) + if not game.active: + print(game.score()) diff --git a/src/gamemaster.py b/src/gamemaster.py index ece2d9f..f51b9c3 100644 --- a/src/gamemaster.py +++ b/src/gamemaster.py @@ -24,9 +24,8 @@ class GameMaster: if player.score(self) > 21: self.active = False status = player.name + ' Bust!' + elif player.blackjack(self): + self.active = False + status = player.name + ' has Blackjack!' - if self.dealer.blackjack(self): - self.active = False - status = 'Dealer Blackjack!' - - print(status) + return status