private void setupRoadGrid() { int x = 315; int y = 70; int x_diff = 75; int y_diff = 150; int col; int columnMax = 6; // The horizontal-button rows for (int r = 0; r < Global_Variables.MAX_ROAD_ROWS; r += 2) { for (col = 0; col < columnMax; col++) { RoadButton b = new RoadButton(r, col); setLocationAndColorButton(b, Color.White, x, y); setRoadButtonSizeCoordinatesAndClick(b, HORIZONTAL_ROAD_SIZE, r, col); roadGrid[r, col] = b; boardPanel.Controls.Add(b); x += x_diff; } // Allow more or less buttons for the next row if (r < 4) columnMax += 2; else if (r >= 6) columnMax -= 2; // Find the correct start positions for the next row if (r < 4) x = x - x_diff*(col + 1); else if (r >= 6) x = x - x_diff*(col - 1); else x = x - x_diff*col; y += y_diff; } // The vertical-button rows x = 292; y = 90; x_diff = 150; y_diff = 150; columnMax = 4; for (int r = 1; r < Global_Variables.MAX_ROAD_ROWS; r += 2) { for (col = 0; col < columnMax; col++) { RoadButton b = new RoadButton(r, col); setLocationAndColorButton(b, Color.White, x, y); setRoadButtonSizeCoordinatesAndClick(b, VERTICAL_ROAD_SIZE, r, col); roadGrid[r, col] = b; boardPanel.Controls.Add(b); x += x_diff; } columnMax = (r < 5) ? columnMax + 1 : columnMax - 1; y = y + y_diff; x = (r <= 4) ? x - x_diff*col - x_diff/2 : x - x_diff*col + x_diff/2; } }
private void setRoadButtonSizeCoordinatesAndClick(RoadButton button, Size size, int x, int y) { button.Size = size; button.Click += roadButton_Click; button.coordinates = new Point(x, y); }