
public class ConsoleRenderer extends GomokuRenderer {

    public ConsoleRenderer() {
    }

    @Override
    public void init(GomokuGame game) {
        this.game = game;
        System.out.println("ConsoleRenderer initialized");
    }

    @Override
    public void update() {
        // Print the board to the console

        String[] board = game.getBoard().toString().split("\n");
        String horizontalLine = getHorizontalLine();
        int width = game.getBoard().getWidth();
        int height = game.getBoard().getHeight();

        // Print a separator line, followed by the game infos
        System.out.println(horizontalLine);
        System.out.println("|" + String.format(" %-" + (width - 1) + "s", "Gomoku Game!") + "|");
        // System.out.println("Current player: " + game.getCurrentPlayer().getName());
        // System.out.println("Number of tokens left: " + game.getCurrentPlayer().getTokensLeft());

        // Print the board
        System.out.println(horizontalLine);
        for (int i = 0; i < height; i++) {
            System.out.print("|");
            System.out.print(board[i]);
            System.out.println("|");
        }
        System.out.println(horizontalLine);

    }

    private String getHorizontalLine() {
        StringBuilder sb = new StringBuilder();
        sb.append("+");
        for (int i = 0; i < game.getBoard().getWidth(); i++) {
            sb.append("-");
        }
        sb.append("+");
        return sb.toString();
    }
}
