Auto Search Word Generator

In this tutorial we will create a game in C# called Auto Search Word Generator. This game creates a way of searching the word in the display letters in the form. And this game has a features to add, remove, generate, and show the answer of the list of words given or added by the user. Each word will be automatically generate and mix in the random letters and you will find out if what word will you want it to search and it will automatically show the exact word that you give. I will show you the sample code and images below.

Sample Code

Generating Script
  1. function generate(Words)
  2. {
  3.     gridlength := maxlength(listofwords);
  4.     while (successful)
  5.     {
  6.         notfound := false;
  7.         foreach (word in list)
  8.         {
  9.             word->Location := Calculate(wordsplaced, word);
  10.             if (Location == null)
  11.             {
  12.                 notfound := true;
  13.                 break;
  14.             }
  15.             if (!notfound)
  16.             {
  17.                 return FormGrid(words, locations);
  18.             }
  19.             else
  20.             {
  21.                 gridlength++;
  22.             }
  23.         }
  24.     }
  25. }
And for the Random Code
  1. private Letter[] Next(Letter[][] letters, string word, int length)
  2. {
  3.     List<Point> all = new List<Point>(AllPoints(length));
  4.     while (all.Count > 0)
  5.     {
  6.         int index = rand.Next(0, all.Count);
  7.         List<Direction> dirs = new List<Direction>(AllDirections());
  8.         while (dirs.Count > 0)
  9.         {
  10.             int index2 = rand.Next(0, dirs.Count);
  11.             Direction current = dirs[index2];
  12.             Letter[] c = Construct(all[index], current, word, length);
  13.             bool legal = true;
  14.             for (int i = 0; i < c.Length; i++)
  15.             {
  16.                 if (c[i].X < 0 || c[i].X >= length || c[i].Y < 0 || c[i].Y >= length)
  17.                 {
  18.                     legal = false;
  19.                     break;
  20.                 }
  21.                 else
  22.                 {
  23.                     for (int j = 0; j < letters.Length; j++)
  24.                     {
  25.                         Point[] pts = letters[j].Select<Letter, Point>(t => new Point(t.X, t.Y)).ToArray();
  26.                         int _index2 = pts.ToList().FindIndex(t => t.X == c[i].X && t.Y == c[i].Y);
  27.                         if (_index2 != -1)
  28.                             if (c[i]._Letter != letters[j][_index2]._Letter)
  29.                                 legal = false;
  30.                     }
  31.                 }
  32.             }
  33.             if (legal)
  34.                 return c;
  35.             dirs.RemoveAt(index2);
  36.         }
  37.         all.RemoveAt(index);
  38.     }
  39.     return null;
  40. }
result If you want to run this game in .exe application you must build and debug it again using Visual Studio. Don't forget to Like and Share. Enjoy Coding.

Add new comment