let remainingLetters = 0;
let needsRestart = false;
const gameInProgress = false;
+ let currentPlay = {};
let eventSource = null;
let webSocket = null;
movingTile.style.width = "";
movingTile.style.height = "";
+ /* Keep track of letter */
+ if (moveCMD.from === "rack") {
+ if (moveCMD.to === "board") {
+ currentPlay[moveCMD.indexTo] = "-";
+ }
+ } else { /* moveCMD.from === "board" */
+ if (moveCMD.to === "board") {
+ currentPlay[moveCMD.indexTo] = currentPlay[moveCMD.indexFrom];
+ }
+ delete currentPlay[moveCMD.indexFrom];
+ }
+
mouseUp(document, dragTileEnd, true);
mouseMove(document, dragTileMove, true);
? format(_("You changed the language of the board to {0}"), newLang)
: format(_("{0} changed the language of the board to {1}"), msg.sender, newLang)
);
+ dictionnary = JSON.parse();
return;
}
tablePlayers[currentPlayer].classList.remove("current-player");
}
+ currentPlay = {};
currentPlayer = player;
refreshCurrentPlayer();
}
break;
case "setCell":
setCell(data.indexTo, data.letter, Object.prototype.hasOwnProperty.call(data, "player") && data.player !== localStorage.trivabblePlayerName);
+ if ((data.letter !== "") && (currentPlay[data.indexTo] === "-")) {
+ currentPlay[data.indexTo] = data.letter;
+ }
break;
case "setRackCell":
setRackCell(data.indexTo, data.letter);
}
+ function getLetterFromBoard(row, col) {
+ if ((row < 0) || (row >= 15) || (col < 0) || (col >= 15)) return "";
+ let letter = "";
+ try {
+ let index = row * 15 + col;
+ let tilePlaceholder = boardCells[index].getElementsByClassName("tile-placeholder")[0];
+ let tile = tilePlaceholder.getElementsByClassName("tile")[0];
+ letter = tile.firstChild.textContent;
+ } catch (e) {}
+ return letter;
+ }
+
+ function searchWordInLine(row, col, incRow, incCol) {
+
+ while (getLetterFromBoard(row - incRow, col - incCol) !== "") {
+ row -= incRow;
+ col -= incCol
+ }
+
+ let word = "";
+ let letter;
+ while ((letter = getLetterFromBoard(row, col)) !== "") {
+ word += letter;
+ row += incRow;
+ col += incCol;
+ }
+ return (word.length > 1) ? word : "";
+ }
+
+ function computeWord() {
+ let str = "letter:";
+ for (let i in currentPlay) {
+ str += " " + currentPlay[i] + ": " + i;
+ }
+
+ let words = [];
+ for (let i in currentPlay) {
+ let row = Math.floor(i / 15);
+ let col = i % 15;
+ let newWord;
+ newWord = searchWordInLine(row, col, 1, 0);
+ if ((newWord !== "") && (!words.includes(newWord))) {
+ words.push(newWord);
+ }
+ newWord = searchWordInLine(row, col, 0, 1);
+ if ((newWord !== "") && (!words.includes(newWord))) {
+ words.push(newWord);
+ }
+ }
+
+ myConfirm(
+ _("Words found\n" + str + "\n" + words),
+ function () {}
+ );
+ }
+
function initChat() {
chatMessages.style.width = chatMessages.offsetWidth + "px";
document.getElementById("join-game").onclick = joinGame;
document.getElementById("clear-rack").onclick = clearRack;
document.getElementById("show-rack").onclick = showRack;
+ document.getElementById("compute-word").onclick = computeWord;
helpClear.onclick = clearGame;
}