My Solution

Full disclosure: I have some knowledge of Python and bits and pieces of other programming languages.

I’m not sure this is the most efficient solution, but here is mine. I haven’t looked at the teacher’s solution yet to see what the “real” answer is.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hacker : MonoBehaviour {
    int level;
    string passWord;

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

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

    void ShowMainMenu() {
        currentScreen = Screen.MainMenu;
        Terminal.ClearScreen();
        Terminal.WriteLine("BROOTFORCE2K: CHOOZ A SITE 2 HAXXXOR");
        Terminal.WriteLine("");
        Terminal.WriteLine("1. Sunshine Valley Elementary School");
        Terminal.WriteLine("2. Springfield Agricultural College");
        Terminal.WriteLine("3. Gryzzl");
        Terminal.WriteLine("");
        Terminal.WriteLine("Choose wisely: ");
    }

    void OnUserInput(string input)
    {
        if (input == "menu")
        {
            ShowMainMenu();          
        }
        else if (currentScreen == Screen.MainMenu)
        {
            RunMainMenu(input);
        }
        else if (currentScreen == Screen.Password)
        {
            CheckPassWord(input);
        }
    }

    void CheckPassWord(string input)
    {
       if(input == passWord)
        {
            Terminal.WriteLine("Root Access Granted!");
        }
       else
        {
            Terminal.WriteLine("Access Denied.");
            Terminal.WriteLine("Password: ");
        }
    }

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

        }
        else if (input == "3")
        {
            level = 3;
            StartGame();

        }
        else if (input == "1337")
        {
            Terminal.WriteLine("All ur base r belong 2 us");
        }
        else
        {
            Terminal.WriteLine("Unrecognized command");
        }
    }

    void StartGame()
    {
        currentScreen = Screen.Password;
        Terminal.ClearScreen();

        if(level == 1)
        {
            passWord = "chair";
            Terminal.WriteLine("Welcome to Sunshine Elementary!");
            Terminal.WriteLine("username: admin");
            Terminal.WriteLine("password: ");
        }
        else if (level == 2)
        {
            passWord = "medicine";
            Terminal.WriteLine("Springfield College Mainframe");
            Terminal.WriteLine("username: admin");
            Terminal.WriteLine("password: ");
        }

    }
}

Privacy & Terms