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 | |
parent | 5309cf4c441571a94e6c0033765ec43a3dc67ec8 (diff) | |
download | xblast-b0356d4ff6694ccc7f8fae1766b73b0e99c78ed9.tar.gz |
Import NameCheck04 and GaneStatePrinter (given files for the week 4)
-rw-r--r-- | src/ch/epfl/xblast/server/debug/GameStatePrinter.java | 57 | ||||
-rw-r--r-- | test/ch/epfl/xblast/namecheck/NameCheck04.java | 81 |
2 files changed, 138 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 | } | ||
diff --git a/test/ch/epfl/xblast/namecheck/NameCheck04.java b/test/ch/epfl/xblast/namecheck/NameCheck04.java new file mode 100644 index 0000000..b6adc8c --- /dev/null +++ b/test/ch/epfl/xblast/namecheck/NameCheck04.java | |||
@@ -0,0 +1,81 @@ | |||
1 | package ch.epfl.xblast.namecheck; | ||
2 | |||
3 | import java.util.List; | ||
4 | import java.util.Optional; | ||
5 | |||
6 | import ch.epfl.cs108.Sq; | ||
7 | import ch.epfl.xblast.Cell; | ||
8 | import ch.epfl.xblast.Lists; | ||
9 | import ch.epfl.xblast.PlayerID; | ||
10 | import ch.epfl.xblast.Time; | ||
11 | import ch.epfl.xblast.server.Block; | ||
12 | import ch.epfl.xblast.server.Board; | ||
13 | import ch.epfl.xblast.server.Bomb; | ||
14 | import ch.epfl.xblast.server.Bonus; | ||
15 | import ch.epfl.xblast.server.GameState; | ||
16 | import ch.epfl.xblast.server.Player; | ||
17 | import ch.epfl.xblast.server.Ticks; | ||
18 | |||
19 | /** | ||
20 | * 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 | ||
22 | * pas un test unitaire, et n'a pas pour but d'être exécuté! | ||
23 | */ | ||
24 | |||
25 | abstract class NameCheck04 { | ||
26 | void checkLists() { | ||
27 | List<Integer> l1 = null; | ||
28 | List<List<Integer>> p1 = Lists.permutations(l1); | ||
29 | List<List<List<Integer>>> p2 = Lists.permutations(p1); | ||
30 | System.out.println(p2); | ||
31 | } | ||
32 | |||
33 | void checkBonus(boolean x) { | ||
34 | Bonus b = x ? Bonus.INC_BOMB : Bonus.INC_RANGE; | ||
35 | Player p = null; | ||
36 | p = b.applyTo(p); | ||
37 | } | ||
38 | |||
39 | void checkBlock(Block b) { | ||
40 | b = b.isBonus() ? Block.BONUS_BOMB : Block.BONUS_RANGE; | ||
41 | Bonus s = b.associatedBonus(); | ||
42 | System.out.println(s); | ||
43 | } | ||
44 | |||
45 | void checkTime() { | ||
46 | Optional<Integer> o; | ||
47 | o = Optional.of(Time.S_PER_MIN); | ||
48 | o = Optional.of(Time.MS_PER_S); | ||
49 | o = Optional.of(Time.US_PER_S); | ||
50 | o = Optional.of(Time.NS_PER_S); | ||
51 | System.out.println(o); | ||
52 | } | ||
53 | |||
54 | void checkTicks() { | ||
55 | Optional<Integer> o; | ||
56 | o = Optional.of(Ticks.TICKS_PER_SECOND); | ||
57 | o = Optional.of(Ticks.TICK_NANOSECOND_DURATION); | ||
58 | o = Optional.of(Ticks.TOTAL_TICKS); | ||
59 | System.out.println(o); | ||
60 | } | ||
61 | |||
62 | void checkGameState() { | ||
63 | int ts = 0; | ||
64 | Board b = null; | ||
65 | List<Player> ps = null; | ||
66 | List<Bomb> bs = null; | ||
67 | List<Sq<Sq<Cell>>> es = null; | ||
68 | List<Sq<Cell>> xs = null; | ||
69 | GameState s = new GameState(ts, b, ps, bs, es, xs); | ||
70 | s = new GameState(b, ps); | ||
71 | ts = s.ticks(); | ||
72 | if (s.isGameOver()) { | ||
73 | Optional<Double> t = Optional.of(s.remainingTime()); | ||
74 | System.out.println(t.get()); | ||
75 | } | ||
76 | Optional<PlayerID> w = s.winner(); | ||
77 | b = s.board(); | ||
78 | ps = s.isGameOver() ? s.alivePlayers() : s.players(); | ||
79 | System.out.println(w); | ||
80 | } | ||
81 | } | ||