Пример #1
0
        private void deleteWordButton_Click(object sender, EventArgs e)
        {
            if (selectedWord != null)
            {
                if (MessageBox.Show(
                    "Вы уверены, что хотите удалить понятие " + selectedWord + " из словаря?",
                    "Предупреждение", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    DictionaryWord[] NewDictionaryWords = new DictionaryWord[dictionary.DictionaryWords.Length - 1];

                    int j = 0;

                    for (int i = 0; i < dictionary.DictionaryWords.Length; i++)
                    {
                        if (dictionary.DictionaryWords[i].Word != selectedWord)
                        {
                            NewDictionaryWords[j] = dictionary.DictionaryWords[i];
                            j++;
                        }
                    }

                    dictionary.DictionaryWords = NewDictionaryWords;
                    UpdateUi();

                    selectedWord = null;
                    if (search)
                    {
                        searchButton_Click(sender, e);
                    }
                }
            }
            else
            {
                MessageBox.Show(
                    "Вы не выбрали понятие",
                    "Ошибка", MessageBoxButtons.OK);
            }
        }
Пример #2
0
 public CrosswordWord(global::Crossword.Crossword crossword, DictionaryWord dictionaryWord, CrosswordWordPosition position, bool isResolved)
 {
     this.dictionaryWord = dictionaryWord;
     this.position = position;
     IsResolved = isResolved;
 }
Пример #3
0
 public CrosswordWord(global::Crossword.Crossword crossword, DictionaryWord dictionaryWord, CrosswordWordPosition position)
     : this(crossword, dictionaryWord, position, false)
 {
 }
        private void okButton_Click(object sender, EventArgs e)
        {
            int wordSize = wordTextBox.Text.Length;
            int descriptionSize = descriptionTextBox.Text.Length;
            string newWord = wordTextBox.Text.ToUpper();
            string newDescription = descriptionTextBox.Text;
            if ((wordSize > 15) || (wordSize < 3) || (descriptionSize < 3))
            {
                MessageBox.Show(
                    "Вы неверно заполнили поля с понятием и определением",
                    "Ошибка", MessageBoxButtons.OK);
                DialogResult = DialogResult.None;
            }
            else
            {
                int position = -1;
                for (int i = 0; i < dictionary.DictionaryWords.Length; i++)
                {
                    string word = dictionary.DictionaryWords[i].Word;
                    if (word != selectedWord.ToUpper())
                    {
                        if (word == newWord)
                        {
                            state = State.Error;
                            MessageBox.Show(
                            "Понятие дублирует уже существующее",
                            "Ошибка", MessageBoxButtons.OK);
                            DialogResult = DialogResult.None;
                            return;
                        }
                    }
                    else
                    {
                        position = i;
                    }
                }

                if (state == State.Normal)
                {
                    if (position > -1)
                    {
                        dictionary.DictionaryWords[position].Word = newWord;
                        dictionary.DictionaryWords[position].Description = newDescription;
                    }
                    else
                    {
                        DictionaryWord[] newDictionaryWords = new DictionaryWord[dictionary.DictionaryWords.Length + 1];
                        for (int i = 0; i < newDictionaryWords.Length - 1; i++)
                        {
                            newDictionaryWords[i] = dictionary.DictionaryWords[i];
                        }
                        newDictionaryWords[newDictionaryWords.Length - 1] = new DictionaryWord(newWord + " " + newDescription);
                        dictionary.DictionaryWords = newDictionaryWords;
                    }
                }
            }

            state = State.Normal;
        }
Пример #5
0
        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;
        }
Пример #6
0
        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;
        }
Пример #7
0
        public PreviewCrosswordWord GetBestHighlight(DictionaryWord dictionaryWord, int x, int y,
            Orientation preferedOrientation)
        {
            var highlights = GetHighlights(dictionaryWord, x, y);
            if (highlights.Count == 0)
            {
                return null;
            }

            foreach (var previewCrosswordWord in highlights)
            {
                if (previewCrosswordWord.Position.Orientation == preferedOrientation)
                {
                    return previewCrosswordWord;
                }
            }

            return crosswordWords.Count > 0 ? highlights[0] : null;
        }