// Update title to reflect the current version
// var titleVersion = " "; // Add the JSON variable for the string
// document.getElementById("title").innerHTML = titleVersion; // Set the title as the titleVersion
-
- document.title = "group 24: " + message.versionNumber;
};
socket.onmessage = function(event) {
console.log('Message from server: ' + event.data);
const message = JSON.parse(event.data);
-
+
switch(message.type){
- case 'typehash':
- document.title = "group 24: " + message.versionNumber;
- break;
-
case 'Grid':
console.log("Grid recieved");
displayWordSearch(message.grid);
@@ -143,32 +137,14 @@
var playerColor = document.getElementById("playerColor").value;
if(playerName === message.player1.PlayerName || playerName === message.player2.PlayerName){
playerName = message.FindersName;
-
- var foundWord = message.WordsUsed[message.FoundWordIndex];
- console.log("found word = " + foundWord);
-
if(playerName === message.player1.PlayerName){
playerColor = message.player1.PlayerColor;
- playerName = message.player1.PlayerName;
- if(message.FoundWordIndex != -1){
- var leftbox = document.getElementById("leftbox");
- var messageElement = document.createElement("div");
- messageElement.textContent = "FOUND: " + foundWord;
- leftbox.appendChild(messageElement);
- }
}else{
playerColor = message.player2.PlayerColor;
- playerName = message.player2.PlayerName;
- if(message.FoundWordIndex != -1){
- var rightbox = document.getElementById("rightbox");
- var messageElement = document.createElement("div");
- messageElement.textContent = "FOUND: " + foundWord;
- rightbox.appendChild(messageElement);
- }
}
- crossOutWord(message.FoundWordIndex, message.cIndex1, message.rIndex1, message.cIndex2, message.rIndex2, playerColor, playerName, message.WordsUsed);
- //FUNCTION TO ADD FOUND WORD TO SIDE LIST
+ crossOutWord(message.FoundWordIndex, message.cIndex1, message.rIndex1, message.cIndex2, message.rIndex2, playerColor);
+ //FUNCTION TO ADD FOUND WORD TO SIDE LISTS
}
break;
@@ -180,7 +156,6 @@
if(FoundWordIndex != -1){
//Cross Out Word in wordbank IF found word was correct
var wordBank = document.getElementById('WordBank');
-
wordBank.children[FoundWordIndex].classList.add('crossed-out');
- wordBank.children[FoundWordIndex].style.color = playerColor;
-
+
+
//Create line of highlighted boxes to fill out the whole word
for(var i = 0; i < Math.max(Math.abs(ColDiff), Math.abs(RowDiff)); i++){
cell.style.backgroundColor = playerColor;
@@ -561,10 +524,8 @@
}
cell = row.cells[cIndex1];
cell.style.backgroundColor = playerColor;
-
-
}
- socket.send("Leaderboard " + playerName + " ");
+
}else{
//If FoundWordIndex was -1 that means no correct word was found so selected sqaure goes back
//to default color