Bug - CheckPassword - resetting password when incorrect

Hello,

I am really enjoying this class so far!

Per the game design, I feel that there is a bug in the CheckPassword code.

void CheckPassword(string input)
    {
        if (input == password)
        {
            DisplayWinScreen();
        }
        else
        {
            AskForPassword();  <-------------
        }
    }

When you AskForPassword it will reset the password and then run the anagram. If I am understanding the design correctly, the idea is to only rerun the anagram so as to give a further hint to the correct password. Not reset password again.

void AskForPassword()
{
    currentScreen = Screen.Password;
    Terminal.ClearScreen();
    SetRandomPassword(); <----------------
    Terminal.WriteLine("Enter your password, hint: " + password.Anagram());
    Terminal.WriteLine(menuHint);
}

A possible solution to this could be to only set the random password in the RunMainMenu method.

.......
    {
                level = int.Parse(input);
                SetRandomPassword(); <-------------------------
                AskForPassword();
     }
........

Thank you again for creating all this content. I am looking forward to the next section!

Michael

1 Like

You are right on that. I’ve found it weird when I saw it resetting. Your solution is correct too.

Privacy & Terms