Skip to content

Commit

Permalink
added methods to help with testing files
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Fierro committed Apr 16, 2024
1 parent 3509276 commit 2fa7ea2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/uta/cse3310/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/uta/cse3310/Leaderboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ public void addOrUpdatePlayer(PlayerType player, int score) {
public List<PlayerType> getSortedPlayers() {
List<Map.Entry<PlayerType, Integer>> sortedEntries = new ArrayList<>(playerScores.entrySet());
sortedEntries.sort(Map.Entry.<PlayerType, Integer>comparingByValue().reversed());

//Extract players for returning

List<PlayerType> sortedPlayers = new ArrayList<>();
for (Map.Entry<PlayerType, Integer> entry : sortedEntries) {
sortedPlayers.add(entry.getKey());
}
return sortedPlayers;

}

// Displays the leaderboard
Expand All @@ -46,4 +44,8 @@ public void display() {
public void reset() {
playerScores.clear();
}

public Map<PlayerType, Integer> getPlayerScores() {
return new HashMap<>(playerScores);
}
}
4 changes: 2 additions & 2 deletions src/main/java/uta/cse3310/Lobby.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2fa7ea2

Please sign in to comment.