From 03a6be12726147c494e145b543230ecbf64905e7 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Sun, 8 May 2016 14:15:26 +0200 Subject: Debug the GameStateDeserializer Class --- .../epfl/xblast/client/GameStateDeserializer.java | 35 ++++++++++++---------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/ch/epfl/xblast/client/GameStateDeserializer.java b/src/ch/epfl/xblast/client/GameStateDeserializer.java index f95c515..66be2d9 100644 --- a/src/ch/epfl/xblast/client/GameStateDeserializer.java +++ b/src/ch/epfl/xblast/client/GameStateDeserializer.java @@ -28,8 +28,9 @@ public final class GameStateDeserializer { * Serialized data chunks */ private final static int NUMBER_OF_PLAYERS = 4; - private final static int PLAYER_CHUNK_SIZE = 6; - private final static int PLAYER_SIZE = NUMBER_OF_PLAYERS * PLAYER_CHUNK_SIZE; + private final static int PLAYER_CHUNK_SIZE = 4; + private final static int PLAYER_TOTAL_SIZE = NUMBER_OF_PLAYERS * PLAYER_CHUNK_SIZE; + private final static int TIME_LINE_SIZE = (Ticks.GAME_DURATION / 2); /** @@ -55,10 +56,10 @@ public final class GameStateDeserializer { } /** - * Build a list of players given the serialized data.. + * Build a list of players given the serialized data. * * @param serializedPlayers the serialized players - * @return a list of players built from the serialized players + * @return a list of players built from the serialized data */ private static List deserializePlayers(List serializedPlayers) { List players = new ArrayList<>(); @@ -75,10 +76,10 @@ public final class GameStateDeserializer { } /** - * Generate a Player from the serialized data. + * Generate a Player from its serialized data. * * @param serializedPlayer a serialized player - * @return a player built from the serialized player + * @return a player built from its serialized data */ private static Player deserializePlayer(List serializedPlayer, int i) { PlayerID id = PlayerID.values()[i]; @@ -126,6 +127,7 @@ public final class GameStateDeserializer { playerScore.add(imageCollection.imageOrNull(SCORE_TEXT_RIGHT_IMAGE_ID)); return playerScore; } + /** * Generate the list of images composing the time "line". * @@ -153,28 +155,29 @@ public final class GameStateDeserializer { */ public static GameState deserialize(List serializedData) { - // Indexes - int boardIndex = 1; - int boardSize = serializedData.get(boardIndex); - int explosionsIndex = boardIndex + boardSize; - int explosionsSize = serializedData.get(explosionsIndex); - int playersIndex = explosionsIndex + explosionsSize; - Byte time = serializedData.get(serializedData.size()); + // Build the indexes + int boardBeginIndex = 0; // First element + int boardEndIndex = (boardBeginIndex) + Byte.toUnsignedInt(serializedData.get(boardBeginIndex)); + int explosionsBeginIndex = boardEndIndex + 1; + int explosionsEndIndex = explosionsBeginIndex + Byte.toUnsignedInt(serializedData.get(explosionsBeginIndex)); + int playersBeginIndex = explosionsEndIndex + 1; + int playersEndIndex = (playersBeginIndex - 1) + PLAYER_TOTAL_SIZE; + Byte time = serializedData.get(playersEndIndex + 1); // Last element // Deserialize the Board List board = deserializeChunk( - serializedData.subList(boardIndex, boardSize), + serializedData.subList(boardBeginIndex + 1, boardEndIndex + 1), new ImageCollection(BOARD_IMAGES_FOLDER) ); // Deserialize the explosions List explosions = deserializeChunk( - serializedData.subList(boardIndex,boardSize), + serializedData.subList(explosionsBeginIndex + 1,explosionsEndIndex + 1), new ImageCollection(EXPLOSION_IMAGES_FOLDER) ); // Deserialize the players - List players = deserializePlayers(serializedData.subList(playersIndex,PLAYER_SIZE)); + List players = deserializePlayers(serializedData.subList(playersBeginIndex,playersEndIndex + 1)); // Generate the scores and the time "line" List scores = buildScores(players); -- cgit v1.2.3