diff --git a/README.md b/README.md
index 776747e..d6b5a49 100644
--- a/README.md
+++ b/README.md
@@ -29,6 +29,8 @@ To play singleplayer, simply press the singleplayer button, but note that there
To play multiplayer, simply find (or force) a friend to also load the site from your private IP or whatever other networking solution you may have, both enter your name on the home page. One of you needs to create a lobby and the other needs to join it with the buttons labled as such, press ready then bam, you're in a game. Turns are denoted by the colour on the person at the top left, if it's your turn. your name will be green, if it's theirs, their name will be blue.
+PLEASE REMEMBER TO RESTART THE SERVER IF THE HOST OF THE GAME DISCONNECTS DURING THE GAME
+
### Implementation Rationale
These are some of my thoughts behind why I implemeneted stuff the way I did. To see more, take a look at TODO.
diff --git a/client/public/scrabble/game.js b/client/public/scrabble/game.js
index a63dbb7..50b0fde 100644
--- a/client/public/scrabble/game.js
+++ b/client/public/scrabble/game.js
@@ -155,6 +155,54 @@ function processTurn(turn)
{
removeStagedPieces();
renderBoardState(turn.boardtiles);
+
+ /*
+ OUTCOME OBJECT
+ {
+ valid: bool,
+ points: pointsgained,
+ words: [{
+ word: word,
+ points: points,
+ tiles: [{
+ pos: {x: x, y: y},
+ modifier: modifier,
+ letter: letter,
+ score: int
+ }]
+ }],
+ }
+ */
+ const outcome = turn.outcome;
+
+ if (!outcome.valid) return;
+
+ // GAMEUSERS OBJECT
+ // {
+ // uid: uid,
+ // name: name,
+ // score: int,
+ // me: bool,
+ // turn: bool
+ // }
+ // NOTES
+
+ let newpoints = 0;
+
+ let lastuser = {};
+ for (const user in Users)
+ {
+ if(Users[user].uid != turn.playeruid) continue;
+ Users[user].score += turn.outcome.points;
+ lastuser = Users[user];
+ }
+
+ changePlayerScore(lastuser.uid, lastuser.score);
+
+ for (const word of turn.outcome.words)
+ {
+ addTurnDesc(word.word, lastuser.name, word.points);
+ }
}
function newPieces(pieces)
diff --git a/client/public/scrabble/index.html b/client/public/scrabble/index.html
index 0a446c8..0af2ed2 100644
--- a/client/public/scrabble/index.html
+++ b/client/public/scrabble/index.html
@@ -24,12 +24,12 @@
:
-
+
diff --git a/client/public/scrabble/network.js b/client/public/scrabble/network.js
index 6c3ec2d..b820acf 100644
--- a/client/public/scrabble/network.js
+++ b/client/public/scrabble/network.js
@@ -282,7 +282,14 @@ function netSkipTurn()
function onTurnError(socket, args)
{
console.log('error', args);
- alert('Error in your turn: ' + args.error);
+ if (args.error === 'error-game-word-not-exist')
+ {
+ alert(`${args.word} is not a word!`);
+ } else
+ {
+ alert('Error in your turn: ' + args.error);
+ }
+ putPiecesBack();
}
function onturnProcessed(socket, args)
diff --git a/client/public/scrabble/pieces.js b/client/public/scrabble/pieces.js
index 75a74da..e8a448f 100644
--- a/client/public/scrabble/pieces.js
+++ b/client/public/scrabble/pieces.js
@@ -63,6 +63,18 @@ function removePiecesFromDrawer(pieces)
}
}
+function putPiecesBack()
+{
+ for (const piece of document.querySelectorAll('.staged-piece'))
+ {
+ piece.classList.remove('staged-piece');
+ piece.classList.remove('small-piece');
+ delete piece.dataset.coords;
+
+ DrawerSounds[Math.floor(Math.random() * 3)].play();
+ }
+ setupPieces();
+}
function updateBoardCoords()
{
diff --git a/client/public/scrabble/ui.js b/client/public/scrabble/ui.js
index 85fd185..e2caa9d 100644
--- a/client/public/scrabble/ui.js
+++ b/client/public/scrabble/ui.js
@@ -1,9 +1,9 @@
// DOES NOT DEAL WITH GAME BOARD
// chat
-const ChatBox = document.querySelector('#game-chat');
-const ChatMessageBox = document.querySelector('#game-chat-input');
-const ChatMessageSubmit = document.querySelector('#game-chat-button');
+// const ChatBox = document.querySelector('#game-chat');
+// const ChatMessageBox = document.querySelector('#game-chat-input');
+// const ChatMessageSubmit = document.querySelector('#game-chat-button');
// players
const IPlayerScores = document.querySelectorAll('.player-scores');
@@ -22,7 +22,7 @@ function initUI()
e.innerHTML = '';
});
PlayLog.innerHTML = '';
- ChatBox.value = '';
+ // ChatBox.value = '';
IExchangeButton.forEach(e => {
e.disabled = true;
@@ -90,6 +90,15 @@ function updateUsersUI(users)
}
}
+function changePlayerScore(playeruid, score)
+{
+ document.querySelectorAll(`.player${playeruid}`).forEach(e => {
+ const scoreElement = e.querySelector('.player-score');
+ scoreElement.innerText = score;
+ });
+}
+
+
function startMyTurnUI()
{
for (const piece of document.querySelectorAll('piece, nopiece'))
@@ -169,17 +178,7 @@ function onPlayTurn()
}
}
-function onMessageSend()
+function addTurnDesc(word, player, points )
{
-
-}
-
-function onTurnProcess()
-{
-
-}
-
-function onTurnPlay(oldturnuser, newturnuser, newboardstate)
-{
-
+ PlayLog.innerText += `${player} played ${word} for ${points} points!\n`;
}
diff --git a/server/src/game-logic.js b/server/src/game-logic.js
index 7c79558..eb887c1 100644
--- a/server/src/game-logic.js
+++ b/server/src/game-logic.js
@@ -411,13 +411,27 @@ function PlayTurn(gameuid, playeruid, turn)
}
// check dictionary
- for (const word in wordbasic)
+ for (const word in wordsbasic)
{
- let reversedword = word.split('').reverse().join('');
-
+ let reversedword = wordsbasic[word].split('').reverse().join('');
+ const doesexist = Dict.FindWord(game.locale, wordsbasic[word].toUpperCase());
+ const doesreversedexist = Dict.FindWord(game.locale, reversedword.toUpperCase());
+ if (!doesexist && !doesreversedexist)
+ {
+ const error = {
+ error: 'error-game-word-not-exist',
+ word: wordsbasic[word]
+ };
+ return [error, undefined, undefined, undefined]
+ }
+ if (doesreversedexist)
+ {
+ wordsbasic[word] = reversedword;
+ words[word].reverse();
+ }
+ Logger.game(`WORD ${wordsbasic[word]} FOUND`);
}
-
// update tiles with scores
turn.boardtiles = turn.oldboardtiles.concat(turn.boardtiles);
for (const tile in turn.boardtiles)
@@ -496,6 +510,7 @@ function PlayTurn(gameuid, playeruid, turn)
}
turn.outcome = outcome;
+ gameplayer.score += outcome.points;
ActiveGames[gameuid].gamestates.push(turn);
ActiveGames[gameuid].turn = turninfo.newTurn;
ActiveGames[gameuid].turntotal = turninfo.newTotalTurn;