ui handle all ui
This commit is contained in:
parent
fa1805043a
commit
8076cb6b15
2 changed files with 21 additions and 14 deletions
21
blackjack.py
21
blackjack.py
|
@ -1,10 +1,10 @@
|
||||||
from src.deck import Deck
|
from src.deck import Deck
|
||||||
from src.display import CLI
|
from src.io import CLI
|
||||||
from src.gamemaster import GameMaster
|
from src.gamemaster import GameMaster
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global kill
|
global kill
|
||||||
global display
|
global ui
|
||||||
global num_decks
|
global num_decks
|
||||||
global deck
|
global deck
|
||||||
game = GameMaster()
|
game = GameMaster()
|
||||||
|
@ -17,7 +17,7 @@ def main():
|
||||||
player = game.player
|
player = game.player
|
||||||
|
|
||||||
while game.active:
|
while game.active:
|
||||||
display.update(game)
|
ui.update(game)
|
||||||
|
|
||||||
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? ')
|
||||||
|
@ -38,14 +38,13 @@ def main():
|
||||||
game.active = False
|
game.active = False
|
||||||
while dealer.score(game) < 17:
|
while dealer.score(game) < 17:
|
||||||
dealer.hand.append(deck.draw())
|
dealer.hand.append(deck.draw())
|
||||||
|
ui.update(game)
|
||||||
display.update(game)
|
|
||||||
|
|
||||||
kill = False
|
kill = False
|
||||||
display = CLI()
|
ui = CLI()
|
||||||
display.intro()
|
ui.intro()
|
||||||
|
|
||||||
num_decks = input('How many decks? (1-8): ')
|
num_decks = ui.get_decks()
|
||||||
if num_decks == 'q':
|
if num_decks == 'q':
|
||||||
kill = True
|
kill = True
|
||||||
|
|
||||||
|
@ -53,9 +52,5 @@ deck = Deck(num_decks)
|
||||||
|
|
||||||
while not kill:
|
while not kill:
|
||||||
main()
|
main()
|
||||||
user_input = input('Play again? [Y/n] ')
|
if not ui.play_again():
|
||||||
match user_input.lower():
|
|
||||||
case 'n':
|
|
||||||
kill = True
|
|
||||||
case 'q':
|
|
||||||
kill = True
|
kill = True
|
||||||
|
|
|
@ -109,3 +109,15 @@ o8YooP' 8 .oPYo. .oPYo. 8 .o 8 .oPYo. .oPYo. 8 .o
|
||||||
self.print_hand(player, game)
|
self.print_hand(player, game)
|
||||||
if not game.active:
|
if not game.active:
|
||||||
print(game.score())
|
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
|
Loading…
Add table
Reference in a new issue