Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C#: Hello, I need some help making a scrambler for a word scramble game I am mak

ID: 3716879 • Letter: C

Question

C#: Hello, I need some help making a scrambler for a word scramble game I am making. I am really confused on how to even make a scrambler but I think I need to make it with an array. I need this scrambler to scramble the words in a certain level (like easy, medium, and hard) and output them scrambled so the player has to unscramble it and then check to see if they got it correct. I want this game to be a windows form but I mostly care about having a working scrambler as I can make it a windows form later. Here are a couple of words I am thinking about having in the game but I will add more after I figure out how to do the scramble and check to see if the user got it right.

Easy words
cat
dog
boy
cup
car
kid
toy
sun

Medium words
nose
grow
bird
game
hard
jump
sell
gift
more
fall


Hard words
truck
train
craft
apple
start
paint

Thank you for any help you can provide on this. This is the first game type program I am attempting.

Explanation / Answer

ScreenShot

--------------------------------------------------------------------------------------------------------------------------------------

Program

//Import package
using System;
//Scrample word project
namespace ScrampleWords
{
    //Converter class has a function to scrample the entering string
    class converter
    {
        //Convertor function
        public string ScrambleWord(string word)
        {
            //Array to take each charcters in the string to scramble
            char[] scramble = new char[word.Length];
            //Randomly select the character
            Random rand = new Random(10000);
            //Variable to get the scramble array index
            int index = 0;
            //Loop to check until entire word
            while (word.Length > 0)
            { // Get a random number between 0 and the length of the word.
                int next = rand.Next(0, word.Length - 1); // Take the character from the random position and add to our char array.
                scramble[index] = word[next];                // Remove the character from the word.
                //Substring method in string to generate next word
                word = word.Substring(0, next) + word.Substring(next + 1);
                ++index;
            }
            //Return the scrambled word
            return new String(scramble);
        }
    }
    //Main class
    class Program
    {
        //Main method
        static void Main(string[] args)
        {
            //String arrays to store original words and scrambled words
            string[] easy = { "cat", "dog", "boy", "cup", "car", "kid", "toy", "sun" };
            string[] easyScrample = new string[easy.Length];
            //Object creation
            var c = new converter();
            //Call converter class method to scramble each word in the array and store into another array
            for(int i = 0; i < easy.Length; i++)
            {
                easyScrample[i] = c.ScrambleWord(easy[i]);
            }
            //Display original array
            Console.WriteLine("Original array:");
            Console.Write("[");
            for (int i = 0; i < easy.Length; i++)
            {
                Console.Write(easy[i]+"   ");
            }
            Console.Write("] ");
            //Display scrambled array
            Console.WriteLine("Scrampled word array:");
            Console.Write("[");
            for (int i = 0; i < easyScrample.Length; i++)
            {
                Console.Write(easyScrample[i]+"   ");
            }
            Console.Write("] ");
        }
    }
}

--------------------------------------------------------------------------------------

Note

I hope this scrambleWord function will help you to your project.

If you need clarification,let me know