Skip to content

Commit

Permalink
Merge pull request #24 from utastudents/main
Browse files Browse the repository at this point in the history
Update Game_Class
  • Loading branch information
muktar1907 authored Apr 24, 2024
2 parents 201b8f3 + 22ed2ce commit 0efacce
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,23 @@ <h1>The Word Search Game</h1>


var gameId;
var player = new Player;
var player;

class Player
{
nick;
score;
status;
totalPoints;
gameWins;
nick="";
score=0;
//status;
totalPoints=0;
gameWins=0;
}

class UserEvent
{
gameId;
player;
cell;
action;
gameId=-1;
player="";
cell=-1;
action=-1;
}

function requestGameList() {
Expand Down Expand Up @@ -153,7 +153,8 @@ <h1>The Word Search Game</h1>
gameIndex: gameIndex,
modeIndex: mode
};
//socket.send(JSON.stringify(data));

socket.send(JSON.stringify(data));
}

// replace leaveGame function with one that sends a WebSocket message
Expand Down Expand Up @@ -196,8 +197,8 @@ <h1>The Word Search Game</h1>
//create cells and add it to the row
const cell = document.createElement("td");
cell.setAttribute("id",k.toString());
cell.onclick=buttonClick(k,1);
cell.onmouseover=buttonClick(k,2);


const cellText=document.createTextNode(`${k}`);
cell.appendChild(cellText);
row.appendChild(cell);
Expand All @@ -209,16 +210,43 @@ <h1>The Word Search Game</h1>
tbl.appendChild(tblBody);
document.body.appendChild(tbl);
tbl.setAttribute("border","1.5");
eventListener();

}

function buttonClick(cell,action)
function eventListener()
{
var cells = document.querySelectorAll("td");
for(var i=0;i<cells.length;i++)
{
cells[i].addEventListener("click",function()
{
buttonEvent(this.getAttribute("id"),0);
});
cells[i].addEventListener("mouseover",function()
{
buttonEvent(this.getAttribute("id"),1);
});
cells[i].addEventListener("mouseover",function()
{
buttonEvent(this.getAttribute("id"),2);
});

}
}
function buttonEvent(cell,action)
{
let button= document.getElementById(cell);
button.style.backgroundColor="blue";
U = new UserEvent();
U.cell=cell;
U.cell=parseInt(cell);
U.action=action;
U.player=player;
U.gameId=gameId;

var data = {
type: "UpdateGame",
events: U
};
socket.send(JSON.stringify(U));
console.log(JSON.stringify(U));
}
Expand Down

0 comments on commit 0efacce

Please sign in to comment.