Control: Terminal Hacker

My take on the Terminal Hacker tutorial:

I added some secrets (based on one of my recent favourite games), and tried to jazz it up a little bit. Any critique is welcome, and I’ll add the code below. Any tips on refactoring further would be appreciated.

A quick thanks to the GameDev.tv team. I’ve been struggling to learn C# for a while now, but going through this tutorial made things a lot more clear for me.

    ////////////////
    // Game Data //
    ///////////////

    // Game config
    string[] level1Password = { "email", "music", "files", "games", "videos" };
    string[] level2Password = { "password", "exams", "teachers", "students", "library" };
    string[] level3Password = { "extraterrestrial", "roswell", "pentagon", "nuclear", "kennedy" };

    string[] sLevel1Password = { "hiss", "jesse", "duck", "pope", "board" };
    string[] sLevel2Password = { "darling", "trench", "hotline", "astral", "altered" };
    string[] sLevel3Password = { "mannequin", "oscillator", "simulacrum", "oceanview", "polaris" };

    // Game state 
    public int level;
    public string password;
    enum Screen { MainMenu, SecretMenu, Password, SecretPassword, Win };
    Screen currentScreen;

    // Initialisation
    void Start()
    {
        currentScreen = Screen.MainMenu;
        ShowMainMenu("Hello Dreamer.");
    }

    ///////////////////////
    // Main Menu Section //
    ///////////////////////

    // Normal and secret menu screens
    void ShowMainMenu(string greeting)
    {
        Terminal.ClearScreen();
        Terminal.WriteLine(greeting);
        // Normal menu
        if (currentScreen == Screen.MainMenu)
        {
            Terminal.WriteLine("A breach exists.");
            Terminal.WriteLine("You must reveal it.");
            Terminal.WriteLine("\nWhich link shall we hack first?");
            Terminal.WriteLine("\n1. Your Friend? (Easy)\n2. Your College? (Medium)\n3. Your Government? (Hard)");
            Terminal.WriteLine("\nSelect link:");
        }
        // Secret menu
        else if (currentScreen == Screen.SecretMenu)
        {
            Terminal.WriteLine("A breach/threshold exists.");
            Terminal.WriteLine("You must reveal/destroy it.");
            Terminal.WriteLine("\nExplore the Oldest House.");
            Terminal.WriteLine("1. Executive (Easy)\n2. Maintenance (Medium)\n3. Research (Hard)");
            Terminal.WriteLine("\nSelect floor:");
        }
        
    }

    // Typo catch-all
    void WrongKey()
    {
        if (currentScreen == Screen.MainMenu || currentScreen == Screen.SecretMenu || currentScreen == Screen.Win)
        {
            Terminal.WriteLine("Wrong key/s.");
            Terminal.WriteLine("Type 'help' for a list of commands.");
        }
        else
        {
            Terminal.WriteLine("Incorrect.");
            Terminal.WriteLine("Type 'help' for a list of commands.");
        }
    }

    // Input that can run on any screen
    void OnUserInput(string input)
    {
        if (input == "menu")
        {
            currentScreen = Screen.MainMenu;
            ShowMainMenu("Welcome back.");
        }
        else if (input == "control")
        {
            currentScreen = Screen.SecretMenu;
            ShowMainMenu("Greetings, Director.");
        }
        else if (input == "help")
        {
            Terminal.WriteLine("\nmenu = Main Menu");
            if (currentScreen == Screen.MainMenu || currentScreen == Screen.SecretMenu)
            {
                Terminal.WriteLine("1-3 = Level choice\n");
            }
            else if (currentScreen == Screen.Password || currentScreen == Screen.SecretPassword)
            {
                Terminal.WriteLine("reset = Restart current level");
                Terminal.WriteLine("Type the solution and press enter:");
            }
        }
        else if (input == "DIRECTOR")
        {
            Terminal.ClearScreen();
            Terminal.WriteLine("Credits:");
            Terminal.WriteLine("\nCreated with the help of GameDev.tv.");
            Terminal.WriteLine("Terminal design by GameDev.tv.");
            Terminal.WriteLine("Terminal code by SilentKingdom13.");
            Terminal.WriteLine("\nSecret game based on 'Control', \ndeveloped by Remedy Entertainment.");
            Terminal.WriteLine("\nThanks for playing :)");
        }
        // Gets input when on the main menu
        else if (currentScreen == Screen.MainMenu)
        {
            RunMainMenu(input);
        }
        // Gets input when on the secret menu
        else if (currentScreen == Screen.SecretMenu)
        {
            RunSecretMenu(input);
        }
        // Gets input on the password screen
        else if (currentScreen == Screen.Password)
        {
            RunPasswordMenu(input);
        }
        // Gets input on the secret password screen
        else if (currentScreen == Screen.SecretPassword)
        {
            RunSecretPasswordMenu(input);
        }
        else if (input != "menu" || input != "control" || input != "help" || input != "DIRECTOR")
        {
            WrongKey();
        }
    }

    // Only accepts input on main menu
    void RunMainMenu(string input)
    {
        switch (input)
        {
            case "1":
                Terminal.WriteLine("You chose your friend.");
                password = level1Password[Random.Range(0, level1Password.Length)];
                level = 1;
                StartGame();
                break;
            case "2":
                Terminal.WriteLine("You chose your college.");
                password = level2Password[Random.Range(0, level2Password.Length)];
                level = 2;
                StartGame();
                break;
            case "3":
                Terminal.WriteLine("You chose your government.");
                password = level3Password[Random.Range(0, level3Password.Length)];
                level = 3;
                StartGame();
                break;
            default:
                WrongKey();
                break;
        }
    }


    // Only accepts input on secret menu
    void RunSecretMenu(string input)
    {
        switch (input)
        {
            case "1":
                Terminal.WriteLine("You have the clearance to proceed.");
                password = sLevel1Password[Random.Range(0, sLevel1Password.Length)];
                level = 1;
                SecretGame();
                break;
            case "2":
                Terminal.WriteLine("The Janitor is waiting for you.");
                password = sLevel2Password[Random.Range(0, sLevel2Password.Length)];
                level = 2;
                SecretGame();
                break;
            case "3":
                Terminal.WriteLine("The Hiss are close.");
                password = sLevel3Password[Random.Range(0, sLevel3Password.Length)]; 
                level = 3;
                SecretGame();
                break;
            default:
                WrongKey();
                break;

        }
    }

    //////////////////////
    // Password Section //
    //////////////////////

    // Normal game
    void StartGame()
    {
        currentScreen = Screen.Password;
        Terminal.ClearScreen();
        Terminal.WriteLine("Please enter the password:");
        Terminal.WriteLine("Hint: " + password.Anagram());
    }

    // Secret game
    void SecretGame()
    {
        currentScreen = Screen.SecretPassword;
        Terminal.ClearScreen();
        Terminal.WriteLine("Please connect your service weapon:");
        Terminal.WriteLine("Hint: " + password.Anagram());
    }

    // Only accepts input on password menu
    void RunPasswordMenu(string input)
    {
        if (input == password)
        {
            WinScreen();
        }
        else if (input == "reset")
        {
            Terminal.ClearScreen();
            Terminal.WriteLine("Hint: " + password.Anagram());
        }
        else
        {
            WrongKey();
        }
    }

    // Only accepts input on secret password menu
    void RunSecretPasswordMenu(string input)
    {
        if (input == password)
        {
            SecretWinScreen();
        }
        else if (input == "reset")
        {
            Terminal.ClearScreen();
            Terminal.WriteLine("Hint: " + password.Anagram());
        }
        else
        {
            WrongKey();
        }
    }

    /////////////////
    // Win Section //
    /////////////////

    // Normal win screen rewards
    void WinScreen()
    {
        currentScreen = Screen.Win;
        Terminal.ClearScreen();
        Terminal.WriteLine("Well done!");
        // Reward depending on level won
        switch(level)
        {
            case 1:
                Terminal.WriteLine(@"
           _____________
          |.-----------.|
          || 'control' ||
          ||           ||
          |'-----------'|
           `)__    ___('
           [===  --- o ]
           '-----------'  ");
                break;
            case 2:
                Terminal.WriteLine(@"

              /-/|
             /_/ |
             | |/|
             |^| |
             |_|/

                ");
                break;
            case 3:
                Terminal.WriteLine(@"
              ,/`.
            ,'/ __`.
          ,'_/_  _ _`.
        ,'__/_ ___ _  `.
      ,'_  /___ __ _ __ `.
     '-.._/___...--.- ..__`.

                ");
                break;
            default:
                Terminal.WriteLine("Error. Type 'menu' to restart:");
                break;
        }
        Terminal.WriteLine("Type 'menu' to return to Main Menu.");
    }

    // Secret win screen rewards
    void SecretWinScreen()
    {
        currentScreen = Screen.Win;
        Terminal.ClearScreen();
        Terminal.WriteLine("Well done, Director.");
        Terminal.WriteLine("The Hiss are gone/destroyed.");
        // Reward depending on level won
        switch (level)
        {
            case 1:
                Terminal.WriteLine(@"
             __________
            (_]------[_)
           .~ | .''. |
           ~. | '..' |
             ``------` ");
                break;
            case 2:
                Terminal.WriteLine(@"
                        _.----.
      .----------------' /  /  \
     (   'DIRECTOR'   | |   |) |
      `----------------._\  \  /
                         '----'");
                break;
            case 3:
                Terminal.WriteLine(@"
    -. .-.   .-. .-.   .-. .-.   .
      \   \ /   \   \ /   \   \ /
     / \   \   / \   \   / \   \
    ~   `-~ `-`   `-~ `-`   `-~ `-");
                break;
            default:
                Terminal.WriteLine("Error. Type 'control' to restart:");
                break;
        }
        Terminal.WriteLine("Type 'control' to return to \nSecret Menu.");

2 Likes

Isn’t amazing when the fog clears and you start to understand what you are building.

2 Likes

Privacy & Terms