diff --git a/src/main/java/uta/cse3310/App.java b/src/main/java/uta/cse3310/App.java index 48de92b..36fecf1 100644 --- a/src/main/java/uta/cse3310/App.java +++ b/src/main/java/uta/cse3310/App.java @@ -52,7 +52,7 @@ public void onMessage(WebSocket conn, String message) { PlayerType player = new PlayerType(username, userColor, null); // try to add player using then check for lobby capacity - if (lobby.tryAddPlayer(player)) { + if (lobby.addPlayer(player)) { System.out.println(username + " added to the lobby."); broadcastLobbyUpdate(); //update all clients about the new player } else { diff --git a/src/main/java/uta/cse3310/Leaderboard.java b/src/main/java/uta/cse3310/Leaderboard.java index abf52dd..965c7f2 100644 --- a/src/main/java/uta/cse3310/Leaderboard.java +++ b/src/main/java/uta/cse3310/Leaderboard.java @@ -23,14 +23,12 @@ public void addOrUpdatePlayer(PlayerType player, int score) { public List getSortedPlayers() { List> sortedEntries = new ArrayList<>(playerScores.entrySet()); sortedEntries.sort(Map.Entry.comparingByValue().reversed()); - - //Extract players for returning + List sortedPlayers = new ArrayList<>(); for (Map.Entry entry : sortedEntries) { sortedPlayers.add(entry.getKey()); } return sortedPlayers; - } // Displays the leaderboard @@ -46,4 +44,8 @@ public void display() { public void reset() { playerScores.clear(); } + + public Map getPlayerScores() { + return new HashMap<>(playerScores); + } } diff --git a/src/main/java/uta/cse3310/Lobby.java b/src/main/java/uta/cse3310/Lobby.java index 750947b..b13710f 100644 --- a/src/main/java/uta/cse3310/Lobby.java +++ b/src/main/java/uta/cse3310/Lobby.java @@ -12,8 +12,8 @@ public Lobby() { } // Method to add a player to the lobby - public void addPlayer(PlayerType player) { - players.add(player); + public boolean addPlayer(PlayerType player) { + return players.add(player); } // Method to remove a player from the lobby