private void SetupThePuzzleGridStructure() { _puzzleLogic = new PuzzleLogic(_numRows); // Define rows and columns in the Grid for (int row = 0; row < _numRows; row++) { RowDefinition r = new RowDefinition(); r.Height = GridLength.Auto; this.RowDefinitions.Add(r); ColumnDefinition c = new ColumnDefinition(); c.Width = GridLength.Auto; this.ColumnDefinitions.Add(c); } Style buttonStyle = (Style)this.Resources["PuzzleButtonStyle"]; // Now add the buttons in int i = 1; for (int row = 0; row < _numRows; row++) { for (int col = 0; col < _numRows; col++) { // lower right cell is empty if (_numRows != 1 && row == _numRows - 1 && col == _numRows - 1) { continue; } KinectTileButton b = new KinectTileButton(); b.FontSize = 24; // Styling comes in only here... if (_styling) { b.Style = buttonStyle; } b.SetValue(Grid.RowProperty, row); b.SetValue(Grid.ColumnProperty, col); b.Content = i.ToString(); i++; this.Children.Add(b); } } }
// Assumed to be a valid move. private void MovePiece(KinectTileButton 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); } } }