public void RevealWord(string[,] fieldOfCodedWords, List <string> guessedWords) { Console.Clear(); var lineInArray = string.Empty; int startIndex = 0; for (int row = 0; row < fieldOfCodedWords.GetLength(0); row++) { lineInArray = arrayOperator.ExtractRowFromMatrix(fieldOfCodedWords, row); for (int wordCount = 0; wordCount < guessedWords.Count; wordCount++) { if (Regex.Match(lineInArray, guessedWords[wordCount]).Success) { startIndex = Regex.Match(lineInArray, guessedWords[wordCount]).Index; for (int nextLetter = 0; nextLetter < guessedWords[wordCount].Length; nextLetter++) { coordinates.Add(new int[] { row, startIndex + nextLetter }); } } } } for (int col = 0; col < fieldOfCodedWords.GetLength(1); col++) { lineInArray = arrayOperator.ExtractColFromMatrix(fieldOfCodedWords, col); for (int wordCount = 0; wordCount < guessedWords.Count; wordCount++) { if (Regex.Match(lineInArray, guessedWords[wordCount]).Success) { startIndex = Regex.Match(lineInArray, guessedWords[wordCount]).Index; for (int nextLetter = 0; nextLetter < guessedWords[wordCount].Length; nextLetter++) { coordinates.Add(new int[] { startIndex + nextLetter, col }); } } } } var isMatch = false; for (int row = 0; row < fieldOfCodedWords.GetLength(0); row++) { for (int col = 0; col < fieldOfCodedWords.GetLength(1); col++) { for (int indexOfCoordinatesOfGuessWord = 0; indexOfCoordinatesOfGuessWord < coordinates.Count; indexOfCoordinatesOfGuessWord++) { if (coordinates[indexOfCoordinatesOfGuessWord][0] == row && coordinates[indexOfCoordinatesOfGuessWord][1] == col) { isMatch = true; } else { continue; } } if (isMatch) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("{0} ", fieldOfCodedWords[row, col]); isMatch = false; } else { Console.ResetColor(); Console.Write("{0} ", fieldOfCodedWords[row, col]); } } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("You've managed to guess {0} words", guessedWords.Count); coordinates.Clear(); }
public void GenerateCrossword() { var colFromMatrix = string.Empty; var rowFromMatrix = string.Empty; var listFromSpecificPattern = new List <string>(); var frameOfAPotentialWord = string.Empty; var colOutsideRange = 1; var indexCounter = 0; var adaptatedIndex = 0; var randomWord = string.Empty; for (int row = 1; row < crossword.GetLength(0); row++) { for (int col = colOutsideRange; col < crossword.GetLength(1); col++) { colFromMatrix = arrayOperator.ExtractColFromMatrix(crossword, col); frameOfAPotentialWord = wordsOperator.ExtractFrameOfAPotentialWord(colFromMatrix); if (frameOfAPotentialWord == string.Empty) { break; } if (!frameOfAPotentialWord.Contains(GlobalConstants.SpecificSymbolToReplaceNull)) { while (!wordVerificator.ContainsWordWithSpecificBeginning(listOfAllWords, frameOfAPotentialWord)) { if (frameOfAPotentialWord.Length > 1) { frameOfAPotentialWord = frameOfAPotentialWord.Substring(1); indexCounter++; } else { break; } } adaptatedIndex = indexCounter; listFromSpecificPattern = wordsOperator.GetListOfAllWordsFromASpecifiedBeginning(frameOfAPotentialWord); randomWord = randomGenerator.GenerateRandomWord(listFromSpecificPattern); wordsOperator.CollectedWordsFromCrossword.Add(randomWord); crossword = matrixWriter.WriteOnCol(crossword, randomWord, adaptatedIndex, col); indexCounter = 0; Console.Clear(); painter.PaintMatrix(crossword, col, adaptatedIndex); break; } else { while (!wordVerificator.ContainsWordWithSpecificPositionOfCharacters(listOfAllWords, frameOfAPotentialWord)) { if (frameOfAPotentialWord.Length > 1) { frameOfAPotentialWord = frameOfAPotentialWord.Substring(1); indexCounter++; } else { break; } } adaptatedIndex = indexCounter; listFromSpecificPattern = wordsOperator.GetListOfAllWordsFromASpecifiedPattern(frameOfAPotentialWord); randomWord = randomGenerator.GenerateRandomWord(listFromSpecificPattern); wordsOperator.CollectedWordsFromCrossword.Add(randomWord); crossword = matrixWriter.WriteOnCol(crossword, randomWord, adaptatedIndex, col); indexCounter = 0; Console.Clear(); painter.PaintMatrix(crossword, col, adaptatedIndex); break; } } //row begins here frameOfAPotentialWord = string.Empty; rowFromMatrix = arrayOperator.ExtractRowFromMatrix(crossword, row); frameOfAPotentialWord = wordsOperator.ExtractFrameOfAPotentialWord(rowFromMatrix); indexCounter = 0; if (frameOfAPotentialWord == string.Empty) { break; } //fillerOfMatrix if (!frameOfAPotentialWord.Contains(GlobalConstants.SpecificSymbolToReplaceNull)) { while (!wordVerificator.ContainsWordWithSpecificBeginning(listOfAllWords, frameOfAPotentialWord)) { if (frameOfAPotentialWord.Length > 1) { frameOfAPotentialWord = frameOfAPotentialWord.Substring(1); indexCounter++; } else { continue; } } adaptatedIndex = indexCounter; listFromSpecificPattern = wordsOperator.GetListOfAllWordsFromASpecifiedBeginning(frameOfAPotentialWord); randomWord = randomGenerator.GenerateRandomWord(listFromSpecificPattern); wordsOperator.CollectedWordsFromCrossword.Add(randomWord); crossword = matrixWriter.WriteOnRow(crossword, randomWord, row, adaptatedIndex); indexCounter = 0; colOutsideRange++; Console.Clear(); painter.PaintMatrix(crossword, row, adaptatedIndex); continue; } else { while (!wordVerificator.ContainsWordWithSpecificPositionOfCharacters(listOfAllWords, frameOfAPotentialWord)) { if (frameOfAPotentialWord.Length > 1) { frameOfAPotentialWord = frameOfAPotentialWord.Substring(1); indexCounter++; } else { throw new FormatException("No such word exists in the given database."); } } adaptatedIndex = indexCounter; listFromSpecificPattern = wordsOperator.GetListOfAllWordsFromASpecifiedPattern(frameOfAPotentialWord); randomWord = randomGenerator.GenerateRandomWord(listFromSpecificPattern); wordsOperator.CollectedWordsFromCrossword.Add(randomWord); crossword = matrixWriter.WriteOnRow(crossword, randomWord, row, adaptatedIndex); indexCounter = 0; colOutsideRange++; Console.Clear(); painter.PaintMatrix(crossword, row, adaptatedIndex); continue; } } painter.ListAllTheWords(wordsOperator); Thread.Sleep(300); Console.Clear(); painter.PaintMatrixWithSymbol(crossword, GlobalConstants.SymbolToHideNumbersWith); crosswordSolver.SolveCrossword(crossword, wordsOperator); }