added Game.show_cards() method

This commit is contained in:
2025-10-27 18:28:54 +01:00
parent a7f1ec667c
commit f41c759814

View File

@@ -17,7 +17,7 @@ class Game:
self.player = Player(0)
self.dealer = Dealer(1000)
def compare_hands(self, bet: int) -> str:
def compare_hands(self, bet: float) -> str:
"""*Resolution/Payout*: Compares final hand values, checks for
Bust, Blackjack, and highest value.
@@ -25,9 +25,6 @@ class Game:
*Returns* the result string (e.g., "Player Wins!")."""
# HACK: this might work but certainly needs to be fixed.
# check if Player or Dealer busts
player_value = self.player.hand.value
dealer_value = self.dealer.hand.value
player_cards = len(self.player.hand.cards)
@@ -43,7 +40,6 @@ class Game:
return "Player Wins"
# Check for Blackjack (21 with 2 cards)
is_player_bj = player_value == 21 and player_cards == 2
is_dealer_bj = dealer_value == 21 and dealer_cards == 2
@@ -58,10 +54,29 @@ class Game:
if player_value > dealer_value:
self.player.chips += bet
return "Player Wins"
elif player_value < dealer_value:
self.player.chips -= bet
return "Player Lost"
else:
return "Tie"
def show_cards(self, hide_dealer: bool = False) -> None:
"""Displays the cards. The boolean determines if the dealer's
second card is shown or concealed."""
player_cards = self.player.hand.cards
dealer_cards = self.dealer.hand.cards
print("--Player Cards:--")
for card in player_cards:
print(str(card))
if hide_dealer:
card = dealer_cards[0]
print("--Dealer Cards:--")
print(str(card))
print("XXXX")
else:
print("--Dealer Cards:--")
for card in dealer_cards:
print(str(card))