I hope I did not DRY mu self. I have not yet looked at Bens solution.
public class Hacker : MonoBehaviour
{
int level;
Screen currentScreen;
enum Screen
{
MainMeny,
Password,
Win
}
// Use this for initialization
void Start ()
{
ShowMainMeny ();
}
void ShowMainMeny ()
{
currentScreen = Screen.MainMeny;
Terminal.ClearScreen ();
Terminal.WriteLine ("What would you like to hack into?");
Terminal.WriteLine ("Press 1 for the local library");
Terminal.WriteLine ("Press 2 for the police station");
Terminal.WriteLine ("Enter your selection");
}
void OnUserInput (string input)
{
if (input == "menu") {
ShowMainMeny ();
} else if (currentScreen == Screen.MainMeny) {
RunMainMenu (input);
} else if (currentScreen == Screen.Password) {
RunPasswordMenu (input);
}
}
void RunMainMenu (string input)
{
if (input == "1") {
level = 1;
StartGame ();
} else if (input == "2") {
level = 2;
StartGame ();
} else {
Terminal.WriteLine ("Please select a valid level");
}
}
void RunPasswordMenu (string input)
{
if ((input == "abc" || input == "def") && level == 1) {
Terminal.WriteLine ("Correct password for level: " + level);
} else if ((input == "123" || input == "456") && level == 2) {
Terminal.WriteLine ("Correct password for level: " + level);
} else {
Terminal.WriteLine ("Wrong password for level: " + level);
}
}
void StartGame ()
{
currentScreen = Screen.Password;
Terminal.WriteLine ("You have chosen the level " + level);
Terminal.WriteLine ("Enter your password");
}
}