Add console renderer base and fix load() issues
This commit is contained in:
@@ -1,16 +1,48 @@
|
||||
|
||||
|
||||
public class ConsoleRenderer extends GomokuRenderer {
|
||||
|
||||
public ConsoleRenderer() {}
|
||||
public ConsoleRenderer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(GomokuGame game) {
|
||||
System.out.println("Console Renderer initialized.");
|
||||
this.game = game;
|
||||
System.out.println("ConsoleRenderer initialized");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
// TODO: draw the board
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user