Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
ixk3065 committed Apr 29, 2024
1 parent 3637327 commit af12165
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
5 changes: 2 additions & 3 deletions html/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ connection.onmessage = function(event){
console.log("sublobby error");
handleSubLobbyError();
break;
case 'StartGame':
showGame(data);
break;
//case 'resetLobbyState':
// console.log("Lobby state reset.");
// break;
Expand All @@ -68,6 +65,8 @@ connection.onmessage = function(event){
break;
case 'matrixCreated':
generateGrid(json.eventData);
showGame();
break;
default:
console.log("Unknown message type:", data.type);
}
Expand Down
38 changes: 16 additions & 22 deletions src/main/java/uta/cse3310/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ public void onMessage(WebSocket conn, String message) {
break;

case "startGame":
System.out.println("Server side game Started");
// Additional game start logic here
System.out.println("Game data sent to client");
startGame(conn);
break;

case "resetLobbyState":
Expand Down Expand Up @@ -209,30 +207,26 @@ public void toggleReady(WebSocket conn) {
}


private void startGame(SubLobby subLobby) {
// Logic to start the game goes here
subLobby.getGameMatrix();// Assume this prepares the game
}
/*private String convertMatrixToJson(char[][] matrix) {
JsonObject obj = new JsonObject();
JsonArray rows = new JsonArray();
for (char[] row : matrix) {
JsonArray jsonRow = new JsonArray();
for (char c : row) {
jsonRow.add(Character.toString(c));
public void startGame(WebSocket conn) {
for (SubLobby subLobby : ActiveGames) {
// Loop through all players in the current sublobby
for (Player player : subLobby.getPlayers()) {
if (player.getConn().equals(conn)) {
if (subLobby.allPlayersReady() && subLobby.getPlayers().size() == subLobby.getSubLobbySize()) {
startGameSilently(subLobby);
return;
}
}
}
rows.add(jsonRow);
}
obj.add("grid", rows);
obj.addProperty("type", "gameStateUpdate");
return obj.toString();
}*/
private String convertMatrixToJson(char[][] matrix){
}
}

public String convertMatrixToJson(char[][] matrix){
Gson gson =new Gson();
String json=gson.toJson(matrix);
return json;
}
private void startGameSilently(SubLobby subLobby) {
public void startGameSilently(SubLobby subLobby) {
JsonObject json = new JsonObject();
json.addProperty("type", "matrixCreated");

Expand Down
1 change: 1 addition & 0 deletions src/main/java/uta/cse3310/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ public String getGridAndWordsAsJson() {
}
//d


}


Expand Down

0 comments on commit af12165

Please sign in to comment.