aboutsummaryrefslogtreecommitdiff
path: root/src/ch/epfl
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl')
-rw-r--r--src/ch/epfl/xblast/server/debug/GameStatePrinter.java56
1 files changed, 40 insertions, 16 deletions
diff --git a/src/ch/epfl/xblast/server/debug/GameStatePrinter.java b/src/ch/epfl/xblast/server/debug/GameStatePrinter.java
index 240446b..ea8b360 100644
--- a/src/ch/epfl/xblast/server/debug/GameStatePrinter.java
+++ b/src/ch/epfl/xblast/server/debug/GameStatePrinter.java
@@ -1,24 +1,32 @@
1package ch.epfl.xblast.server.debug; 1package ch.epfl.xblast.server.debug;
2 2
3import java.util.List;
4
5import ch.epfl.xblast.Cell; 3import ch.epfl.xblast.Cell;
6import ch.epfl.xblast.server.Block; 4import ch.epfl.xblast.server.Block;
7import ch.epfl.xblast.server.Board; 5import ch.epfl.xblast.server.Board;
8import ch.epfl.xblast.server.GameState; 6import ch.epfl.xblast.server.GameState;
9import ch.epfl.xblast.server.Player; 7import ch.epfl.xblast.server.Player;
10 8
9import java.util.List;
10
11/**
12 * Game state printer utility class that outputs the board to the terminal.
13 *
14 * @author EPFL
15 */
11public final class GameStatePrinter { 16public final class GameStatePrinter {
12 private GameStatePrinter() {} 17
18 private GameStatePrinter() {
19 }
13 20
14 public static void printGameState(GameState s) { 21 public static void printGameState(GameState s) {
15 List<Player> ps = s.alivePlayers(); 22 List<Player> ps = s.alivePlayers();
16 Board board = s.board(); 23 Board board = s.board();
17 24
18 for (int y = 0; y < Cell.ROWS; ++y) { 25 for (int y = 0; y < Cell.ROWS; ++y) {
19 xLoop: for (int x = 0; x < Cell.COLUMNS; ++x) { 26 xLoop:
27 for (int x = 0; x < Cell.COLUMNS; ++x) {
20 Cell c = new Cell(x, y); 28 Cell c = new Cell(x, y);
21 for (Player p: ps) { 29 for (Player p : ps) {
22 if (p.position().containingCell().equals(c)) { 30 if (p.position().containingCell().equals(c)) {
23 System.out.print(stringForPlayer(p)); 31 System.out.print(stringForPlayer(p));
24 continue xLoop; 32 continue xLoop;
@@ -35,23 +43,39 @@ public final class GameStatePrinter {
35 StringBuilder b = new StringBuilder(); 43 StringBuilder b = new StringBuilder();
36 b.append(p.id().ordinal() + 1); 44 b.append(p.id().ordinal() + 1);
37 switch (p.direction()) { 45 switch (p.direction()) {
38 case N: b.append('^'); break; 46 case N:
39 case E: b.append('>'); break; 47 b.append('^');
40 case S: b.append('v'); break; 48 break;
41 case W: b.append('<'); break; 49 case E:
50 b.append('>');
51 break;
52 case S:
53 b.append('v');
54 break;
55 case W:
56 b.append('<');
57 break;
42 } 58 }
43 return b.toString(); 59 return b.toString();
44 } 60 }
45 61
46 private static String stringForBlock(Block b) { 62 private static String stringForBlock(Block b) {
47 switch (b) { 63 switch (b) {
48 case FREE: return " "; 64 case FREE:
49 case INDESTRUCTIBLE_WALL: return "##"; 65 return " ";
50 case DESTRUCTIBLE_WALL: return "??"; 66 case INDESTRUCTIBLE_WALL:
51 case CRUMBLING_WALL: return "¿¿"; 67 return "##";
52 case BONUS_BOMB: return "+b"; 68 case DESTRUCTIBLE_WALL:
53 case BONUS_RANGE: return "+r"; 69 return "??";
54 default: throw new Error(); 70 case CRUMBLING_WALL:
71 return "¿¿";
72 case BONUS_BOMB:
73 return "+b";
74 case BONUS_RANGE:
75 return "+r";
76 default:
77 throw new Error();
55 } 78 }
56 } 79 }
80
57} 81}