Skip to content

Commit

Permalink
Merge branch 'Game_Class' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
muktar1907 authored Apr 23, 2024
2 parents 3c1cebb + 15734f2 commit 1643ce8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@
<div>
<label for="gameSelect">Game:</label>
<select id="gameSelect">

<option value="game1">Game1</option>
<option value="game2">Game2</option>
<option value="game3">Game3</option>
<option value="game4">Game4</option>
<option value="game5">Game5</option>


</select>
</div>
<div>
<label for="modeSelect">Game Mode:</label>
<select id="modeSelect">

<option value="2players">2 Players</option>
<option value="3players">3 Players</option>
<option value="4players">4 Players</option>

</select>
</div>
<button id="confirmButton">CONFIRM</button>
Expand All @@ -55,6 +59,7 @@ <h1>The Word Search Game</h1>
<script>
var socket = new WebSocket("ws://localhost:9105");


socket.onopen = function(evt) {
console.log("Open");
requestGameList();
Expand All @@ -74,6 +79,7 @@ <h1>The Word Search Game</h1>
document.getElementById("topMessage").innerText = "Server Offline";
};


socket.onerror = function(evt) {
console.error("WebSocket error: " + evt.message);
};
Expand Down Expand Up @@ -148,18 +154,22 @@ <h1>The Word Search Game</h1>
requestGameList();
});


//generate 35*35 grid

//too big may have to do smaller grid or smaller cells
function generateGrid()
{
const tbl = document.createElement("table");
const tblBody = document.createElement("tbody");
//create cells

for(let i=0;i<=35;i++)
{
//create rows
const row = document.createElement("tr");
for(let j=0;j<=35;j++)

{
//create cells and add it to the row
const cell = document.createElement("td");
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/uta/cse3310/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,30 @@ public void onMessage(WebSocket conn, String message) {
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
UserEvent U = gson.fromJson(message,UserEvent.class);
System.out.println(U.cell+ "was selected");
insertInnerMap(U,everyAttempt);

if(U.action==2)
{
ArrayList<UserEvent> attempt= new ArrayList<UserEvent>();
attempt=everyAttempt.get(U.gameId).get(U.player.getNick());
Game G = null;
for(Game i : activeGames)
{
if(i.getGameID().equals(U.gameId))
{
G = i;
G.updateGame(attempt);
break;
}
}
String jsonString;
jsonString = gson.toJson(G);

System.out.println(jsonString);
broadcast(jsonString);
}



}
Expand Down

0 comments on commit 1643ce8

Please sign in to comment.