CLI should handle all printing
This commit is contained in:
parent
d4e055f2e4
commit
fa1805043a
3 changed files with 21 additions and 22 deletions
19
blackjack.py
19
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':
|
||||
|
|
|
@ -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())
|
|
@ -24,9 +24,8 @@ class GameMaster:
|
|||
if player.score(self) > 21:
|
||||
self.active = False
|
||||
status = player.name + ' Bust!'
|
||||
|
||||
if self.dealer.blackjack(self):
|
||||
elif player.blackjack(self):
|
||||
self.active = False
|
||||
status = 'Dealer Blackjack!'
|
||||
status = player.name + ' has Blackjack!'
|
||||
|
||||
print(status)
|
||||
return status
|
||||
|
|
Loading…
Add table
Reference in a new issue