Skip to content
Snippets Groups Projects
Commit 370b2b8c authored by Makarios Abouseif's avatar Makarios Abouseif
Browse files

Updated the cookies to save the progress of the Opponent's board as well, the...

Updated the cookies to save the progress of the Opponent's board as well, the cookies expire after 10 minutes of the last update.
parent 0013f759
Branches
No related tags found
1 merge request!4Merging into Master
......@@ -310,6 +310,19 @@
}
}
}
// Saves and pulls the Opponents's gameboard progress after refreshing
let enteredOppColors = [];
if (checkCookie("enteredOppColors")) {
enteredOppColors = getCookie("enteredOppColors").split(",");
for (let idx in enteredOppColors) {
let currentOppColors = enteredOppColors[idx].split("-");
let oppGuess = document.getElementById(`opponent-guess-${idx}`);
for (let [index, cell] of oppGuess.childNodes.entries()) {
cell.style.backgroundColor = colorDict[Number(currentOppColors[index])];
}
}
}
socket.on("correct word", () => {
alert("Correct word!");
let currentGuess = document.getElementById(`guess-${guessNum++}`);
......@@ -350,7 +363,7 @@
correct++;
}
}
enteredOppColors.push(colors.join('-'));
if (correct === 5) {
if (playerFirst === 0) {
oppFirst = 1;
......@@ -363,6 +376,7 @@
oScore.innerText = `OPPONENT'S SCORE: ${oppScore}`;
setCookie("oppScore", oppScore, 10);
setCookie("oppGuessNum", oppGuessNum, 10);
setCookie("enteredOppColors", enteredOppColors.join(), 10);
});
socket.on("incorrect word", (colors) => {
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment