Added returning cards from hand at end of game
This commit is contained in:
24
BlackJack.py
24
BlackJack.py
@@ -94,12 +94,19 @@ class Deck():
|
||||
def returnFromDiscard(self):
|
||||
self.returnToDeckTop(self.discard.pop())
|
||||
|
||||
def return_all_from_discard(self):
|
||||
self.deck.extend(self.discard)
|
||||
self.discard = []
|
||||
|
||||
def __str__(self) -> str:
|
||||
string = ""
|
||||
for card in self.deck:
|
||||
string += str(card)
|
||||
return string
|
||||
|
||||
def __len__(self):
|
||||
return len(self.deck)
|
||||
|
||||
class Hand():
|
||||
def __init__(self) -> None:
|
||||
self.hand = []
|
||||
@@ -118,6 +125,9 @@ class Hand():
|
||||
card.turn_card()
|
||||
self.add_to_hand(card)
|
||||
|
||||
def __len__(self):
|
||||
return len(self.hand)
|
||||
|
||||
def __str__(self) -> str:
|
||||
string = ""
|
||||
for card in self.hand:
|
||||
@@ -159,6 +169,11 @@ class BlackJack:
|
||||
# Hide one of the dealers cards
|
||||
self.dealerHand.hide_card(1)
|
||||
|
||||
def discard_hand(self, hand):
|
||||
for _ in range(len(hand)):
|
||||
card = hand.remove_from_hand(0)
|
||||
self.deck.addToDiscard(card)
|
||||
|
||||
async def show_cards(self, send, displayDealerScore=False):
|
||||
# Show Cards to player
|
||||
string = f"Player Hand = {repr(self.playerHand)}: {self.playerHand}\nDealer Hand = ??: {self.dealerHand}"
|
||||
@@ -183,6 +198,7 @@ class BlackJack:
|
||||
if playerHit:
|
||||
self.deal_card(self.playerHand)
|
||||
else:
|
||||
self.dealerHand.hide_card(1)
|
||||
gameState = DEALERTURN
|
||||
|
||||
if int(repr(self.playerHand)) >= 21:
|
||||
@@ -192,7 +208,6 @@ class BlackJack:
|
||||
|
||||
if gameState == DEALERTURN:
|
||||
|
||||
self.dealerHand.hide_card(1)
|
||||
self.deal_card(self.dealerHand)
|
||||
if int(repr(self.dealerHand)) >= 17:
|
||||
gameState = FINISHED
|
||||
@@ -201,6 +216,13 @@ class BlackJack:
|
||||
|
||||
await self.show_cards(send, True)
|
||||
await send("You won or lost idk lmao")
|
||||
self.discard_hand(self.playerHand)
|
||||
self.discard_hand(self.dealerHand)
|
||||
|
||||
if len(self.deck) < 0.25 * 51:
|
||||
self.deck.return_all_from_discard()
|
||||
self.deck.shuffle()
|
||||
await send("Everyday I'm shuffling")
|
||||
gameState = OVER
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user