aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-03-26 13:45:30 +0100
committerPacien TRAN-GIRARD2016-03-26 13:45:30 +0100
commit5e2797946a3d63de9142d79b241788e2284f8eab (patch)
tree279ab37a16a62368ee44b9c43b5b29e853f92b8a
parent552d82f34ee4b60785164bc40d6dd5b5d8923609 (diff)
downloadxblast-5e2797946a3d63de9142d79b241788e2284f8eab.tar.gz
Implement simulation terminal output coloring
-rw-r--r--src/ch/epfl/xblast/server/debug/GameStatePrinter.java31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/ch/epfl/xblast/server/debug/GameStatePrinter.java b/src/ch/epfl/xblast/server/debug/GameStatePrinter.java
index d4d91e5..a846421 100644
--- a/src/ch/epfl/xblast/server/debug/GameStatePrinter.java
+++ b/src/ch/epfl/xblast/server/debug/GameStatePrinter.java
@@ -16,6 +16,25 @@ import java.util.List;
16 */ 16 */
17public final class GameStatePrinter { 17public final class GameStatePrinter {
18 18
19 private enum ANSIColor {
20
21 BLACK(0), RED(1), GREEN(2), YELLOW(3), BLUE(4), MAGENTA(5), CYAN(6), WHITE(7);
22
23 private static final String CSI = "\u001b[";
24 private static final String END = "m";
25 private static final int SET_COMMAND = 4;
26
27 private final int code;
28
29 ANSIColor(int code) {
30 this.code = code;
31 }
32
33 public String coloredText(String t) {
34 return String.format("%s%d%d%s%s%s%s", CSI, SET_COMMAND, this.code, END, t, CSI, END);
35 }
36 }
37
19 private GameStatePrinter() { 38 private GameStatePrinter() {
20 } 39 }
21 40
@@ -63,7 +82,7 @@ public final class GameStatePrinter {
63 b.append('<'); 82 b.append('<');
64 break; 83 break;
65 } 84 }
66 return b.toString(); 85 return ANSIColor.CYAN.coloredText(b.toString());
67 } 86 }
68 87
69 private static String stringForBlock(Block b) { 88 private static String stringForBlock(Block b) {
@@ -71,15 +90,15 @@ public final class GameStatePrinter {
71 case FREE: 90 case FREE:
72 return " "; 91 return " ";
73 case INDESTRUCTIBLE_WALL: 92 case INDESTRUCTIBLE_WALL:
74 return "##"; 93 return ANSIColor.BLACK.coloredText("##");
75 case DESTRUCTIBLE_WALL: 94 case DESTRUCTIBLE_WALL:
76 return "??"; 95 return ANSIColor.BLACK.coloredText("??");
77 case CRUMBLING_WALL: 96 case CRUMBLING_WALL:
78 return "¿¿"; 97 return ANSIColor.BLACK.coloredText("¿¿");
79 case BONUS_BOMB: 98 case BONUS_BOMB:
80 return "+b"; 99 return ANSIColor.GREEN.coloredText("+b");
81 case BONUS_RANGE: 100 case BONUS_RANGE:
82 return "+r"; 101 return ANSIColor.GREEN.coloredText("+r");
83 default: 102 default:
84 throw new Error(); 103 throw new Error();
85 } 104 }