More Renderer stuff
This commit is contained in:
@@ -5,8 +5,12 @@ public class ConsoleRenderer extends GomokuRenderer {
|
||||
public ConsoleRenderer() {}
|
||||
|
||||
@Override
|
||||
public void init() {}
|
||||
public void init(GomokuGame game) {
|
||||
System.out.println("Console Renderer initialized.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(GomokuGame game) {}
|
||||
public void update() {
|
||||
// TODO: draw the board
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
public abstract class GomokuRenderer {
|
||||
|
||||
protected GomokuGame game;
|
||||
|
||||
public abstract void init(GomokuGame game);
|
||||
public abstract void update();
|
||||
}
|
||||
|
||||
33
src/RenderBoard.java
Normal file
33
src/RenderBoard.java
Normal file
@@ -0,0 +1,33 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
class RenderBoard {
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
private int[][] boardState; // Example representation of the board state
|
||||
|
||||
public RenderBoard(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
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, int w, int h) {
|
||||
// Draw the board here
|
||||
g.setColor(Color.LIGHT_GRAY);
|
||||
int cellSize = w / this.width;
|
||||
|
||||
for (int i = 0; i < this.width; i++) {
|
||||
for (int j = 0; j < this.height; j++) {
|
||||
g.drawRect(x + i * cellSize, y + j * cellSize, cellSize, cellSize);
|
||||
// Draw the tokens here
|
||||
g.fillOval(x + i * cellSize, y + j * cellSize, cellSize, cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public class SwingRenderer extends GomokuRenderer {
|
||||
|
||||
private JFrame mainFrame;
|
||||
private GomokuGame game;
|
||||
private RendererPanel canvas;
|
||||
private RenderCanvas canvas;
|
||||
|
||||
public SwingRenderer() {}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class SwingRenderer extends GomokuRenderer {
|
||||
mainFrame = new JFrame("Gomoku! - Projet L2");
|
||||
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
mainFrame.setSize(960, 960);
|
||||
canvas = new RendererPanel();
|
||||
canvas = new RenderCanvas();
|
||||
mainFrame.add(canvas);
|
||||
mainFrame.pack();
|
||||
mainFrame.setVisible(true);
|
||||
@@ -43,14 +43,14 @@ public class SwingRenderer extends GomokuRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
class RendererPanel extends JPanel {
|
||||
class RenderCanvas extends JPanel {
|
||||
|
||||
public RendererBoard board;
|
||||
public RenderBoard board;
|
||||
|
||||
public RendererPanel() {
|
||||
public RenderCanvas() {
|
||||
setBorder(BorderFactory.createLineBorder(Color.black));
|
||||
setBackground(Color.white);
|
||||
board = new RendererBoard(8, 8); // Example board size
|
||||
board = new RenderBoard(8, 8); // Example board size
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
@@ -74,36 +74,4 @@ class RendererPanel extends JPanel {
|
||||
board.update(game);
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
class RendererBoard {
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
private GomokuGame game;
|
||||
|
||||
public RendererBoard(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void update(GomokuGame game) {
|
||||
// Update the board state based on the game
|
||||
// This method should be called whenever the game state changes
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
public void drawBoard(Graphics g, int x, int y, int w, int h) {
|
||||
// Draw the board here
|
||||
g.setColor(Color.LIGHT_GRAY);
|
||||
int cellSize = w / this.width;
|
||||
|
||||
for (int i = 0; i < this.width; i++) {
|
||||
for (int j = 0; j < this.height; j++) {
|
||||
g.drawRect(x + i * cellSize, y + j * cellSize, cellSize, cellSize);
|
||||
// Draw the tokens here
|
||||
g.fillOval(x + i * cellSize, y + j * cellSize, cellSize, cellSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user