Я попытался скомпилировать код, но слова не вводятся в массив, также мог бы кто-нибудь прокомментировать код для направления
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Wordsearch { class Program { struct wordPosition { public string word; public int column; public int row; public string direction; /// <summary> /// This is the struct that places the word in its position /// /// <param name="pNumberOfColumns" /> /// <param name="pNumberOfRows" /> static void Board(int pNumberOfColumns, int pNumberOfRows) { string[,] Board = new string[pNumberOfRows, pNumberOfColumns]; // this string is created for the random letter generator, this will be included into the array string[] alphabet = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; Random rng = new Random(); // this allows the letters to be placed randomly, this can be any letter Console.Clear(); Console.Write(" "); Console.ForegroundColor = ConsoleColor.Yellow; for (int i = 0; i < pNumberOfColumns; i++) { Console.Write(i + " "); } Console.WriteLine(""); Console.ForegroundColor = ConsoleColor.White; for (int i = 0; i < pNumberOfRows; i++) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(i + " "); Console.ForegroundColor = ConsoleColor.White; for (int j = 0; j < pNumberOfColumns; j++) { int randomNumber = rng.Next(0, 26); Board[i, j] = alphabet[randomNumber]; Console.Write(" "); Console.Write(Board[i, j]); } Console.WriteLine(); } } /// <summary> /// These lines of code does a list of all the words in the file right below the wordsearch. /// /// <param name="pWords" /> static void wordsearchList(wordPosition[] pWords) { for (int i = 0; i < pWords.Length; i++) { Console.WriteLine(pWords[i].word); } } /// <summary> /// /// /// <param name="wordIndex" /> /// <param name="board" /> /// <param name="pWords" /> static void GridWithWords(int wordIndex, ref char[,] board, wordPosition[] pWords) { //populating the grid with the correct words. switch (pWords[wordIndex].direction) { case "right": for (int j = 0; j < pWords[wordIndex].word.Length; j++) { board[pWords[wordIndex].row, pWords[wordIndex].column + j] = pWords[wordIndex].word[j]; } break; case "left": for (int j = 0; j < pWords[wordIndex].word.Length; j++) { board[pWords[wordIndex].row, pWords[wordIndex].column - j] = pWords[wordIndex].word[j]; } break; case "up": for (int j = 0; j < pWords[wordIndex].word.Length; j++) { board[pWords[wordIndex].row - j, pWords[wordIndex].column] = pWords[wordIndex].word[j]; } break; case "down": for (int j = 0; j < pWords[wordIndex].word.Length; j++) { board[pWords[wordIndex].row + j, pWords[wordIndex].column] = pWords[wordIndex].word[j]; } break; case "rightup": for (int j = 0; j < pWords[wordIndex].word.Length; j++) { board[pWords[wordIndex].row - j, pWords[wordIndex].column + j] = pWords[wordIndex].word[j]; } break; case "leftup": for (int j = 0; j < pWords[wordIndex].word.Length; j++) { board[pWords[wordIndex].row - j, pWords[wordIndex].column - j] = pWords[wordIndex].word[j]; } break; case "rightdown": for (int j = 0; j < pWords[wordIndex].word.Length; j++) { board[pWords[wordIndex].row + j, pWords[wordIndex].column + j] = pWords[wordIndex].word[j]; } break; case "leftdown": for (int j = 0; j < pWords[wordIndex].word.Length; j++) { board[pWords[wordIndex].row + j, pWords[wordIndex].column - j] = pWords[wordIndex].word[j]; } break; } } /// <summary> /// Loads the text file /// /// <param name="pTextFile" />file to be loaded /// <param name="pWords" />array of wordPositions struct /// <param name="numberOfColumns" /> /// <param name="numberOfRows" /> /// <param name="numberOfWord" /> private static void LoadTextFile(string pTextFile, out wordPosition[] pWords, out int numberOfColumns, out int numberOfRows, out int numberOfWord) { System.IO.StreamReader reader = null; // try to read the file. if there is something wrong with the file we cannot continue // therefore we have a finally block to ensure the file is closed properly // try { reader = new System.IO.StreamReader(pTextFile); string firstLine = reader.ReadLine(); // first line of the file is the column, row and number of words, it is split with a , inbetween string[] firstlineValues = firstLine.Split(','); //this reads the first line of the lines numberOfColumns = int.Parse(firstlineValues[0]); numberOfRows = int.Parse(firstlineValues[1]); numberOfWord = int.Parse(firstlineValues[2]); pWords = new wordPosition[numberOfWord]; for (int wordIndex = 0; wordIndex < numberOfWord; wordIndex++) { string word = reader.ReadLine(); // words are stored as the name, column coordinate of the first letter, row coordinate of the first letter and which direction it is headed string[] wordData = word.Split(','); pWords[wordIndex].word = wordData[0]; pWords[wordIndex].column = int.Parse(wordData[1]); pWords[wordIndex].row = int.Parse(wordData[2]); pWords[wordIndex].direction = wordData[3]; } } finally { if (reader != null) { reader.Close(); } } } static void Main(string[] args) { wordPosition[] word; int column; int row; int words; try { LoadTextFile(args[0], out word, out column, out row, out words); } catch (Exception exception) { Console.WriteLine("Unable to read file " + args[0]); Console.WriteLine(exception.Message); Console.WriteLine("Press any key to exit."); Console.ReadKey(); return; } Board(column, row); wordsearchList(word); Console.ReadKey(); } } } }
Спасибо
Что я уже пробовал:
Я еще ничего не пробовал, хочу увидеть комментарии, прежде чем что-то пробовать
[no name]
"Я еще ничего не пробовал", тогда попробуйте что-нибудь. Может быть, что-то вроде того, чтобы задать вопрос или описать проблему с вашим кодом.