diff --git a/poker_class_version.py b/poker_class_version.py index b341be4..2e44718 100644 --- a/poker_class_version.py +++ b/poker_class_version.py @@ -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:")