94 lines
2.8 KiB
Java
94 lines
2.8 KiB
Java
import java.awt.Color;
|
|
import java.awt.Graphics;
|
|
|
|
class RenderBoard {
|
|
|
|
private int boardWidth;
|
|
private int boardHeight;
|
|
public int renderWidth;
|
|
public int renderHeight;
|
|
private int cellSize;
|
|
private int borderThickness;
|
|
// private int[][] boardState;
|
|
|
|
public RenderBoard(int width, int height, int renderWidth, int renderHeight) {
|
|
this.boardWidth = width;
|
|
this.boardHeight = height;
|
|
this.renderWidth = renderWidth;
|
|
this.renderHeight = renderHeight;
|
|
this.borderThickness = 5;
|
|
int cellWidth = renderWidth / width;
|
|
int cellHeight = renderHeight / height;
|
|
this.cellSize = Math.min(cellWidth, cellHeight);
|
|
}
|
|
|
|
public RenderBoard(int renderWidth, int renderHeight) {
|
|
this(
|
|
GomokuGame.DEFAULT_BOARD_WIDTH,
|
|
GomokuGame.DEFAULT_BOARD_HEIGHT,
|
|
renderWidth,
|
|
renderHeight
|
|
);
|
|
}
|
|
|
|
public void update(GomokuGame game) {
|
|
// Update the board state based on the game
|
|
// This method should be called whenever the game state changes
|
|
}
|
|
|
|
public void drawBoard(Graphics g, int x, int y) {
|
|
// Draw the global border
|
|
g.setColor(Color.LIGHT_GRAY);
|
|
g.fillRect(
|
|
x,
|
|
y,
|
|
this.renderWidth + 2 * this.borderThickness,
|
|
this.renderHeight + 2 * this.borderThickness
|
|
);
|
|
g.setColor(Color.WHITE);
|
|
g.fillRect(
|
|
x + this.borderThickness,
|
|
y + this.borderThickness,
|
|
this.renderWidth,
|
|
this.renderHeight
|
|
);
|
|
|
|
int i, j;
|
|
int cy = y + this.borderThickness;
|
|
for (i = 0; i < this.boardHeight; i++) {
|
|
int cx = x + this.borderThickness;
|
|
for (j = 0; j < this.boardWidth; j++) {
|
|
// Draw the border
|
|
g.setColor(Color.LIGHT_GRAY);
|
|
g.fillRect(
|
|
cx,
|
|
cy,
|
|
this.cellSize,
|
|
this.cellSize
|
|
);
|
|
g.setColor(Color.WHITE);
|
|
g.fillRect(
|
|
cx + this.borderThickness,
|
|
cy + this.borderThickness,
|
|
this.cellSize - 2 * this.borderThickness,
|
|
this.cellSize - 2 * this.borderThickness
|
|
);
|
|
// Draw the cell
|
|
this.drawToken(g, x, y, Color.BLUE);
|
|
cx += this.cellSize;
|
|
}
|
|
cy += this.cellSize;
|
|
}
|
|
}
|
|
|
|
public void drawToken(Graphics g, int x, int y, Color color) {
|
|
// Draw the token at the specified position
|
|
g.setColor(color);
|
|
g.fillRect(
|
|
x + 2 * this.borderThickness,
|
|
y + 2 * this.borderThickness,
|
|
cellSize - 2 * borderThickness,
|
|
cellSize - 2 * borderThickness
|
|
);
|
|
}
|
|
} |