From b0356d4ff6694ccc7f8fae1766b73b0e99c78ed9 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Tue, 8 Mar 2016 23:16:12 +0100 Subject: Import NameCheck04 and GaneStatePrinter (given files for the week 4) --- .../epfl/xblast/server/debug/GameStatePrinter.java | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/ch/epfl/xblast/server/debug/GameStatePrinter.java (limited to 'src') 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 @@ +package ch.epfl.xblast.server.debug; + +import java.util.List; + +import ch.epfl.xblast.Cell; +import ch.epfl.xblast.server.Block; +import ch.epfl.xblast.server.Board; +import ch.epfl.xblast.server.GameState; +import ch.epfl.xblast.server.Player; + +public final class GameStatePrinter { + private GameStatePrinter() {} + + public static void printGameState(GameState s) { + List ps = s.alivePlayers(); + Board board = s.board(); + + for (int y = 0; y < Cell.ROWS; ++y) { + xLoop: for (int x = 0; x < Cell.COLUMNS; ++x) { + Cell c = new Cell(x, y); + for (Player p: ps) { + if (p.position().containingCell().equals(c)) { + System.out.print(stringForPlayer(p)); + continue xLoop; + } + } + Block b = board.blockAt(c); + System.out.print(stringForBlock(b)); + } + System.out.println(); + } + } + + private static String stringForPlayer(Player p) { + StringBuilder b = new StringBuilder(); + b.append(p.id().ordinal() + 1); + switch (p.direction()) { + case N: b.append('^'); break; + case E: b.append('>'); break; + case S: b.append('v'); break; + case W: b.append('<'); break; + } + return b.toString(); + } + + private static String stringForBlock(Block b) { + switch (b) { + case FREE: return " "; + case INDESTRUCTIBLE_WALL: return "##"; + case DESTRUCTIBLE_WALL: return "??"; + case CRUMBLING_WALL: return "¿¿"; + case BONUS_BOMB: return "+b"; + case BONUS_RANGE: return "+r"; + default: throw new Error(); + } + } +} -- cgit v1.2.3