I got it!

Took me a while and there’s probably a bit of unnecessary code but I managed it in the end.

Tried to keep the code tidy anyway by creating separate “game modes” in the enum variable.

This allowed me to assign a password to each mode and possibly some functionality later down the line if I ever need it. I’m not sure haha!

void OnUserInput(string input)
{
    if(input == "menu")
    {
        CurrentScreen = Screen.MainMenu;
        ShowMainMenu("Hello Gema.");
    }
    else if(CurrentScreen == Screen.MainMenu)
    {
        RunMainMenu(input);
    }
    //Added more enum "states" to have individual screens for game modes
    else if(CurrentScreen == Screen.HackLibraryPassword)
    {
       PlayerGuess(input);
    }
    else if(CurrentScreen == Screen.HackPolicePassword)
    {
        PlayerGuess(input);
    }
    else if(CurrentScreen == Screen.HackNasaPassword)
    {
       PlayerGuess(input);
    }
    else
    {
        CurrentScreen = Screen.Win;
        Terminal.WriteLine("CONGRATULATIONS! You're in!");
     //TODO Add a Win Function that asks the user if they would like to exit or play again
    }
}

void RunMainMenu(string input)
{
    if(input == "1")
    {
        Terminal.ClearScreen();
        CurrentScreen = Screen.HackLibraryPassword;
        StartLibraryLevel(input);
    }
    else if(input == "2")
    {
        Terminal.ClearScreen();
        CurrentScreen = Screen.HackPolicePassword;
        StartPoliceLevel(input);
    }
    else if(input == "3")
    {
        Terminal.ClearScreen();
        CurrentScreen = Screen.HackNasaPassword;
        StartNasaLevel(input);
    }
    else if(input == "007")
    {
        Terminal.WriteLine("Welcome, Mr. Bond");
    }
    else //This could probably be removed but added for my own assurance
    {
        Terminal.WriteLine("ERROR: Enter a valid selection.");
    }
}
 //I created separate functions to initialize the game modes and introduce them
void StartLibraryLevel(string input)
{
    GetPassword();
    Terminal.WriteLine("Jaen Local Library.");
    Terminal.WriteLine("PASSWORD REQUIRED.");
    Terminal.WriteLine("Please enter the password: "); 
}

void StartPoliceLevel(string input)
{
    GetPassword();
    Terminal.WriteLine("Jaen Police Station.");
    Terminal.WriteLine("PASSWORD REQUIRED.");
    Terminal.WriteLine("Please enter the password: "); 
}

void StartNasaLevel(string input)
{
    GetPassword();
    Terminal.WriteLine("NASA Space Station.");
    Terminal.WriteLine("PASSWORD REQUIRED.");
    Terminal.WriteLine("Please enter the password: "); 
}

void GetPassword() //Function to initialize password string based on Game mode.
{
    if(CurrentScreen == Screen.HackLibraryPassword)
    {
        Password = "easy";
    }
    else if(CurrentScreen == Screen.HackPolicePassword)
    {
        Password = "medium";
    }
    else if(CurrentScreen == Screen.HackNasaPassword)
    {
        Password = "hard";
    }
    else // Again I added this for my own assurance
    {
        Password = "hello";
    }
}

void PlayerGuess(string input) //Function to avoid repeated code
{

    if(input != Password)
    {
        Terminal.WriteLine("Password INCORRECT.");
        Terminal.WriteLine("Reenter password? (Y/N)");
        TryAgain(input);
    }
    else
    {
        Terminal.WriteLine("CONGRATULATIONS! You're in!");
        CurrentScreen = Screen.Win;
        
    }
}

void TryAgain(string input) //Function to query the user on whether to continue or quit on guess fail
{
    if(input=="Y")
    {
        PlayerGuess(input);
    }
    else if(input == "N")
    {
        CurrentScreen = Screen.MainMenu;
        ShowMainMenu("Hello Gema.");
    }
}

Privacy & Terms