MathBul / MathBul-Text_based_Adventure_Game-BULAT_Mathilde-CDOF1

MIT License
1 stars 1 forks source link

Bug Report: Handling of User Choices Exceeding Option Range #5

Open noemiegs opened 9 months ago

noemiegs commented 9 months ago

Hello,

While reviewing the code for the "Text based Adventure Game," I noticed a logical issue in the make_choice function that may affect the game's flow when handling user inputs.

Issue Description: The make_choice function is designed to prompt the user to choose from a given set of options. However, there's currently no explicit handling for cases where the user inputs a number that exceeds the range of available options. For example, if there are 2 options and the user enters '3', the game accepts this input without any error message or re-prompt.

Steps to Reproduce:

  1. Run the game and reach any point where a choice is to be made (e.g., choosing between taking the bus or walking).

  2. When prompted for input, enter a numeric value that exceeds the number of available options.

  3. Observe the game's response to this input.

Expected Behavior: The game should prompt the user again for a valid choice within the range of available options.

Actual Behavior: The game accepts out-of-range numeric inputs without any error message, potentially leading to unexpected game behavior or missed game paths.

Suggested Fix: Modify the while loop condition in the make_choice function to explicitly check if the user input is within the range of available options. Here's a modified code snippet:

while True:
    try:
        choice = int(input("Votre choix: "))
        if 1 <= choice <= len(options):
            break
        else:
            print(f"Veuillez choisir un numéro entre 1 et {len(options)}.")
    except ValueError:
        print("Veuillez entrer un numéro valide.")

This modification ensures that the input is both an integer and within the valid range of options.

I hope this information is helpful for improving the game's user input handling.

Noemie

MathBul commented 9 months ago

Hello,

Thank you for you commit, it is a pleasure to see the code being improved.