diff options
-rw-r--r-- | src/ch/epfl/xblast/server/debug/GameStatePrinter.java | 56 | ||||
-rw-r--r-- | test/ch/epfl/xblast/namecheck/NameCheck04.java | 19 |
2 files changed, 48 insertions, 27 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 @@ | |||
1 | package ch.epfl.xblast.server.debug; | 1 | package ch.epfl.xblast.server.debug; |
2 | 2 | ||
3 | import java.util.List; | ||
4 | |||
5 | import ch.epfl.xblast.Cell; | 3 | import ch.epfl.xblast.Cell; |
6 | import ch.epfl.xblast.server.Block; | 4 | import ch.epfl.xblast.server.Block; |
7 | import ch.epfl.xblast.server.Board; | 5 | import ch.epfl.xblast.server.Board; |
8 | import ch.epfl.xblast.server.GameState; | 6 | import ch.epfl.xblast.server.GameState; |
9 | import ch.epfl.xblast.server.Player; | 7 | import ch.epfl.xblast.server.Player; |
10 | 8 | ||
9 | import java.util.List; | ||
10 | |||
11 | /** | ||
12 | * Game state printer utility class that outputs the board to the terminal. | ||
13 | * | ||
14 | * @author EPFL | ||
15 | */ | ||
11 | public final class GameStatePrinter { | 16 | public 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 | } |
diff --git a/test/ch/epfl/xblast/namecheck/NameCheck04.java b/test/ch/epfl/xblast/namecheck/NameCheck04.java index b6adc8c..dc6cfb2 100644 --- a/test/ch/epfl/xblast/namecheck/NameCheck04.java +++ b/test/ch/epfl/xblast/namecheck/NameCheck04.java | |||
@@ -1,28 +1,24 @@ | |||
1 | package ch.epfl.xblast.namecheck; | 1 | package ch.epfl.xblast.namecheck; |
2 | 2 | ||
3 | import java.util.List; | ||
4 | import java.util.Optional; | ||
5 | |||
6 | import ch.epfl.cs108.Sq; | 3 | import ch.epfl.cs108.Sq; |
7 | import ch.epfl.xblast.Cell; | 4 | import ch.epfl.xblast.Cell; |
8 | import ch.epfl.xblast.Lists; | 5 | import ch.epfl.xblast.Lists; |
9 | import ch.epfl.xblast.PlayerID; | 6 | import ch.epfl.xblast.PlayerID; |
10 | import ch.epfl.xblast.Time; | 7 | import ch.epfl.xblast.Time; |
11 | import ch.epfl.xblast.server.Block; | 8 | import ch.epfl.xblast.server.*; |
12 | import ch.epfl.xblast.server.Board; | 9 | |
13 | import ch.epfl.xblast.server.Bomb; | 10 | import java.util.List; |
14 | import ch.epfl.xblast.server.Bonus; | 11 | import java.util.Optional; |
15 | import ch.epfl.xblast.server.GameState; | ||
16 | import ch.epfl.xblast.server.Player; | ||
17 | import ch.epfl.xblast.server.Ticks; | ||
18 | 12 | ||
19 | /** | 13 | /** |
20 | * Classe abstraite utilisant tous les éléments de l'étape 4, pour essayer de | 14 | * Classe abstraite utilisant tous les éléments de l'étape 4, pour essayer de |
21 | * garantir que ceux-ci ont le bon nom et les bons types. Attention, ceci n'est | 15 | * garantir que ceux-ci ont le bon nom et les bons types. Attention, ceci n'est |
22 | * pas un test unitaire, et n'a pas pour but d'être exécuté! | 16 | * pas un test unitaire, et n'a pas pour but d'être exécuté! |
17 | * | ||
18 | * @author EPFL | ||
23 | */ | 19 | */ |
24 | |||
25 | abstract class NameCheck04 { | 20 | abstract class NameCheck04 { |
21 | |||
26 | void checkLists() { | 22 | void checkLists() { |
27 | List<Integer> l1 = null; | 23 | List<Integer> l1 = null; |
28 | List<List<Integer>> p1 = Lists.permutations(l1); | 24 | List<List<Integer>> p1 = Lists.permutations(l1); |
@@ -78,4 +74,5 @@ abstract class NameCheck04 { | |||
78 | ps = s.isGameOver() ? s.alivePlayers() : s.players(); | 74 | ps = s.isGameOver() ? s.alivePlayers() : s.players(); |
79 | System.out.println(w); | 75 | System.out.println(w); |
80 | } | 76 | } |
77 | |||
81 | } | 78 | } |