public void OnWordSelected(CrosswordWord word) { if (_wordSelectionAction != null) { _wordSelectionAction.Invoke(word); } }
public IntersectionType GetIntersectionType(CrosswordWord other) { if (other.Word.Equals(Word)) { return IntersectionType.WrongIntersection; } int Ax, Ay, Bx, By, Cx, Cy, Dx, Dy; PositionAtIndex(0, out Ax, out Ay); PositionAtIndex(Word.Length - 1, out Bx, out By); other.PositionAtIndex(0, out Cx, out Cy); other.PositionAtIndex(other.Word.Length - 1, out Dx, out Dy); Ax--; Ay--; Bx++; By++; if (!(Intersect(Ax, Bx, Cx, Dx) && Intersect(Ay, By, Cy, Dy))) { return IntersectionType.NoIntersection; } // Rectangles are intersected. If words not then WRONG if (!(Intersect(Ax + 1, Bx - 1, Cx, Dx) && Intersect(Ay + 1, By - 1, Cy, Dy))) { return IntersectionType.WrongIntersection; } for (int i = 0; i < Word.Length; i++) { for (int j = 0; j < other.Word.Length; j++) { int x1, y1, x2, y2; PositionAtIndex(i, out x1, out y1); other.PositionAtIndex(j, out x2, out y2); if (x1 == x2 && y1 == y2) { if (other.Position.Orientation == Position.Orientation) { return IntersectionType.WrongIntersection; } if (!Word[i].Equals(other.Word[j])) { return IntersectionType.WrongIntersection; } return IntersectionType.CorrectIntersection; } } } //for (int i = 0; i < Word.Length; i++) //{ // for (int j = 0; j < other.Word.Length; j++) // { // int x1, y1, x2, y2; // PositionAtIndex(i, out x1, out y1); // other.PositionAtIndex(j, out x2, out y2); // if (Math.Abs(x2 - x1) + Math.Abs(y2 - y1) == 1) // { // return IntersectionType.WrongIntersection; // } // } //} return IntersectionType.NoIntersection; }
internal int Generate(Crossword crossword, Dictionary dictionary) { if (dictionary.DictionaryWords.Length == 0) { return -1; } int blankIterations = 0; int wordsHaveBeenAdded = 0; dictionary.Sort(new DictionaryWordComparator(DictionaryWordComparator.SortDirection.Descending, DictionaryWordComparator.SortBy.LetterCount)); int iterationNumber = 0; while (blankIterations < 100) { iterationNumber++; var dictionaryWord = dictionary.GetRandomDictionaryWord(iterationNumber < 10 ? 0.3 : 1); var positions = crossword.GetPreviewsPositions(dictionaryWord); if (positions != null) { if (positions.Count == 0) { blankIterations++; continue; } var position = positions[random.Next(0, positions.Count)]; // range: [0; positions.Count - 1] var crosswordWord = new CrosswordWord(crossword, dictionaryWord, position.Position, false); crossword.AddWord(crosswordWord); wordsHaveBeenAdded = 1; } else { Orientation orientation = random.Next(2) > 0 ? Orientation.Horizontal : Orientation.Vertical; crossword.AddWord(new CrosswordWord(crossword, dictionaryWord, new CrosswordWordPosition(0, 0, orientation), false)); wordsHaveBeenAdded = 1; } blankIterations = 0; } return wordsHaveBeenAdded; }
public void OnWordDeleted(CrosswordWord crosswordWord) { if (_wordDeletedAction != null) { _wordDeletedAction.Invoke(crosswordWord); } }
private bool IsWordInBorders(CrosswordWord word) { int x; int y; word.PositionAtIndex(word.Word.Length - 1, out x, out y); return x < Width && y < Height; }
public void DeleteWord(CrosswordWord crosswordWord) { CrosswordWord removedWord = null; for (int i = 0; i < crosswordWords.Count; i++) { if (crosswordWords[i].Word.Equals(crosswordWord.Word)) { removedWord = crosswordWords[i]; break; } } if (removedWord != null) { crosswordWords.Remove(removedWord); } if (_crosswordStateListener != null) { _crosswordStateListener.OnWordDeleted(removedWord); } }
public void AddWord(CrosswordWord crosswordWord) { if (typeof(PreviewCrosswordWord) == crosswordWord.GetType()) { throw new InvalidOperationException("You should not put PreviewWord here"); } crosswordWords.Add(crosswordWord); if (_crosswordStateListener != null) { _crosswordStateListener.OnWordAdded(crosswordWord); } UpdateHelpers(); }