diff --git a/src/ConsoleRenderer.java b/src/ConsoleRenderer.java index d536b19..8388013 100644 --- a/src/ConsoleRenderer.java +++ b/src/ConsoleRenderer.java @@ -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 + } } diff --git a/src/GomokuRenderer.java b/src/GomokuRenderer.java index 09f9f0f..ab4f21e 100644 --- a/src/GomokuRenderer.java +++ b/src/GomokuRenderer.java @@ -2,6 +2,8 @@ public abstract class GomokuRenderer { + protected GomokuGame game; + public abstract void init(GomokuGame game); public abstract void update(); } diff --git a/src/RenderBoard.java b/src/RenderBoard.java new file mode 100644 index 0000000..a406c06 --- /dev/null +++ b/src/RenderBoard.java @@ -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); + } + } + } +} \ No newline at end of file diff --git a/src/SwingRenderer.java b/src/SwingRenderer.java index 7e06c0f..30b1670 100644 --- a/src/SwingRenderer.java +++ b/src/SwingRenderer.java @@ -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); - } - } - } } \ No newline at end of file