Updated prompt_card_replacement function to prompt for another card if the player enters a card which is not in his hand.

This commit is contained in:
Donald Calloway 2025-09-17 10:55:44 -07:00
parent 4d45d1168e
commit 4ee362911b

View File

@ -93,23 +93,46 @@ class Game:
print("Invalid input. Please enter a number between 0 and 3.")
for _ in range(num):
print("Your hand:\n", player.show_hand())
user_input = input("Enter a card to replace (e.g., A of Spades): ").strip()
if ' of ' not in user_input:
print("Invalid format. Use 'Rank of Suit'.")
continue
while True:
print("\nYour current hand:\n", player.show_hand())
user_input = input("Enter a card to replace (e.g., A of Spades): ").strip()
rank, suit = user_input.split(' of ', 1)
old_card = Card(rank, suit)
if old_card not in player.hand:
print(f"{old_card} not found in your hand.")
continue
if ' of ' not in user_input:
print("Invalid format. Use 'Rank of Suit'.")
continue
new_card = self.deck.deal_card()
if player.replace_card(old_card, new_card):
print(f"Replaced {old_card} with {new_card}")
else:
print("Replacement failed.")
rank, suit = user_input.split(' of ', 1)
old_card = Card(rank, suit)
if old_card not in player.hand:
print(f"{old_card} not found in your hand. Please try again.")
continue
new_card = self.deck.deal_card()
if player.replace_card(old_card, new_card):
print(f"Replaced {old_card} with {new_card}")
else:
print("Replacement failed unexpectedly.")
break # Exit the inner loop once a valid replacement is made
for _ in range(num):
print("Your hand:\n", player.show_hand())
user_input = input("Enter a card to replace (e.g., A of Spades): ").strip()
if ' of ' not in user_input:
print("Invalid format. Use 'Rank of Suit'.")
continue
rank, suit = user_input.split(' of ', 1)
old_card = Card(rank, suit)
if old_card not in player.hand:
print(f"{old_card} not found in your hand.")
continue
new_card = self.deck.deal_card()
if player.replace_card(old_card, new_card):
print(f"Replaced {old_card} with {new_card}")
else:
print("Replacement failed.")
def play(self):
print("Initial hands:")