diff --git a/html/index.html b/html/index.html index 30139fe..dc190b5 100644 --- a/html/index.html +++ b/html/index.html @@ -1,67 +1,112 @@ + - - - - - -
Waiting for players...
-
Players in Lobby:
- - - + Multiplayer Word Search Game + + + +
+ + + +
Waiting for players...
+
Players in Lobby:
+ + + +
+ - + connection.onclose = function () { + document.getElementById("topMessage").innerHTML = "Server Offline"; + }; + connection.onmessage = function (evt) { + var msg = JSON.parse(evt.data); + if (msg.action === "updateLobby") { + updateLobby(msg.players); + document.getElementById("lobby-status").innerHTML = "Waiting for other players..."; + } + }; + + function updateLobby(players) { + var playersList = "Players in Lobby: " + players.join(", "); + document.getElementById("players-in-lobby").innerHTML = playersList; + } + + document.getElementById("joinButton").addEventListener("click", function() { + var username = document.getElementById("username").value.trim(); + if (username) { + var joinRequest = { + action: "join", + username: username + }; + connection.send(JSON.stringify(joinRequest)); + document.getElementById("lobby-status").innerHTML = "Trying to join the game..."; + } else { + alert("Please enter a username."); + } + }); + + diff --git a/src/main/java/uta/cse3310/Lobby.java b/src/main/java/uta/cse3310/Lobby.java new file mode 100644 index 0000000..4c4cc70 --- /dev/null +++ b/src/main/java/uta/cse3310/Lobby.java @@ -0,0 +1,37 @@ +package uta.cse3310; + +import java.util.ArrayList; +import java.util.List; + +public class Lobby { + private List players; + + public Lobby() { + this.players = new ArrayList<>(); + } + + // Method to add a player to the lobby + public void addPlayer(PlayerType player) { + players.add(player); + } + + // Method to remove a player from the lobby + public void removePlayer(PlayerType player) { + players.remove(player); + } + + // Method to check if the lobby is full + public boolean isFull() { + return players.size() >= 4; // Maximum of 4 players + } + + // Method to get the list of players in the lobby + public List getPlayers() { + return players; + } + + // Method to reset the lobby + public void reset() { + players.clear(); + } +} diff --git a/target/classes/uta/cse3310/Lobby.class b/target/classes/uta/cse3310/Lobby.class new file mode 100644 index 0000000..a6ebae7 Binary files /dev/null and b/target/classes/uta/cse3310/Lobby.class differ