yee
This commit is contained in:
parent
de63dd6610
commit
d14d6c23b0
7 changed files with 74 additions and 51 deletions
|
@ -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!')
|
47
main.py
47
main.py
|
@ -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())
|
||||
|
||||
screen.update(game.players)
|
||||
game.score()
|
||||
|
||||
main()
|
||||
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
27
src/gamemaster.py
Normal 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)
|
|
@ -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()
|
|
@ -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)
|
Loading…
Add table
Reference in a new issue