Use LinkedHashSets for players and obstacles to preserve order

This commit is contained in:
Liam Westby 2018-04-27 10:11:04 -05:00
parent a14608fb74
commit bd7b8917a4
2 changed files with 5 additions and 3 deletions

View File

@ -5,6 +5,7 @@ package org.libertybikes.game.core;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@ -24,8 +25,8 @@ public class GameBoard {
public final short[][] board = new short[BOARD_SIZE][BOARD_SIZE];
public final Set<Obstacle> obstacles = new HashSet<>();
public final Set<MovingObstacle> movingObstacles = new HashSet<>();
public final Set<Player> players = new HashSet<>();
public final Set<MovingObstacle> movingObstacles = new LinkedHashSet<>();
public final Set<Player> players = new LinkedHashSet<>();
private final boolean[] takenPlayerSlots = new boolean[Player.MAX_PLAYERS];
private GameMap gameMap;

View File

@ -7,6 +7,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.json.bind.Jsonb;
@ -98,7 +99,7 @@ public class JsonDataTest {
@Test
public void testPlayerList() {
Set<Player> players = new HashSet<>();
Set<Player> players = new LinkedHashSet<>();
players.add(new Player("123", "Bob", (short) 0, 9, 9));
PlayerList list = new OutboundMessage.PlayerList(players);
String bob = "{\"id\":\"123\",\"name\":\"Bob\",\"color\":\"#DF740C\",\"status\":\"Connected\",\"alive\":true,\"x\":9,\"y\":9,\"width\":3,\"height\":3,\"oldX\":9,\"oldY\":9,\"trailPosX\":10,\"trailPosY\":10,\"trailPosX2\":10,\"trailPosY2\":10}";