Your little Pocket Hacker

After some time i finally created this little boy.

HackSomeData2_0
Edit: I probably fixed error metioned in comments so it should work just fine.

I’m attaching code for anyone who wants to see how it works :slight_smile:
Edid: I reattached code couse I’ve done some changes.

using System.Collections;
using UnityEngine;

public class Hacker : MonoBehaviour
{
    // Game configuration data
    const float longWaiting = 0.8f;
    const float shortWaiting = 0.015f;
    string[] targets = {
        "  1 -> World Bank [Level.Basic]",
        "  2 -> Area 51 [Level.Intermediate]",
        "  3 -> NASA [Level.Advanced]"
        };
    string[] level1Passwords = { "account", "cheque", "credit", "salary", "email", "invoke" };
    string[] level2Passwords = { "alien", "army", "laboratory", "experiment", "scientist", "facility" };
    string[] level3Passwords = { "telescope", "gravity", "spaceship", "interstellar", "quazar", "nebula" };
    string menuHint = "  * menu -> Return to menu";
    string menuHint2 = " Enter 'menu' to return...";
    string advanceQuestion = "Want to try higher level?\n yes/no";
    string protocol = "POLKMNJUYHBVXCZGDFSATEQWR10293879384676";
    int attempts = 12;

    // Game state
    string username;
    int level;
    string password;
    enum Screen
    {
        LoginWindow, LoadingState, MainMenu, Password, Win, Advance, ProtocolOmega,
        Reloading
    }
    Screen currentScreen;


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

    // Input direction depending on currentScene
    void OnUserInput(string input)
    {
        if (input == "menu")
        {
            currentScreen = Screen.MainMenu;
            ShowMainMenu();
        }
        else if (input == "quit" || input == "close" || input == "exit")
        {
            Terminal.WriteLine("If on the web close the tab");
            Application.Quit();
        }
        else if (currentScreen == Screen.LoginWindow)
        {
            SetUsername(input);
        }
        else if (currentScreen == Screen.MainMenu)
        {
            RunLevel(input);
        }
        else if (currentScreen == Screen.Password)
        {
            CheckPassword(input);
        }
        else if (currentScreen == Screen.Advance)
        {
            AdvanceToHigherLevel(input);
        }
    }

    void ShowLoginWindow()
    {
        currentScreen = Screen.LoginWindow;
        Terminal.WriteLine("  Welcome in [Little Pocket Hacker]");
        Terminal.WriteLine("______________________________________");
        Terminal.WriteLine("> Please enter your name to continue: ");
    }

    void SetUsername(string input)
    {
        username = input;
        currentScreen = Screen.LoadingState;
        StartCoroutine("ShowLoadingScreen");
    }

    IEnumerator ShowLoadingScreen()
    {
        Terminal.ClearScreen();

        yield return new WaitForSeconds(shortWaiting);
        for (int i = 0; i < 1; i++)
        {
            float loadingProcess = 1f;
            yield return new WaitForSeconds(shortWaiting);
            for (int j = 0; j < 100; j++)
            {
                Terminal.ClearScreen();
                Terminal.WriteLine("Your system is now loading, please wait...");
                Terminal.WriteLine("Loading process: " + loadingProcess + "% \r");
                loadingProcess += 1;
                yield return new WaitForSeconds(shortWaiting);
            }
            yield return new WaitForSeconds(longWaiting);

            currentScreen = Screen.MainMenu;
            ShowMainMenu();
        }
    }

    void ShowMainMenu()
    {
        attempts = 12;
        Terminal.ClearScreen();
        Terminal.WriteLine("Welcome " + username);
        Terminal.WriteLine("  **POSSIBLE TARGETS**");
        Terminal.WriteLine("______________________________________");
        Terminal.WriteLine(targets[0]);
        Terminal.WriteLine(targets[1]);
        Terminal.WriteLine(targets[2]);
        Terminal.WriteLine(menuHint);
        Terminal.WriteLine("______________________________________");
        Terminal.WriteLine("> Choose your target to infiltrate ");
        Terminal.WriteLine("> and press ENTER to confirm... ");
    }

    // this should only decide who to handle input, not actually do it. 

    void RunLevel(string input)
    {
        bool isValidLevelNumber = (input == "1" || input == "2" || input == "3");
        if (isValidLevelNumber)
        {
            level = int.Parse(input);
            attempts /= level;
            AskForPassowrd();
        }
        else if (input == "108") // Easter Egg 
        {
            currentScreen = Screen.ProtocolOmega;
            StartCoroutine("ProtocolOmega");
        }
        else
        {
            Terminal.WriteLine(">You can't enter here yet.");
        }
    }

    IEnumerator ProtocolOmega()
    {
        Terminal.ClearScreen();
        Terminal.WriteLine("!!! Divine Hacker trybe activated !!!");
        Terminal.WriteLine("!!! Initializing protocol Omega !!!");
        Terminal.WriteLine("!!! [ B.L.A.C.K.   H.O.L.E. ] !!!");
        yield return new WaitForSeconds(2f);
        for (int i = 0; i < 50; i++)
        {
            Terminal.WriteLine(protocol.Anagram());
            yield return new WaitForSeconds(0.1f);
        }
        for (int i = 0; i < 3; i++)
        {
            yield return new WaitForSeconds(1.2f);
            Terminal.WriteLine(".");
        }
        yield return new WaitForSeconds(2f);
        Terminal.WriteLine(">Nothing happend...");
        yield return new WaitForSeconds(3f);
        Terminal.WriteLine(">Really...");
        yield return new WaitForSeconds(3f);
        Terminal.WriteLine(">Can you just, you know...");
        yield return new WaitForSeconds(1.5f);
        Terminal.WriteLine(">take care of your bussiness?");
        yield return new WaitForSeconds(3f);
        Terminal.WriteLine(">Hack something or write some code...");
        yield return new WaitForSeconds(1.5f);
        Terminal.WriteLine(">Bye!!!");
        yield return new WaitForSeconds(3f);
        currentScreen = Screen.MainMenu;
        ShowMainMenu();
    }

    void AskForPassowrd()
    {
        currentScreen = Screen.Password;
        Terminal.ClearScreen();
        SetRandomPassword();
        Terminal.WriteLine(">Attempts left: [" + attempts + "]");
        Terminal.WriteLine(">Decipher code below to hack system:");
        Terminal.WriteLine("[hint: " + password.Anagram() + " ]");
    }

    void SetRandomPassword()
    {
        switch (level)
        {
            case 1:
                password = level1Passwords[Random.Range(0, level1Passwords.Length)];
                break;
            case 2:
                password = level2Passwords[Random.Range(0, level2Passwords.Length)];
                break;
            case 3:
                password = level3Passwords[Random.Range(0, level3Passwords.Length)];
                break;
            default:
                Debug.LogError("Invalid level value");
                break;
        }
    }

    void CheckPassword(string input)
    {
        if (input == password)
        {
            DisplayWinScreen();
        }
        else
        {
            attempts--;
            if (attempts == 0)
            {
                currentScreen = Screen.Reloading;
                StartCoroutine("Reloading");
            }
            else
            {
                AskForPassowrd();
            }
        }
    }

    IEnumerator Reloading()
    {
        Terminal.ClearScreen();
        Terminal.WriteLine("!!! All attempts failed !!!");
        Terminal.WriteLine("!!! You have been tracked down !!!");
        Terminal.WriteLine("!!! Forced IP changing !!!");
        Terminal.WriteLine("!!! Please try again, after system \nrestart !!!");
        yield return new WaitForSeconds(4f);
        Terminal.ClearScreen();
        Terminal.WriteLine(">System reloaded...");
        yield return new WaitForSeconds(2f);
        Terminal.WriteLine(">IP changed...");
        yield return new WaitForSeconds(2f);
        currentScreen = Screen.MainMenu;
        ShowMainMenu();
    }

    void DisplayWinScreen()
    {
        currentScreen = Screen.Win;
        Terminal.ClearScreen();
        ShowLevelReward();


    }

    void ShowLevelReward()
    {
        switch (level)
        {
            case 1:
                Terminal.WriteLine(@"

|    | _ ._| _|  |~) _ ._ | 
 \/\/ (_)| |(_|  |_)(_|| ||<
"
                );
                Terminal.WriteLine(">You successfuly aquired 1 bilion $!!!");
                Terminal.WriteLine(">Amazing!!! Now you are rich man!!!");
                currentScreen = Screen.Advance;
                Terminal.WriteLine(advanceQuestion);
                break;
            case 2:
                Terminal.WriteLine(@"
     ___
 ___/   \___
/   '---'   \
'--_______--'
    /\O/\
    / | \
    // \\
"
                );
                Terminal.WriteLine(">Fantastic!!!It's True!!!\nWe've never been alone!!!");
                currentScreen = Screen.Advance;
                Terminal.WriteLine(advanceQuestion);
                break;
            case 3:
                Terminal.WriteLine(@"
        _____
    ,-:` \;',`'-, 
  .'-;_,;  ':-;_,'.
 /;   '/    ,  _`.-\
| '`. (`     /` ` \`|
|     (   `,  .`\ ;'|
 \     | .'     `-'/
  `.   ;/        .'
    `'-._____.
"
                );
                Terminal.WriteLine(">Wonderful you have hacked the hardest");
                Terminal.WriteLine(">target!!");
                Terminal.WriteLine(">Time for little vacation, in space!!!");
                Terminal.WriteLine(menuHint2);
                break;
            default:
                Debug.LogError(">Invalid level reached");
                break;
        }
    }

    void AdvanceToHigherLevel(string input)
    {
        if (input == "yes")
        {
            level++;
            attempts = 12 / level;
            AskForPassowrd();
        }
        else if (input == "no")
        {
            currentScreen = Screen.MainMenu;
            ShowMainMenu();
        }
    }
}

Additonal link for ASCII pictures from which I took fantastic pictures:
ASCIItext
ASCIIpictures

I broke the game image

Thank you for playing :slight_smile: I will try to fix it !

Privacy & Terms