{"id":482,"date":"2010-01-12T11:35:11","date_gmt":"2010-01-12T11:35:11","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=482"},"modified":"2010-01-15T11:43:48","modified_gmt":"2010-01-15T11:43:48","slug":"wordsearch-c-word-class","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2010\/01\/12\/wordsearch-c-word-class\/","title":{"rendered":"Wordsearch &#8211; c# Grid class"},"content":{"rendered":"<p>When coding in <a href=\"http:\/\/msdn.microsoft.com\/en-us\/vcsharp\/default.aspx\">c#\/csharp<\/a>, I use <a href=\"http:\/\/monodevelop.com\/\">monodevelop<\/a>. Here is the wordsearch base Grid class in c#, I am coding in different languages just for fun as such, but here is the main idea for the <a href=\"http:\/\/www.codingfriends.com\/index.php\/projects\/word-search\">wordsearch<\/a>.  I have already done a basic version in <a href=\"http:\/\/php.net\/\">php<\/a> which is at the present state in creating a <a href=\"http:\/\/www.codingfriends.com\/index.php\/2010\/01\/11\/wordsearch-php-the-words-inserted-into-the-grid\/\">grid<\/a> (but without any intersection of words with others).   But here is the <a href=\"http:\/\/www.codingfriends.com\/index.php\/2010\/01\/04\/wordsearch-php-grid-class\/\">Grid<\/a> class in php, and below is the similar setup in csharp.<\/p>\n<p>The main class, is where the application executes from, it is very similar to c++ in that there is a main function<\/p>\n<pre lang=\"csharp\">\r\npublic static void Main(string[] args)\r\n<\/pre>\n<p>which takes the string[] args as a parameter, which is what is passed in on the command line.<\/p>\n<p>Anyway, here is the code.. I have added in some comments to what the code is doing.<\/p>\n<pre lang=\"csharp\">\r\nusing System;\r\n\r\nnamespace wordsearchcsharp\r\n{\r\n\tclass Grid {\r\n\t\tprotected int _size = 0;\r\n\t\tprotected char[][] _grid;\r\n\t\t\r\n\t\t\/\/ the \": this(11)\" means call the Grid(int size) constructor with 11 as a parameter\r\n\t\tpublic Grid() : this(11)\r\n\t\t{\r\n\t\t\t\/\/ default size of a grid = 11\r\n\t\t}\r\n\t\t\r\n\t\tpublic Grid(int size)\r\n\t\t{\r\n\t\t\tthis._size = size;\r\n\t\t\t\/\/ create a new row (Y direction)\r\n\t\t\tthis._grid = new char[this._size][];\r\n\t\t\tfor (int i =0; i < this._size; i++)\r\n\t\t\t{\r\n\t\t\t\t\/\/ create new X direction row.\r\n\t\t\t\tthis._grid[i] = createGridRow();\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t\/\/ createGridRow, this can be inherited and thus altered to create any type of character in the grid \r\n\t\tpublic virtual char[] createGridRow()\r\n\t\t{\r\n\t\t\t\/\/ need to insert a good seed into the random generator.. else same characters\r\n\t\t\tRandom random = new Random((int)DateTime.Now.Ticks);\r\n\r\n\t\t\t\/\/ create a new row (X direction) and place characters into it.\r\n\t\t\tchar[] grid_insert = new char[this._size];\r\n\t\t\tfor (int i = 0; i < this._size; i++)\r\n\t\t\t{\r\n\t\t\t\t\/\/ 0 - 25 = alphabet, and also +97 is the ascii start for the character 'a'\r\n\t\t\t\tgrid_insert[i] = (char)(random.Next(0,25)+97);\r\n\t\t\t}\r\n\t\t\treturn grid_insert;\r\n\t\t}\r\n\t\t\r\n\t\t\/\/ printOutGrid, will print out the grid created above.\r\n\t\t\/\/ i = Y direction, and j = X direction.\r\n\t\tpublic void printOutGrid()\r\n\t\t{\r\n\t\t\tConsole.WriteLine(\"The Grid\");\r\n\t\t\tfor (int i = 0; i < this._size; i++)\r\n\t\t\t{\r\n\t\t\t\tConsole.Write(i + \" ..\");\r\n\t\t\t\tfor (int j = 0; j < this._size; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tConsole.Write(j + \" = \" + this._grid[i][j]);\r\n\t\t\t\t}\r\n\t\t\t\tConsole.WriteLine(\"\");\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic int returnSize()\r\n\t\t{\r\n\t\t\treturn this._size;\r\n\t\t}\r\n\r\n\t\t\/\/ insert a character into the grid at position X, Y and the character \r\n\t\tpublic void insertCharIntoGrid(int pX, int pY, char character)\r\n\t\t{\r\n\t\t\tthis._grid[pY][pX] = character;\r\n\t\t}\r\n\t\t\r\n\t\t\/\/  return the grid reference \r\n\t\tpublic char[][] returnGrid()\r\n\t\t{\r\n\t\t\treturn this._grid;\r\n\t\t}\r\n\t\r\n\t}\r\n\t\r\n\tclass MainClass\r\n\t{\r\n\t\tpublic static void Main(string[] args)\r\n\t\t{\r\n\t\t\tGrid grid = new Grid();\r\n\t\t\tgrid.printOutGrid();\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>And here is the output.<\/p>\n<pre lang=\"bash\">\r\nThe Grid\r\n0 ..0 = m1 = y2 = p3 = d4 = d5 = y6 = g7 = p8 = m9 = i10 = t\r\n1 ..0 = k1 = c2 = y3 = n4 = i5 = m6 = q7 = f8 = g9 = p10 = j\r\n2 ..0 = o1 = r2 = v3 = q4 = a5 = i6 = y7 = h8 = k9 = y10 = c\r\n3 ..0 = h1 = u2 = f3 = s4 = v5 = r6 = p7 = g8 = h9 = j10 = b\r\n4 ..0 = n1 = j2 = y3 = u4 = v5 = q6 = n7 = b8 = y9 = w10 = g\r\n5 ..0 = g1 = m2 = i3 = x4 = r5 = a6 = e7 = a8 = w9 = i10 = f\r\n6 ..0 = m1 = c2 = c3 = a4 = r5 = y6 = c7 = v8 = o9 = u10 = k\r\n7 ..0 = f1 = e2 = k3 = c4 = n5 = j6 = s7 = t8 = m9 = g10 = j\r\n8 ..0 = l1 = t2 = f3 = e4 = n5 = i6 = q7 = p8 = e9 = t10 = p\r\n9 ..0 = e1 = w2 = n3 = h4 = j5 = r6 = h7 = o8 = b9 = e10 = o\r\n10 ..0 = y1 = x2 = u3 = j4 = n5 = g6 = n7 = h8 = m9 = t10 = a\r\n<\/pre>\n<p>I use linux and thus mono is my csharp virtual machine setup, but here is a output of the file command in linux which tells me that the wordsearchcsharp.exe if a mono assembly and thus if you .\/wordsearchcsharp.exe will goto the mono virtual machine.. it will link\/expand to mono wordsearchcsharp.exe on the command line.<\/p>\n<pre lang=\"bash\">\r\nfile wordsearchcsharp.exe\r\nwordsearchcsharp.exe: PE32 executable for MS Windows (console) Intel 80386 32-bit Mono\/.Net assembly\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When coding in c#\/csharp, I use monodevelop. Here is the wordsearch base Grid class in c#, I am coding in different languages just for fun as such, but here is the main idea for the wordsearch. I have already done a basic version in php which is at the present state in creating a grid &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2010\/01\/12\/wordsearch-c-word-class\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Wordsearch &#8211; c# Grid class<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[45],"class_list":["post-482","post","type-post","status-publish","format-standard","hentry","category-c_sharp","tag-wordsearch"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=482"}],"version-history":[{"count":8,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/482\/revisions"}],"predecessor-version":[{"id":521,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/482\/revisions\/521"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}