jeudi 30 septembre 2021

Trying to go back one loop but not to main parent loop

This game requires two inputs from the user: "user_choice" and "player_choice". I get the user_choice input first. The final issue I am running into is on the 2nd input (player_choice). If the user enters something invalid it is making them reselect user_choice, and I just want them to have to reselect player_choice.

def playGame(wordList):
       
    hand = []   
    while True:   
    # ask the user if they want to play
        user_choice = input('Enter n to deal a new hand, r to replay the last hand, or e to end game: ')
        # if they enter 'e' end the game
        if (user_choice == 'e'):
            break
        elif (user_choice == 'r' and len(hand) == 0):
            print('You have not played a hand yet. Please play a new hand first!')
        # if they enter an invalid command send them back
        elif (user_choice != 'n' and user_choice != 'r'):
            print('Invalid command.')
        
        # if they enter n or r ask them who is going to play
        if (user_choice == 'n' or user_choice == 'r'):
            player_choice = input('Enter u to have yourself play, c to have the computer play: ')
            # if human is playing follow the steps from before
            if (player_choice == 'u'):
                if (user_choice == 'n'):
                    hand = dealHand(HAND_SIZE)
                    playHand(hand, wordList, HAND_SIZE)
                elif (user_choice == 'r' and len(hand) != 0):
                    playHand(hand, wordList, HAND_SIZE)
                else :
                    print('You have not played a hand yet. Please play a new hand first!')
                    
            # if computer is playing . . .
            elif (player_choice == 'c'):
                if (user_choice == 'n'):
                    hand = dealHand(HAND_SIZE)
                    compPlayHand(hand, wordList, HAND_SIZE)
                elif (user_choice == 'r' and len(hand) != 0):
                    compPlayHand(hand, wordList, HAND_SIZE)
                else:
                    print('You have not played a hand yet. Please play a new hand first!')
            else:
                print('Invalid command.')
                continue

'''

Aucun commentaire:

Enregistrer un commentaire