Пример #1
0
        private void Step(int stepCount)
        {
            if (stepCount == 0)
            {
                return;
            }

            UIGameBoard.SuspendLayout();
            UIGameBoard.TurnOffHighlighting();
            int increment = (stepCount > 0) ? -1 : 1;

            while (stepCount != 0)
            {
                stepCount += increment;
                if (increment < 0)  // moving forward
                {
                    PuzzleSolution[CurrentStep++].Apply();
                }
                else
                {
                    PuzzleSolution[--CurrentStep].Undo();
                }
            }

            UpdateRuleButtons();
            UIGameBoard.ResumeLayout();
            UIGameBoard.Invalidate(true /*invalidateChildren*/);
            UIGameBoard.Update();
        }
Пример #2
0
 private void ButtonEndEdit_Click(object sender, EventArgs e)
 {
     UIGameBoard.Board.EditMode = false;
     ButtonEditGame.Visible     = true;
     ButtonEndEdit.Visible      = false;
     ButtonSolve.Visible        = true;
     UIGameBoard.Invalidate(true /*invalidateChildren*/);
     UIGameBoard.Update();
 }
Пример #3
0
        public void OnEditModeClick(object sender, MouseEventArgs args)
        {
            if (!Cell.Board.EditMode)
            {
                return;
            }

            UIGameBoard uiBoard = Form1.MainForm.UIGameBoard;

            if (Cell.Value > 0)
            {
                Cell.ClearCellValue();
                Cell.Board.RecalculatePencilMarks();
            }
            else
            {
                int        widthSection  = Width / 3;
                int        heightSection = (int)((float)Height / 3.3f);
                int        x             = args.X / widthSection;
                int        y             = args.Y / heightSection;
                int        option        = 3 * y + x + 1;
                List <int> pencilMarks   = Cell.PMSignature.ListOfBits();
                if (!Cell.IsPencilmarkSet(option))
                {
                    return;
                }

                List <Cell> emptyCells = Cell.ShadowedCells
                                         .Where(cell => cell.IsPencilmarkSet(option) && cell.PencilMarkCount == 1)
                                         .ToList();

                if (emptyCells.Count > 0)
                {
                    List <UICell> emptyUiCells = emptyCells
                                                 .Select(cell => UiGameBoard.UiCellMatrix[cell.RowIndex, cell.ColIndex])
                                                 .ToList();

                    UiGameBoard.HighlightCells(emptyUiCells, Color.Yellow, 1.0,
                                               new List <PMFinding>
                    {
                        new PMFinding(option, PMRole.ChainColor1)
                    });

                    return;
                }

                Cell.Board.SetCellValueAndAffectShadowedCells(Cell.RowIndex, Cell.ColIndex, option, false /*mutable*/);
            }

            uiBoard.Invalidate(true /*invalidateChildren*/);
            uiBoard.Update();
        }
Пример #4
0
        private void ButtonEditGame_Click(object sender, EventArgs e)
        {
            if (PuzzleSolution != null && CurrentStep > 0)
            {
                ButtonUndoAll_Click(null, null);
            }

            UIGameBoard.TurnOffHighlighting();
            UIGameBoard.Board.EditMode = true;
            ButtonEditGame.Visible     = false;
            ButtonSolve.Visible        = false;
            ButtonEndEdit.Visible      = true;
            UIGameBoard.Invalidate(true /*invalidateChildren*/);
            UIGameBoard.Update();
        }
Пример #5
0
        public Form1()
        {
            DictionaryDemoGames = new Dictionary <string, string>();
            MainForm            = this;
            InitializeComponent();

            UIGameBoard.Board = new GameBoard(9, @"
xxx xx3 xxx // xx8 47x 35x // xxx 589 64x
x7x xxx 89x // xx3 xxx 2xx // x86 xxx x1x
x31 725 xxx // x29 x18 4xx // xxx 3xx xxx
");

            ResetButtonStates();
            UIGameBoard.BringToFront();
            UIGameBoard.Board = UIGameBoard.Board;
        }
Пример #6
0
        private void OnSolvePuzzle_Click(object sender, EventArgs e)
        {
            bool couldSolve;

            UIGameBoard.SuspendLayout();
            PuzzleSolution = GameSolver.Solve(UIGameBoard.Board, out couldSolve);
            if (!couldSolve)
            {
                new TooHardBox().ShowDialog();
            }

            CurrentStep = PuzzleSolution.Count;
            ButtonUndoAll_Click(null, null);
            ButtonSolve.Visible = false;
            UpdateRuleButtons();
            UIGameBoard.ResumeLayout(true /*performLayout*/);
        }
Пример #7
0
        private void UpdateRuleButtons()
        {
            if (PuzzleSolution == null || PuzzleSolution.Count == 0)
            {
                return;
            }

            ButtonUndoAll.Enabled = ButtonStepBack.Enabled = (CurrentStep > 0);
            ButtonRedoAll.Enabled = ButtonStepForward.Enabled = (CurrentStep < PuzzleSolution.Count);
            if (CurrentStep < PuzzleSolution.Count)
            {
                ISolutionStep step = PuzzleSolution[CurrentStep];
                TextBoxRuleInformation.Text = step.Solution.Description;
                UIGameBoard.HighlightCells(step.Solution);
            }
            else
            {
                TextBoxRuleInformation.Text = string.Empty;
            }
        }