Пример #1
0
        private bool CheckPuzzle(bool resetOnOrror)
        {
            if (InvokeRequired)
            {
                MethodInvoker del = delegate { CheckPuzzle(resetOnOrror); };
                Invoke(del);
                return(true);
            }

            if (_puzzleBoard.IsWrong())
            {
                _errorCounter++;
                _txtErrorCount.Text = _errorCounter.ToString();
                if (resetOnOrror)
                {
                    _puzzleBoard.Reset();
                }
                else
                {
                    _puzzleBoard.Undo();
                }

                if (!_simulationRunsInBackground && _cbxAutoRefreshPlayground.Checked)
                {
                    RefreshPlayGround();
                    RecreateCells();
                }
            }
            else if (_puzzleBoard.IsComplete())
            {
                if (_simulationRunsInBackground || _timer.Enabled)
                {
                    _timer.Enabled = false;
                    _cancellationTokenSource.Cancel();
                    _simulationRunsInBackground = false;
                }

                _cbxRunInterations.Checked = false;
                MessageBox.Show("Puzzle solved!!!", "Robot");
                return(false);
            }
            return(true);
        }