Perhaps way to complicated...but it works :-)

public class Hacker : MonoBehaviour {

// Game state
int level;
string levelOnePassword = "donkey";
string levelTwoPassword = "police";

enum Screen {MainManu, Password, Win };
Screen currentScreen;


// Use this for initialization
void Start ()
{        
    ShowMainMenu();
}

void ShowMainMenu ()
{
    currentScreen = Screen.MainManu;
    Terminal.ClearScreen();
    Terminal.WriteLine("What would you like to hack into?\n");
    Terminal.WriteLine("Press 1 for the library");
    Terminal.WriteLine("Press 2 for the police station\n");
    Terminal.WriteLine("Enter your selection:");
}

void OnUserInput(string input)
{
    if (input == "menu") // we can always go direct to main menu
    {
        
        ShowMainMenu();
    }
    else if (currentScreen == Screen.MainManu)
    {
        RunMainMenu(input);
    }
    else if (currentScreen == Screen.Password)
    {
        RunGame(input);
    }

}

void RunMainMenu(string input)
{
    if (input == "1")
    {
        level = 1;
        StartGame();

    }
    else if (input == "2")
    {
        level = 2;
        StartGame();
    }
    else if (input == "7")
    {
        Terminal.WriteLine("You think you are James Bond 007");
    }
    else
    {
        Terminal.WriteLine("all other");
    }
}

void StartGame()
{
    currentScreen = Screen.Password;
    Terminal.WriteLine("You have chosen level " + level);
}

void RunGame(string input)
{
    if (level == 1)
    {
       if (input == levelOnePassword)
        {
            AnswerCorrect();
        }
        else
        {
            AnswerWrong();
        }
    } 
    else if (level == 2)
    {
        if (input == levelTwoPassword)
        {
            AnswerCorrect();
        }
        else
        {
            AnswerWrong();
        }
    }
}

void AnswerCorrect()
{
    currentScreen = Screen.Win;
    Terminal.WriteLine("Perfect. You have hacked the password");
}

void AnswerWrong()
{
    Terminal.WriteLine("Wrong password. Try it again.");
} 

}

Privacy & Terms