puzzle
i want to create word search puzzle like this
http://www.learncalifornia.org/GoDocUserFiles/2313.ws.jpg
i need to hide the words in a 15 x 15 square letter matrix.
Words can be in any of 8 directions in a combination of the following: horizontal, vertical, diagonal, forwards, and backwards.
The application should display an answer key.
how to ceate letter matrix and insert words randomly in it using c#?
thanks in advance.
Kirtan PatelPosted Dec 5, 2009, 1:50 PM
Here i CODED the Random Matrix Logic
static void Main(string[] args)
{
Random r = new Random();
List<string> list = new List<string>();
List<string> answerkeys = new List<string>();
List<string> FinalQuestionList = new List<string>();
//Add Blank Items to List
for (int i = 0; i < 15; i++)
{
list.Add("");
}
for(int i=0;i<4;i++)
{
Console.WriteLine("Enter Word you Want to Hide in Matrix :");
list[r.Next(0,15)]= Console.ReadLine();
}
answerkeys = list;
Console.WriteLine("**********************Question Matrix ************************");
foreach(string str in list)
{
string CompleteWord = str;
if (CompleteWord.Length < 15)
{
//Add Random Characters in String
while (CompleteWord.Length != 15)
{
CompleteWord += ((char)r.Next(65, 90)).ToString();
}
FinalQuestionList.Add(CompleteWord);
}
}
//Show The Matrix
foreach (string str in FinalQuestionList)
{
char[] wordSplit = str.ToCharArray();
for (int i = 0; i < wordSplit.Length - 1; i++)
{
Console.Write(wordSplit[i].ToString() + " ");
}
Console.Write("\n");
}
//Print Answers
Console.WriteLine("\n\n*****************************************************\n\n\n");
Console.WriteLine("Answers to Matrix ");
foreach (string ans in answerkeys)
{
if (ans.Length < 2)
{
Console.WriteLine(ans);
}
}
Console.ReadLine();
}
You can Make this Program More Complex as per your need I have Given you Just Idea How you Do it :)