From f69ce5064bed9c3a8de37d9ced22c0ae8c13edc0 Mon Sep 17 00:00:00 2001 From: Dorian HAMDANI Date: Tue, 6 May 2025 14:31:17 +0200 Subject: [PATCH] Add proper console rendering --- src/ConsoleRenderer.java | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/ConsoleRenderer.java b/src/ConsoleRenderer.java index bcc15a7..a3ee8ff 100644 --- a/src/ConsoleRenderer.java +++ b/src/ConsoleRenderer.java @@ -1,6 +1,15 @@ public class ConsoleRenderer extends GomokuRenderer { + // Color constants + public static final String RESET = "\u001B[0m"; + public static final String BOLD = "\u001B[1m"; + public static final String COLOR_RED = "\u001B[31m"; + public static final String COLOR_GREEN = "\u001B[32m"; + public static final String COLOR_GRAY = "\u001B[38;5;240m"; + + public static final String CLEAR_TERM = "\033[H\033[2J"; + public ConsoleRenderer() { } @@ -15,11 +24,12 @@ public class ConsoleRenderer extends GomokuRenderer { // Print the board to the console // Clear the console - System.out.print("\033[H\033[2J"); + System.out.print(CLEAR_TERM); System.out.flush(); String[] board = game.getBoard().toString().split("\n"); - String horizontalLine = getHorizontalLine(); + String horizontalLine = getHorizontalLine(RESET); + String horizontalLineGray = getHorizontalLine(COLOR_GRAY); int width = game.getBoard().getWidth(); int height = game.getBoard().getHeight(); @@ -31,23 +41,25 @@ public class ConsoleRenderer extends GomokuRenderer { System.out.println(horizontalLine); for (int i = 0; i < height; i++) { System.out.print("|"); - + for (int j=0; j