Added returning cards from hand at end of game

This commit is contained in:
2023-07-19 11:12:13 +10:00
parent 33a1fb01f6
commit 210cb37575
2 changed files with 23 additions and 1 deletions

View File

@@ -93,6 +93,10 @@ class Deck():
def returnFromDiscard(self): def returnFromDiscard(self):
self.returnToDeckTop(self.discard.pop()) self.returnToDeckTop(self.discard.pop())
def return_all_from_discard(self):
self.deck.extend(self.discard)
self.discard = []
def __str__(self) -> str: def __str__(self) -> str:
string = "" string = ""
@@ -100,6 +104,9 @@ class Deck():
string += str(card) string += str(card)
return string return string
def __len__(self):
return len(self.deck)
class Hand(): class Hand():
def __init__(self) -> None: def __init__(self) -> None:
self.hand = [] self.hand = []
@@ -117,6 +124,9 @@ class Hand():
card = self.remove_from_hand(index) card = self.remove_from_hand(index)
card.turn_card() card.turn_card()
self.add_to_hand(card) self.add_to_hand(card)
def __len__(self):
return len(self.hand)
def __str__(self) -> str: def __str__(self) -> str:
string = "" string = ""
@@ -158,6 +168,11 @@ class BlackJack:
# Hide one of the dealers cards # Hide one of the dealers cards
self.dealerHand.hide_card(1) 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): async def show_cards(self, send, displayDealerScore=False):
# Show Cards to player # Show Cards to player
@@ -183,6 +198,7 @@ class BlackJack:
if playerHit: if playerHit:
self.deal_card(self.playerHand) self.deal_card(self.playerHand)
else: else:
self.dealerHand.hide_card(1)
gameState = DEALERTURN gameState = DEALERTURN
if int(repr(self.playerHand)) >= 21: if int(repr(self.playerHand)) >= 21:
@@ -192,7 +208,6 @@ class BlackJack:
if gameState == DEALERTURN: if gameState == DEALERTURN:
self.dealerHand.hide_card(1)
self.deal_card(self.dealerHand) self.deal_card(self.dealerHand)
if int(repr(self.dealerHand)) >= 17: if int(repr(self.dealerHand)) >= 17:
gameState = FINISHED gameState = FINISHED
@@ -201,6 +216,13 @@ class BlackJack:
await self.show_cards(send, True) await self.show_cards(send, True)
await send("You won or lost idk lmao") 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 gameState = OVER