aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ch/epfl/xblast/server/debug/GameStatePrinter.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/ch/epfl/xblast/server/debug/GameStatePrinter.java b/src/ch/epfl/xblast/server/debug/GameStatePrinter.java
new file mode 100644
index 0000000..240446b
--- /dev/null
+++ b/src/ch/epfl/xblast/server/debug/GameStatePrinter.java
@@ -0,0 +1,57 @@
1package ch.epfl.xblast.server.debug;
2
3import java.util.List;
4
5import ch.epfl.xblast.Cell;
6import ch.epfl.xblast.server.Block;
7import ch.epfl.xblast.server.Board;
8import ch.epfl.xblast.server.GameState;
9import ch.epfl.xblast.server.Player;
10
11public final class GameStatePrinter {
12 private GameStatePrinter() {}
13
14 public static void printGameState(GameState s) {
15 List<Player> ps = s.alivePlayers();
16 Board board = s.board();
17
18 for (int y = 0; y < Cell.ROWS; ++y) {
19 xLoop: for (int x = 0; x < Cell.COLUMNS; ++x) {
20 Cell c = new Cell(x, y);
21 for (Player p: ps) {
22 if (p.position().containingCell().equals(c)) {
23 System.out.print(stringForPlayer(p));
24 continue xLoop;
25 }
26 }
27 Block b = board.blockAt(c);
28 System.out.print(stringForBlock(b));
29 }
30 System.out.println();
31 }
32 }
33
34 private static String stringForPlayer(Player p) {
35 StringBuilder b = new StringBuilder();
36 b.append(p.id().ordinal() + 1);
37 switch (p.direction()) {
38 case N: b.append('^'); break;
39 case E: b.append('>'); break;
40 case S: b.append('v'); break;
41 case W: b.append('<'); break;
42 }
43 return b.toString();
44 }
45
46 private static String stringForBlock(Block b) {
47 switch (b) {
48 case FREE: return " ";
49 case INDESTRUCTIBLE_WALL: return "##";
50 case DESTRUCTIBLE_WALL: return "??";
51 case CRUMBLING_WALL: return "¿¿";
52 case BONUS_BOMB: return "+b";
53 case BONUS_RANGE: return "+r";
54 default: throw new Error();
55 }
56 }
57}