Exemplo n.º 1
0
        private void TextBox_MouseEnter(object sender, MouseEventArgs e)
        {
            if (ChangeLevelButton.IsEnabled && checkBoxHelp.IsChecked == true)
            {
                TextBox textBox = sender as TextBox;

                NumberColorsOnEnter numberColorsOnEnter = new NumberColorsOnEnter(textBoxes, textBox, sudokuMap);
            }
        }
Exemplo n.º 2
0
        private void TextBox_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            if (ChangeLevelButton.IsEnabled)
            {
                TextBox textBox = sender as TextBox;

                MapCleaner.Clean(textBoxes, textBox);


                if (e.Key != Key.Right && e.Key != Key.Left &&
                    e.Key != Key.Down && e.Key != Key.Up && checkBoxHelp.IsChecked == true)
                {
                    bool corect = false;

                    for (int i = 0; i < textBoxes.GetLength(0); i++)
                    {
                        for (int j = 0; j < textBoxes.GetLength(1); j++)
                        {
                            if (textBoxes[i, j].Text == textBox.Text)
                            {
                                if (textBoxes[i, j].Text != sudokuMap[i, j].ToString() && textBoxes[i, j].Text != "")
                                {
                                    Dispatcher.Invoke(() => textBoxes[i, j].Background = Brushes.Crimson);
                                    Dispatcher.Invoke(() => textBoxes[i, j].Foreground = Brushes.White);
                                    Dispatcher.Invoke(() => textBoxes[i, j].FontWeight = FontWeights.ExtraBlack);
                                }

                                else if (textBoxes[i, j].Text == sudokuMap[i, j].ToString())
                                {
                                    Dispatcher.Invoke(() => textBoxes[i, j].Background = Brushes.SeaGreen);
                                    Dispatcher.Invoke(() => textBoxes[i, j].Foreground = Brushes.White);
                                    Dispatcher.Invoke(() => textBoxes[i, j].FontWeight = FontWeights.ExtraBlack);
                                    corect = true;
                                }



                                if (textBoxes[i, j] == textBox)
                                {
                                    RowAndColumnColourHolder rowAndColumnColourHolder = new RowAndColumnColourHolder();

                                    Animations.FullLine fullLine = new Animations.FullLine();

                                    if (RowsOrColumnIsFull.CheckForVerticalMach(textBoxes, sudokuMap, j, textBox) && RowsOrColumnIsFull.CheckForHorizontalMach(textBoxes, sudokuMap, i, textBox) && textBoxes[i, j].IsReadOnly == false)
                                    {
                                        textBoxes[i, j].IsReadOnly = true;

                                        rowAndColumnColourHolder.AddColumn(textBoxes, j);
                                        rowAndColumnColourHolder.AddRow(textBoxes, i);

                                        Parallel.Invoke(() =>
                                        {
                                            fullLine.AnimateVertical(textBoxes, j, rowAndColumnColourHolder.GetColumn());
                                        }, () =>
                                        {
                                            fullLine.AnimateHorizontal(textBoxes, i, rowAndColumnColourHolder.GetRow());
                                        });
                                    }
                                    if (RowsOrColumnIsFull.CheckForVerticalMach(textBoxes, sudokuMap, j, textBox) && textBoxes[i, j].IsReadOnly == false)
                                    {
                                        textBoxes[i, j].IsReadOnly = true;
                                        rowAndColumnColourHolder.AddColumn(textBoxes, j);
                                        Dispatcher.Invoke(() => fullLine.AnimateVertical(textBoxes, j, rowAndColumnColourHolder.GetColumn()));
                                    }
                                    else if (RowsOrColumnIsFull.CheckForHorizontalMach(textBoxes, sudokuMap, i, textBox) && textBoxes[i, j].IsReadOnly == false)
                                    {
                                        textBoxes[i, j].IsReadOnly = true;
                                        rowAndColumnColourHolder.AddRow(textBoxes, i);
                                        fullLine.AnimateHorizontal(textBoxes, i, rowAndColumnColourHolder.GetRow());
                                    }
                                }
                            }
                            if (corect)
                            {
                                textBoxes[i, j].IsReadOnly = true;
                            }

                            corect = false;
                        }
                    }

                    Animations.CountMoves countMoves = new Animations.CountMoves();

                    if (textBox.IsReadOnly == true && TextBoxReadOnly == false)
                    {
                        LabelPositiv++;
                        TextBoxReadOnly = true;
                        countMoves.Animate(labelPositiveCount, LabelPositiv);
                    }
                    else if (textBox.IsReadOnly == false && textBox.Text != "")
                    {
                        LabelNegativ++;
                        countMoves.Animate(labelNegativeCount, LabelNegativ);
                    }
                }
                else
                {
                    KeyPressed = true;

                    Animations.AnimateCellClick animateCellClick = new Animations.AnimateCellClick();

                    animateCellClick.AnimateKeyUp(ChangeLevelButton.IsEnabled, sender, textBoxes);

                    KeyPressed = false;

                    if (checkBoxHelp.IsChecked == true)
                    {
                        NumberColorsOnEnter numberColorsOnEnter = new NumberColorsOnEnter(textBoxes, textBox, sudokuMap);
                    }
                }
            }
        }