BlackJack Finished
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import random
|
||||
from Ledger import Ledger
|
||||
|
||||
#TODO Starting a game with 21 fucks with hidden cards
|
||||
#TODO Look into 5card jack thingo that Tim mentioned
|
||||
#TODO Insurance - If dealer starts with 21, you can bet against it and win your money back
|
||||
#TODO Make each game session more distinct (Embeds?)
|
||||
@@ -30,9 +29,11 @@ class Card():
|
||||
self.suit = suit
|
||||
self.hidden = False
|
||||
|
||||
def turn_card(self):
|
||||
# XOR to flip hidden element
|
||||
self.hidden = self.hidden != True
|
||||
def hide_card(self):
|
||||
self.hidden = True
|
||||
|
||||
def show_card(self):
|
||||
self.hidden = False
|
||||
|
||||
def get_value(self):
|
||||
return self.value
|
||||
@@ -67,11 +68,11 @@ class Deck():
|
||||
self.discard = []
|
||||
self.joker = joker
|
||||
|
||||
self.deck.extend([Card(x, Card.HEARTS) for x in range(1, 13)])
|
||||
self.deck.extend([Card(x, Card.DIAMONDS) for x in range(1, 13)])
|
||||
self.deck.extend([Card(x, Card.SPADES) for x in range(1, 13)])
|
||||
self.deck.extend([Card(x, Card.CLUBS) for x in range(1, 13)])
|
||||
|
||||
self.deck.extend([Card(x, Card.HEARTS) for x in range(1, 14)])
|
||||
self.deck.extend([Card(x, Card.DIAMONDS) for x in range(1, 14)])
|
||||
self.deck.extend([Card(x, Card.SPADES) for x in range(1, 14)])
|
||||
self.deck.extend([Card(x, Card.CLUBS) for x in range(1, 14)])
|
||||
print(len(self.deck))
|
||||
if joker:
|
||||
self.deck.append(Card(0, 0))
|
||||
|
||||
@@ -113,6 +114,7 @@ class Deck():
|
||||
class Hand():
|
||||
def __init__(self) -> None:
|
||||
self.hand = []
|
||||
self.hidden_cards = []
|
||||
|
||||
def sortHand(self):
|
||||
self.hand.sort()
|
||||
@@ -130,7 +132,22 @@ class Hand():
|
||||
return self.hand[index]
|
||||
|
||||
def hide_card(self, index):
|
||||
self.peek_card(index).turn_card()
|
||||
card = self.peek_card(index)
|
||||
card.hide_card()
|
||||
self.hidden_cards.append(card)
|
||||
|
||||
def show_card(self, index):
|
||||
card = self.peek_card(index)
|
||||
card.show_card()
|
||||
try:
|
||||
self.hidden_cards.remove(card)
|
||||
except ValueError:
|
||||
print("Card not hidden")
|
||||
|
||||
def show_hand(self):
|
||||
for card in self.hidden_cards:
|
||||
card.show_card()
|
||||
self.hidden_cards.remove(card)
|
||||
|
||||
def __len__(self):
|
||||
return len(self.hand)
|
||||
@@ -151,7 +168,8 @@ class Hand():
|
||||
aces += 1
|
||||
continue
|
||||
if card.value > 10:
|
||||
card.value = 10
|
||||
value += 10
|
||||
continue
|
||||
value += card.value
|
||||
|
||||
# Dynamically add ace value based on ideal rules
|
||||
@@ -173,7 +191,6 @@ class Hand():
|
||||
|
||||
def __next__(self):
|
||||
return next(self.iter)
|
||||
|
||||
|
||||
class BlackJack:
|
||||
def __init__(self) -> None:
|
||||
@@ -196,6 +213,7 @@ class BlackJack:
|
||||
self.dealerHand.hide_card(1)
|
||||
|
||||
def discard_hand(self, hand):
|
||||
hand.show_hand()
|
||||
for _ in range(len(hand)):
|
||||
card = hand.remove_from_hand(0)
|
||||
self.deck.addToDiscard(card)
|
||||
@@ -219,6 +237,9 @@ class BlackJack:
|
||||
playerStats = self.ledger.read(ID)
|
||||
self.game_setup()
|
||||
gameState = PLAYERTURN
|
||||
|
||||
if int(repr(self.playerHand)) >= 21:
|
||||
gameState = FINISHED
|
||||
|
||||
if gameState == PLAYERTURN:
|
||||
|
||||
@@ -227,13 +248,9 @@ class BlackJack:
|
||||
if playerHit:
|
||||
self.deal_card(self.playerHand)
|
||||
else:
|
||||
#TODO Rename hide_card function
|
||||
self.dealerHand.hide_card(1)
|
||||
gameState = DEALERTURN
|
||||
|
||||
if int(repr(self.playerHand)) >= 21:
|
||||
|
||||
self.dealerHand.hide_card(1)
|
||||
gameState = FINISHED
|
||||
|
||||
if gameState == DEALERTURN:
|
||||
@@ -247,6 +264,7 @@ class BlackJack:
|
||||
|
||||
if gameState == FINISHED:
|
||||
|
||||
self.dealerHand.show_hand()
|
||||
playerBlackJack = False
|
||||
dealerBlackJack = False
|
||||
playerBust = False
|
||||
|
||||
BIN
src/py/__pycache__/BlackJack.cpython-310.pyc
Normal file
BIN
src/py/__pycache__/BlackJack.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/py/__pycache__/Calculator.cpython-310.pyc
Normal file
BIN
src/py/__pycache__/Calculator.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/py/__pycache__/Gamepicker.cpython-310.pyc
Normal file
BIN
src/py/__pycache__/Gamepicker.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/py/__pycache__/Ledger.cpython-310.pyc
Normal file
BIN
src/py/__pycache__/Ledger.cpython-310.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user