This commit is contained in:
Adam 2022-12-22 04:58:31 -05:00
parent de63dd6610
commit d14d6c23b0
7 changed files with 74 additions and 51 deletions

View file

@ -1,18 +0,0 @@
from player import Player
class GameMaster:
active = True
players = [Player('Dealer'), Player('Player')] # 5-9 seats
dealer = players[0]
player = players[1]
def score(self):
if self.dealer.score() == self.player.score():
self.active = False
print('Push.')
elif self.dealer.score() > self.player.score():
self.active = False
print('House wins.')
elif self.dealer.score() < self.player.score():
self.active = False
print('You win!')

49
main.py
View file

@ -1,13 +1,17 @@
from deck import Deck
from screen import Screen
from gamemaster import GameMaster
from src.deck import Deck
from src.screen import Screen
from src.gamemaster import GameMaster
def main():
screen = Screen()
num_decks = input('How many decks? (1-8): ')
game = GameMaster()
global kill
global screen
global num_decks
deck = Deck()
game = GameMaster()
if num_decks == 'q':
game.active = False
if deck.count_below(4):
deck.shuffle(num_decks)
@ -15,30 +19,41 @@ def main():
for _ in range(2):
player.hand.append(deck.draw())
dealer = game.players[0]
player = game.players[1]
dealer = game.dealer
player = game.player
while game.active:
screen.update(game.players)
if game.active:
user_input = input(str(deck.count()) + ' cards left in deck.\n[H]it or [S]tand? ')
else:
user_input = input('Play again? [Y/n] ')
if not user_input:
user_input = 's'
match user_input.lower():
case 'y':
game.active = False
case 'q':
game.active = False
kill = True
case 'n':
game.active = False
case 'h':
player.hand.append(deck.draw())
if player.bust():
game.active = False
print('Player Bust!')
case 's':
while dealer.score() < 17:
dealer.hand.append(deck.draw())
game.score()
main()
screen.update(game.players)
game.score()
if not game.active:
user_input = input('Play again? [Y/n] ')
kill = False
screen = Screen()
print(screen.show_intro())
num_decks = input('How many decks? (1-8): ')
while not kill:
main()

27
src/gamemaster.py Normal file
View file

@ -0,0 +1,27 @@
from src.player import Player
class GameMaster:
def __init__(self):
self.active = True
self.players = [Player('Dealer'), Player('Player')] # 5-9 seats
self.dealer = self.players[0]
self.player = self.players[1]
def score(self):
status = 'Error'
if self.dealer.score() == self.player.score():
self.active = False
status = 'Push.'
elif self.dealer.score() > self.player.score():
self.active = False
status = 'House wins.'
elif self.dealer.score() < self.player.score():
self.active = False
status = 'You win!'
for player in self.players:
if player.score() > 21:
self.active = False
status = player.name + ' Bust!'
print(status)

View file

@ -2,6 +2,8 @@ class Player:
def __init__(self, name):
self.name = name
self.hand = []
self.blackjack = False
self.bust = False
def tally_hand(self):
cards = [card[0] for card in self.hand]
@ -18,4 +20,12 @@ class Player:
def bust(self):
if self.score() > 21:
return True
self.bust = True
def blackjack(self):
if self.tally_hand() in [[10,11],[11,10]]:
self.blackjack = True
def check(self):
self.bust()
self.blackjack()

View file

@ -1,4 +1,4 @@
from cardprinter import CardPrinter
from src.cardprinter import CardPrinter
printer = CardPrinter()
class Screen:
@ -14,25 +14,14 @@ o8YooP' 8 .oPYo. .oPYo. 8 .o 8 .oPYo. .oPYo. 8 .o
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::'''
def update(self, player_list):
print('\033c', end='')
print(title)
print(self.title)
for player in player_list:
print(' '+player.name,
'\t\t\t\t Score:',player.score())
printer.print_hand(player)
def player_display_score(self, player):
card_scores = player_score(player)
if sum(card_scores) > 21:
if 11 in card_scores:
index = card_scores.index(11)
card_scores[index] = 1
if player == 'Dealer' and game_active == True:
return sum(card_scores[1:])
else:
return sum(card_scores)
def intro():
def show_intro(self):
print('\033c', end='')
print(screen.title)
print(self.title)