Пример #1
0
        public void MixUpPuzzle()
        {
            _puzzleLogic.MixUpPuzzle();

            short cellNumber = 1;

            foreach (Button b in this.puzzleGrid.Children)
            {
                PuzzleCell location = _puzzleLogic.FindCell(cellNumber++);
                b.SetValue(Grid.ColumnProperty, location.Col);
                b.SetValue(Grid.RowProperty, location.Row);
            }
        }
Пример #2
0
        /// <summary>
        /// Moves the piece
        /// </summary>
        /// <param name="row"></param>
        /// <param name="col"></param>
        /// <returns>The cell of the newly opened position</returns>
        public PuzzleCell MovePiece(int row, int col)
        {
            //	Debug.Assert(GetMoveStatus(row, col) != MoveStatus.BadMove);

            PuzzleCell cell = new PuzzleCell(_emptyRow, _emptyCol, EMPTY_CELL_ID);

            short origCell = _cells[row, col];

            _cells[_emptyRow, _emptyCol] = origCell;
            _cells[row, col]             = EMPTY_CELL_ID;

            _emptyCol = col;
            _emptyRow = row;

            return(cell);
        }
Пример #3
0
        // Assumed to be a valid move.
        private void MovePiece(Button b, int row, int col)
        {
            PuzzleCell newPosition = _puzzleLogic.MovePiece(row, col);

            b.SetValue(Grid.ColumnProperty, newPosition.Col);
            b.SetValue(Grid.RowProperty, newPosition.Row);

            if (_puzzleLogic.CheckForWin())
            {
                this.initPuzzle();

                if (PuzzleWon != null)
                {
                    PuzzleWon(this, EventArgs.Empty);
                }
            }
        }