Skip to content

Commit

Permalink
Attempt to fix multiple lobbies running
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-tieu committed Aug 7, 2024
1 parent bfaddf3 commit 2c4a50b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,24 @@ connection.onmessage = function (evt) {

// When server is online, lobby ID should be displayed in the header of the html file under the title of the game
if('players' in obj) {
lobbyId = obj.lobbyId;
id = obj.playerID;
conn = obj.conn;
lobbyPlayerCount = obj.playerCount;
var t = obj.lobbyId;
if(t) {
console.log("Lobby ID retrieved successfully");
document.getElementById("topMessage").innerHTML = "Lobby: " + t;
if(lobbyId == obj.lobbyId && id == obj.playerID) {
document.getElementById("topMessage").innerHTML = "Lobby: " + t;
}
}
t = obj.playerID;
if(t) {
console.log("Player ID retrieved successfully");
document.getElementById("topMessage2").innerHTML = "Player: " + t;
}

lobbyId = obj.lobbyId;
lobbyPlayerCount = obj.playerCount;
}
else if('playerID' in obj) {
/*else if('playerID' in obj) {
var t = obj.playerID;
if(t) {
console.log("Player ID retrieved successfully");
Expand All @@ -66,7 +74,7 @@ connection.onmessage = function (evt) {
id = obj.playerID;
conn = obj.conn;
}
}*/
else if('roundNumber' in obj) {
var lobbyScreen = document.getElementById("lobbyScreen");
var gameScreen = document.getElementById("gameScreen");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/uta/cse3310/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void onOpen(WebSocket conn, ClientHandshake handshake) {
// search for a lobby needing a player
Lobby L = null;
for (Lobby i : ActiveLobbies) {
if (i.getPlayerCount() >= 1 && i.getPlayerCount() < 4) {
if ((i.getPlayerCount() >= 1 && i.getPlayerCount() < 4) && i.gameStatus == false) {
L = i;
System.out.println("FOUND AN ONGOING LOBBY");
}
Expand All @@ -121,12 +121,12 @@ public void onOpen(WebSocket conn, ClientHandshake handshake) {
}
else if(L.getGameStatus() == false) {
// join an existing Lobby
System.out.println("NOT A NEW LOBBY");
Player newPlayer = new Player("", connectionId, conn.toString());
String jsonString = gson.toJson(newPlayer);
conn.send(jsonString);
L.players.add(newPlayer);
L.setPlayerCount();
System.out.println("NOT A NEW LOBBY");
}
/*else {
L = new Lobby(lobbyId);
Expand Down

0 comments on commit 2c4a50b

Please sign in to comment.