My Personal Hacker Assistant (After Full Course)

So, It’s still pretty basic, it has no real eastereggs (It has a test screen that I used to fit everything in the screen) and it’s pretty much a work in progress. But I felt I was overthinking this, and since it’s working I at least wanted to share how far I got.

The difficulty of the anagrams ramps up quite a bit, and I might at a later date add a bit more comprehensive hints that may line up with a story of sorts. But that takes time and inspiration.
But so far:

http://www.sharemygame.com/share/445bc09f-87a2-46d0-99b6-79075f026f4b

So, making additional hints wasn’t as easy as I thought, but it might feel more like actual hacking. I learned a great deal of new code options, like how to manipulate different type of arrays and making them work like I want them to work. In the end the code wasn’t all that hard, but only after looking back at it now. At least it will give me a great deal more options for future creations.

http://www.sharemygame.com/share/379a609a-4a68-4133-a507-de4443b4e1bc

Hey, I really like how you let them keep working on the same word if they get it wrong. The course just teaches you how to select a new random word (might be the same or might be a different word).

Can you point me in the right direction of how you did that?

First I have a set of variables that i call at the top of the hacker.cs, just so that I can use them freely throughout the script. I think In some cases I can call them on the spot, but I didn’t bother to check when I could.

Either way I have a value for the number of hacks used, and attempts, to track it for the player, and for options later on to limit it. At the main menu I reset that value to zero, as that indicates a new password and set of attempts. It’s… going to be very refactored and drawn out for clarity as I thought i should get into keeping my code clean as the course generally instructs. Either way I will explain along the way anyway.

Anyway I run my password screen slightly different:

void RunPasswordScreen(string input)
{
    if (input == password)
    {
        WinGame();
    }
    else if (input == "hack" && nrofhacks < PWArray.Length) // once the password is fully hacked, don't hack.
    {
        nrofhacks++;
        UpdateHackedPW();
        ShowPasswordScreen(); //update password screen with new values
    }
    else
    {
        attempts++; //Password is false, thus attempts increase
        ShowPasswordScreen(); //update password screen
    }
}

The Show password screen sets the password initially (in CheckAttempts) and checks and prints what needs to be on the password screen.

void ShowPasswordScreen()
{
    currentScreen = Screen.Password;
    Terminal.ClearScreen();
    gameHeader();
    Terminal.WriteLine("> Now hacking a" + difficultyNames[(level - 1)] + " useraccount.");
    CheckAttempts();
    Terminal.WriteLine("> Last keystrokes: " + password.Anagram());
    CheckForHacks();
    Terminal.WriteLine("Please enter password: ");
}

CheckAttempts, checks whether there’s no attempts and thus needs to generate a new password AND makes the necessary arrays out of it immediately. Then increases the attempts value and on higher attempts values gives you the false PW message. (could be modified for custom messages at specific or even set a maximum of attempts)

void CheckAttempts()
{
    switch (attempts)
    {
        case 0:
            setPassword();
            MakePWArrays();
            attempts++; //first attempt
            Terminal.WriteLine("> ");
            break;
        case 1:
            Terminal.WriteLine("> ");
            break;
        default:
            Terminal.WriteLine("X ACCESS DENIED");
            Terminal.WriteLine("> Shuffling Encrypted Data");
            break;

    }
}

And this is what I use to make the password arrays, I used and kept a very simple function because I copied and dialed back the anagram function in the Utility.cs script. It’s a nice example of how a function that returns a value, works at least. And ofcourse made an empty hackedPWarray with the same length as the PWarray, which I filled with a for-loop to make an array of just dots. Each step for a 4 letter password:

(.    )(..  )(... )(....)

BTW, it took me a while to figure out that a character is indicated with single quotation marks IE.: ‘a’ instead of “a” (which is a string)

void MakePWArrays()
{
    PWArray = MakePWArray(password);
    numberOfCharacters = PWArray.Length;
    hackedPWArray = new char[numberOfCharacters];
    for (int i = 0; i < numberOfCharacters; i++)
    {
        hackedPWArray[i] = '.';
    }
}

char[] MakePWArray(string pw)
{
    char[] chararray = pw.ToCharArray();
    return chararray;
}

And then, which is a mindblowingly simple method, at least after I understood the anagram script, this was marginally more simpler, to fill replace the dots with the actual letters: (Which get called when you type hack, and calls itself if it doesn’t get an index with a dot in in it, thus loops until it gets a new character.

   void UpdateHackedPW()
{
    int index = Random.Range(0,numberOfCharacters);
    if (hackedPWArray[index] == '.')
    {
        hackedPWArray[index] = PWArray[index];
    }
    else
    {
        UpdateHackedPW();
    }
}

There’s lots of things you can do from there on out I think. You could also make an anagram ONLY as you set the password, and then show the same anagram throughout the hacking, as to give the player control over when they want to shuffle the letters, rather than have it automatically done each time the update screen refreshes.

Privacy & Terms