aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-03-15 13:44:43 +0100
committerPacien TRAN-GIRARD2016-03-15 13:44:43 +0100
commit59d35ae34c4513f54decf056e944190d7e9926f0 (patch)
tree171f642873369fcad4c3821994d1584d82450c35
parent741cb9da501b8c6e9e5fa006e5c2c9df0b4616f8 (diff)
downloadxblast-59d35ae34c4513f54decf056e944190d7e9926f0.tar.gz
Reformat provided classes
-rw-r--r--src/ch/epfl/xblast/server/debug/GameStatePrinter.java56
-rw-r--r--test/ch/epfl/xblast/namecheck/NameCheck04.java19
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 @@
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}
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 @@
1package ch.epfl.xblast.namecheck; 1package ch.epfl.xblast.namecheck;
2 2
3import java.util.List;
4import java.util.Optional;
5
6import ch.epfl.cs108.Sq; 3import ch.epfl.cs108.Sq;
7import ch.epfl.xblast.Cell; 4import ch.epfl.xblast.Cell;
8import ch.epfl.xblast.Lists; 5import ch.epfl.xblast.Lists;
9import ch.epfl.xblast.PlayerID; 6import ch.epfl.xblast.PlayerID;
10import ch.epfl.xblast.Time; 7import ch.epfl.xblast.Time;
11import ch.epfl.xblast.server.Block; 8import ch.epfl.xblast.server.*;
12import ch.epfl.xblast.server.Board; 9
13import ch.epfl.xblast.server.Bomb; 10import java.util.List;
14import ch.epfl.xblast.server.Bonus; 11import java.util.Optional;
15import ch.epfl.xblast.server.GameState;
16import ch.epfl.xblast.server.Player;
17import 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
25abstract class NameCheck04 { 20abstract 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}