CLI should handle all printing

This commit is contained in:
Adam 2022-12-27 22:55:15 -05:00
parent d4e055f2e4
commit fa1805043a
3 changed files with 21 additions and 22 deletions

View file

@ -1,10 +1,10 @@
from src.deck import Deck from src.deck import Deck
from src.screen import Screen from src.display import CLI
from src.gamemaster import GameMaster from src.gamemaster import GameMaster
def main(): def main():
global kill global kill
global screen global display
global num_decks global num_decks
global deck global deck
game = GameMaster() game = GameMaster()
@ -17,11 +17,7 @@ def main():
player = game.player player = game.player
while game.active: while game.active:
screen.update(game) display.update(game)
if player.blackjack(game):
game.active = False
print('Blackjack!')
break
if game.active: if game.active:
user_input = input(str(deck.count()) + ' cards left in deck.\n[H]it or [S]tand? ') 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: while dealer.score(game) < 17:
dealer.hand.append(deck.draw()) dealer.hand.append(deck.draw())
screen.update(game) display.update(game)
if not game.active:
game.score()
kill = False kill = False
screen = Screen() display = CLI()
display.intro()
print(screen.intro)
num_decks = input('How many decks? (1-8): ') num_decks = input('How many decks? (1-8): ')
if num_decks == 'q': if num_decks == 'q':

View file

@ -1,4 +1,4 @@
class Screen: class CLI:
def __init__(self): def __init__(self):
self.title = '''\ 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 = '''\ self.deck = '''\
@ -95,10 +93,19 @@ o8YooP' 8 .oPYo. .oPYo. 8 .o 8 .oPYo. .oPYo. 8 .o
carriage += chunk carriage += chunk
print(carriage) print(carriage)
def clear(self):
print('\033c')
def intro(self):
self.clear()
print(self.title)
def update(self, game): def update(self, game):
print(self.clear) self.clear()
print(self.title) print(self.title)
for player in game.players: for player in game.players:
print(' '+player.name,'''\ print(' '+player.name,'''\
Score:''', player.score(game)) Score:''', player.score(game))
self.print_hand(player, game) self.print_hand(player, game)
if not game.active:
print(game.score())

View file

@ -24,9 +24,8 @@ class GameMaster:
if player.score(self) > 21: if player.score(self) > 21:
self.active = False self.active = False
status = player.name + ' Bust!' status = player.name + ' Bust!'
elif player.blackjack(self):
self.active = False
status = player.name + ' has Blackjack!'
if self.dealer.blackjack(self): return status
self.active = False
status = 'Dealer Blackjack!'
print(status)