public CrosswordWord(global::Crossword.Crossword crossword, PreviewCrosswordWord previewCrosswordWord) : this(crossword, previewCrosswordWord.dictionaryWord, previewCrosswordWord.position, previewCrosswordWord.isResolved) { }
public List<PreviewCrosswordWord> GetPreviewsPositions(DictionaryWord dictionaryWord) { if (crosswordWords == null || crosswordWords.Count == 0) { return null; } var result = new List<PreviewCrosswordWord>(); for (var i = 0; i < Width; i++) { for (var j = 0; j < Height; j++) { var previewWord = new PreviewCrosswordWord(dictionaryWord, new CrosswordWordPosition(i, j, Orientation.Vertical)); if (CheckIfPreviewWordMatches(previewWord)) { result.Add(previewWord); } previewWord = new PreviewCrosswordWord(dictionaryWord, new CrosswordWordPosition(i, j, Orientation.Horizontal)); if (CheckIfPreviewWordMatches(previewWord)) { result.Add(previewWord); } } } return result; }
private bool CheckIfPreviewWordMatches(PreviewCrosswordWord previewWord) { var countOfIntersections = 0; var goodWord = true; if (!IsWordInBorders(previewWord)) { return false; } foreach (var crosswordWord in CrosswordWords) { var intersectionType = crosswordWord.GetIntersectionType(previewWord); if (intersectionType == CrosswordWord.IntersectionType.WrongIntersection) { goodWord = false; break; } if (intersectionType == CrosswordWord.IntersectionType.CorrectIntersection) { countOfIntersections++; } } if (countOfIntersections == 0) { goodWord = false; } return goodWord; }
public List<PreviewCrosswordWord> GetHighlights(DictionaryWord dictionaryWord, int x, int y) { var result = new List<PreviewCrosswordWord>(); var previewWords = GetPreviewsPositions(dictionaryWord); if (previewWords == null) { var horizontalHighlight = new PreviewCrosswordWord(dictionaryWord, new CrosswordWordPosition(x, y, Orientation.Horizontal)); var verticalHighlight = new PreviewCrosswordWord(dictionaryWord, new CrosswordWordPosition(x, y, Orientation.Vertical)); if (IsWordInBorders(horizontalHighlight)) { result.Add(horizontalHighlight); } if (IsWordInBorders(verticalHighlight)) { result.Add(verticalHighlight); } return result; } foreach (var previewCrosswordWord in previewWords) { if (x == previewCrosswordWord.Position.X && y == previewCrosswordWord.Position.Y) { result.Add(new PreviewCrosswordWord(dictionaryWord, new CrosswordWordPosition(x, y, previewCrosswordWord.Position.Orientation))); } } return result; }