diff --git a/Makefile b/Makefile index e134f54..0a25ee1 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,8 @@ JAVADOC_OPTIONS=-Xdoclint:all -private -encoding UTF-8 -charset UTF-8 -docencodi BUILDS=builds DOC=doc CLASSPATH=src -LIBARIES= +LIBARIES=\ +lib/jansi-1.16.jar CLASSES=\ src/game/Main.java \ src/game/Game.java \ diff --git a/lib/jansi-1.16.jar b/lib/jansi-1.16.jar new file mode 100644 index 0000000..235a9c7 Binary files /dev/null and b/lib/jansi-1.16.jar differ diff --git a/src/game/Game.java b/src/game/Game.java index b8afb8b..0aefc8d 100644 --- a/src/game/Game.java +++ b/src/game/Game.java @@ -1,6 +1,9 @@ package game; import java.util.Random; +import org.fusesource.jansi.AnsiConsole; +import org.fusesource.jansi.Ansi; +import org.fusesource.jansi.Ansi.Color; import player.Player; import player.maurizio.MaurizioAI; @@ -113,6 +116,8 @@ public class Game { * @return the winner of the game (0=draw) */ public int start(boolean output, boolean rand) { + // Initialize Jansi + AnsiConsole.systemInstall(); // Set starting player. if(rand){ Random ran = new Random(); @@ -131,7 +136,7 @@ public class Game { makeMove(output); currentP = other(currentP); if(output){ - logGame(); + logGame(hist.getLast()); } int state = checkState(output); if(state != (-1)){ @@ -140,9 +145,13 @@ public class Game { System.out.println("Thanks for Playing!"); System.out.println("*******************"); } + // Uninstall Jansi + AnsiConsole.systemUninstall(); return state; // the result of the game } } + // Uninstall Jansi + AnsiConsole.systemUninstall(); return checkState(false); // it is impossible to reach this, but it makes the compiler happy ;) } @@ -262,18 +271,31 @@ public class Game { /** * Prints the current board to stdout. */ - private void logGame() { + private void logGame(GameEntry entry) { + Ansi playerX = Ansi.ansi().render("|X"); + Ansi playerO = Ansi.ansi().render("|O"); + Ansi playerXBold = Ansi.ansi().render("|@|red,bold X|@"); + Ansi playerOBold = Ansi.ansi().render("|@|red,bold O|@"); for(int i = 0; i < board[0].length; i++){ for(int j = 0;j < board.length; j++){ + if(i == entry.getRow() && j == entry.getColumn()) { + if(board[j][i] == 1){ + System.out.print(playerXBold); + } + if (board[j][i] == 2){ + System.out.print(playerOBold); + } + } else { + if(board[j][i] == 1){ + System.out.print(playerX); + } + if (board[j][i] == 2){ + System.out.print(playerO); + } + } if(board[j][i] == 0){ System.out.print("| "); } - if(board[j][i] == 1){ - System.out.print("|X"); - } - if (board[j][i] == 2){ - System.out.print("|O"); - } } System.out.println("|"); }