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!')
|
|
49
main.py
49
main.py
|
@ -1,13 +1,17 @@
|
||||||
from deck import Deck
|
from src.deck import Deck
|
||||||
from screen import Screen
|
from src.screen import Screen
|
||||||
from gamemaster import GameMaster
|
from src.gamemaster import GameMaster
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
screen = Screen()
|
global kill
|
||||||
num_decks = input('How many decks? (1-8): ')
|
global screen
|
||||||
|
global num_decks
|
||||||
game = GameMaster()
|
|
||||||
deck = Deck()
|
deck = Deck()
|
||||||
|
game = GameMaster()
|
||||||
|
|
||||||
|
if num_decks == 'q':
|
||||||
|
game.active = False
|
||||||
|
|
||||||
if deck.count_below(4):
|
if deck.count_below(4):
|
||||||
deck.shuffle(num_decks)
|
deck.shuffle(num_decks)
|
||||||
|
|
||||||
|
@ -15,30 +19,41 @@ def main():
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
player.hand.append(deck.draw())
|
player.hand.append(deck.draw())
|
||||||
|
|
||||||
dealer = game.players[0]
|
dealer = game.dealer
|
||||||
player = game.players[1]
|
player = game.player
|
||||||
|
|
||||||
|
|
||||||
while game.active:
|
while game.active:
|
||||||
screen.update(game.players)
|
screen.update(game.players)
|
||||||
|
|
||||||
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? ')
|
||||||
else:
|
|
||||||
user_input = input('Play again? [Y/n] ')
|
if not user_input:
|
||||||
|
user_input = 's'
|
||||||
|
|
||||||
match user_input.lower():
|
match user_input.lower():
|
||||||
|
case 'y':
|
||||||
|
game.active = False
|
||||||
case 'q':
|
case 'q':
|
||||||
game.active = False
|
game.active = False
|
||||||
|
kill = True
|
||||||
case 'n':
|
case 'n':
|
||||||
game.active = False
|
game.active = False
|
||||||
case 'h':
|
case 'h':
|
||||||
player.hand.append(deck.draw())
|
player.hand.append(deck.draw())
|
||||||
if player.bust():
|
|
||||||
game.active = False
|
|
||||||
print('Player Bust!')
|
|
||||||
case 's':
|
case 's':
|
||||||
while dealer.score() < 17:
|
while dealer.score() < 17:
|
||||||
dealer.hand.append(deck.draw())
|
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
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):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.hand = []
|
self.hand = []
|
||||||
|
self.blackjack = False
|
||||||
|
self.bust = False
|
||||||
|
|
||||||
def tally_hand(self):
|
def tally_hand(self):
|
||||||
cards = [card[0] for card in self.hand]
|
cards = [card[0] for card in self.hand]
|
||||||
|
@ -18,4 +20,12 @@ class Player:
|
||||||
|
|
||||||
def bust(self):
|
def bust(self):
|
||||||
if self.score() > 21:
|
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()
|
printer = CardPrinter()
|
||||||
|
|
||||||
class Screen:
|
class Screen:
|
||||||
|
@ -14,25 +14,14 @@ o8YooP' 8 .oPYo. .oPYo. 8 .o 8 .oPYo. .oPYo. 8 .o
|
||||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::'''
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::'''
|
||||||
|
|
||||||
|
|
||||||
def update(self, player_list):
|
def update(self, player_list):
|
||||||
print('\033c', end='')
|
print('\033c', end='')
|
||||||
print(title)
|
print(self.title)
|
||||||
for player in player_list:
|
for player in player_list:
|
||||||
print(' '+player.name,
|
print(' '+player.name,
|
||||||
'\t\t\t\t Score:',player.score())
|
'\t\t\t\t Score:',player.score())
|
||||||
printer.print_hand(player)
|
printer.print_hand(player)
|
||||||
|
|
||||||
def player_display_score(self, player):
|
def show_intro(self):
|
||||||
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():
|
|
||||||
print('\033c', end='')
|
print('\033c', end='')
|
||||||
print(screen.title)
|
print(self.title)
|
Loading…
Add table
Reference in a new issue