First Solo

I found this challenge to be quite fun. I got a bit stuck and needed some help but I was able to with minimal guidance get a nice working system.

The first thing I did was I knew I needed a dynamic way to store and get passwords. I decided to use string arrays to hold the data and then I could randomly select a password.

string GenerateHint()
    {
        // Easy
        if (level == 1)
        {
            int index = rand.Next(easy.Length);
            word = easy[index];            
            ScramblePassword(easy[index]);
            return scramble;
        }
        // Medium
        else if (level == 2)
        {
            int index = rand.Next(medium.Length);
            word = medium[index];
            ScramblePassword(medium[index]);
            return scramble;
        }
        // Hard
        else
        {
            int index = rand.Next(hard.Length);
            word = hard[index];
            ScramblePassword(hard[index]);
            return scramble;
        }
    }

I also built a scrambler to make the anagram hints randomly versus hard coding them in. This makes it so that I can add any number of passwords and not have to worry about typing a scrambled version each time. It also makes the game different each time you launch it.

void ScramblePassword(string password)
    {
        // Create a character array from the password
        char[] chars = new char[password.Length];
        // set default counter
        int index = 0;
        // loop through and scramble the character array
        while (password.Length > 0)
        {
            // index of the character to grab
            int charAt = rand.Next(0, password.Length - 1);

            // Grab the character at the index we got above
            chars[index] = password[charAt];
            // Remove the letter from the password so it is not picked again
            password = password.Substring(0, charAt) + password.Substring(charAt + 1);
            // Increase counter
            index++;
        }

        // If generated scramble is the same as the word scramble it again
        if (new string(chars) == word)
        {
            ScramblePassword(new string(chars));
        }
        else
        {
            // Set scramble to the new scramble
            scramble = new string(chars);
        }
    }

This was a good challenge that made me think both in terms of making the code extensible and able to be built upon (setting up a strong foundation) and game design in making the game re-playable and dynamic between runs.

wow, already with a scrambler.
good work.

Privacy & Terms