diff options
author | Timothée Floure | 2016-03-08 23:16:12 +0100 |
---|---|---|
committer | Timothée Floure | 2016-03-08 23:16:12 +0100 |
commit | b0356d4ff6694ccc7f8fae1766b73b0e99c78ed9 (patch) | |
tree | 3e0400dc79c1a4cbae4e000f6642bf3d316953f2 /src | |
parent | 5309cf4c441571a94e6c0033765ec43a3dc67ec8 (diff) | |
download | xblast-b0356d4ff6694ccc7f8fae1766b73b0e99c78ed9.tar.gz |
Import NameCheck04 and GaneStatePrinter (given files for the week 4)
Diffstat (limited to 'src')
-rw-r--r-- | src/ch/epfl/xblast/server/debug/GameStatePrinter.java | 57 |
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 @@ | |||
1 | package ch.epfl.xblast.server.debug; | ||
2 | |||
3 | import java.util.List; | ||
4 | |||
5 | import ch.epfl.xblast.Cell; | ||
6 | import ch.epfl.xblast.server.Block; | ||
7 | import ch.epfl.xblast.server.Board; | ||
8 | import ch.epfl.xblast.server.GameState; | ||
9 | import ch.epfl.xblast.server.Player; | ||
10 | |||
11 | public 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 | } | ||