private void UpdateGrid(Board board, SquareControl[,] grid) { // Map the current game board to the square controls. for (int i = 0; i < Board.GridMaxRow; i++) { for (int j = 0; j < Board.GridMaxCol; j++) { grid[i, j].Contents = board.GetSquareContents(i, j); grid[i, j].Refresh(); } } }
private void UpdateSquare(int row, int col, SquareControl[,] grid, Board board) { grid[row, col].Contents = board.GetSquareContents(row, col); grid[row, col].Refresh(); }
// Grid Events private void SquareControl_MouseMove(object sender, MouseEventArgs e) { SquareControl squareControl = (SquareControl)sender; // If the square is Empty and the player wants place a building #region Select Empty if (_board.IsValidSquare(squareControl.Row, squareControl.Col) && actionState == ActionState.InPlace) { // If the square is selected and his last content is empty if (!squareControl.IsActive && squareControl.PreviewContents == Board.EmptyInt) { // If the show valid place option is active, mark the square if (options.showValidPlaces) { squareControl.IsActive = true; // If the preview place option is not active, update the square display now if (!options.previewSquares) squareControl.Refresh(); } // If the preview place option is active, mark the appropriate squares if (options.previewSquares) { // Create a temporary board to make the move on Board copy_board = new Board(_board); // Set up the move preview for (int i = 0; i < Board.GridMaxRow; i++) { for (int j = 0; j < Board.GridMaxCol; j++) { if (copy_board.GetSquareContents(i, j) != _board.GetSquareContents(i, j)) { // Set and update the square display _grid[i, j].PreviewContents = copy_board.GetSquareContents(i, j); _grid[i, j].Refresh(); } } } } } // Change the cursor squareControl.Cursor = Cursors.Hand; } #endregion // If the square is a building & the player wants repair building #region Select Building else if (_board.IsBuilding(squareControl.Row, squareControl.Col) && (actionState == ActionState.None || actionState == ActionState.SelectRepair)) { // If the square is selected if (!squareControl.IsActive) { // If the show valid place option is active, mark the square if (options.showValidPlaces) { squareControl.IsActive = true; // If the preview place option is not active, update the square display now if (!options.previewSquares) squareControl.Refresh(); } // If the preview place option is active, mark the appropriate squares if (options.previewSquares) { // Create a temporary board Board copy_board = new Board(_board); // Set up the move preview for (int i = 0; i < Board.GridMaxRow; i++) { for (int j = 0; j < Board.GridMaxCol; j++) { if (copy_board.GetSquareContents(i, j) != _board.GetSquareContents(i, j)) { // Set and update the square display _grid[i, j].PreviewContents = copy_board.GetSquareContents(i, j); _grid[i, j].Refresh(); } } } } } // Change the cursor squareControl.Cursor = Cursors.Hand; } #endregion }