public void MixUpPuzzle() { _puzzleLogic.MixUpPuzzle(); short cellNumber = 1; foreach (Button b in this.Children) { PuzzleCell location = _puzzleLogic.FindCell(cellNumber++); b.SetValue(Grid.ColumnProperty, location.Col); b.SetValue(Grid.RowProperty, location.Row); } }
// 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()) { if (PuzzleWon != null) { PuzzleWon(this, EventArgs.Empty); } } }
/// <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); }
/// <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; }