diff --git a/client/public/scrabble/board.js b/client/public/scrabble/board.js index 0fc5098..de3c12a 100644 --- a/client/public/scrabble/board.js +++ b/client/public/scrabble/board.js @@ -10,67 +10,67 @@ const BoardLookup = { // This was automatically generated, the code for it is lonnnggg gone const BoardLocations = { - "0,0": "TW", - "0,3": "DL", - "0,7": "TW", - "0,11": "DL", - "0,14": "TW", - "1,1": "DW", - "1,5": "TL", - "1,9": "TL", - "1,13": "DW", - "2,2": "DW", - "2,6": "DL", - "2,8": "DL", - "2,12": "DW", - "3,0": "DL", - "3,3": "DW", - "3,7": "DL", - "3,11": "DW", - "3,14": "DL", - "4,4": "DW", - "4,10": "DW", - "5,1": "TL", - "5,5": "TL", - "5,9": "TL", - "5,13": "TL", - "6,2": "DL", - "6,6": "DL", - "6,8": "DL", - "6,12": "DL", - "7,0": "TW", - "7,3": "DL", - "7,7": "★", - "7,11": "DL", - "7,14": "TW", - "8,2": "DL", - "8,6": "DL", - "8,8": "DL", - "8,12": "DL", - "9,1": "TL", - "9,5": "TL", - "9,9": "TL", - "9,13": "TL", - "10,4": "DW", - "10,10": "DW", - "11,0": "DL", - "11,3": "DW", - "11,7": "DL", - "11,11": "DW", - "11,14": "DL", - "12,2": "DW", - "12,6": "DL", - "12,8": "DL", - "12,12": "DW", - "13,1": "DW", - "13,5": "TL", - "13,9": "TL", - "13,13": "DW", - "14,0": "TW", - "14,3": "DL", - "14,7": "TW", - "14,11": "DL", - "14,14": "TW" + '0,0': 'TW', + '0,3': 'DL', + '0,7': 'TW', + '0,11': 'DL', + '0,14': 'TW', + '1,1': 'DW', + '1,5': 'TL', + '1,9': 'TL', + '1,13': 'DW', + '2,2': 'DW', + '2,6': 'DL', + '2,8': 'DL', + '2,12': 'DW', + '3,0': 'DL', + '3,3': 'DW', + '3,7': 'DL', + '3,11': 'DW', + '3,14': 'DL', + '4,4': 'DW', + '4,10': 'DW', + '5,1': 'TL', + '5,5': 'TL', + '5,9': 'TL', + '5,13': 'TL', + '6,2': 'DL', + '6,6': 'DL', + '6,8': 'DL', + '6,12': 'DL', + '7,0': 'TW', + '7,3': 'DL', + '7,7': '★', + '7,11': 'DL', + '7,14': 'TW', + '8,2': 'DL', + '8,6': 'DL', + '8,8': 'DL', + '8,12': 'DL', + '9,1': 'TL', + '9,5': 'TL', + '9,9': 'TL', + '9,13': 'TL', + '10,4': 'DW', + '10,10': 'DW', + '11,0': 'DL', + '11,3': 'DW', + '11,7': 'DL', + '11,11': 'DW', + '11,14': 'DL', + '12,2': 'DW', + '12,6': 'DL', + '12,8': 'DL', + '12,12': 'DW', + '13,1': 'DW', + '13,5': 'TL', + '13,9': 'TL', + '13,13': 'DW', + '14,0': 'TW', + '14,3': 'DL', + '14,7': 'TW', + '14,11': 'DL', + '14,14': 'TW' }; function flip(y, size) @@ -91,7 +91,7 @@ window.onload = e => { let localeThing = BoardLocations[location]; // hacky but it works - if (localStorage.getItem('locale') === "es" || localStorage.getItem('locale') === "pt") + if (localStorage.getItem('locale') === 'es' || localStorage.getItem('locale') === 'pt') { localeThing = localeThing.replace('W', 'P'); } diff --git a/client/public/scrabble/game.js b/client/public/scrabble/game.js index 6230b82..7b98df3 100644 --- a/client/public/scrabble/game.js +++ b/client/public/scrabble/game.js @@ -23,8 +23,10 @@ let MyTurn = false; let pastTurns = []; -function initGame(boardstate, tileset, myplayer, players) +function initGame(oldboardstates, boardstate, tileset, myplayer, players) { + pastTurns = oldboardstates; + // construct piece array // structure [{letter: '', score: int}] let drawerStructure = []; @@ -92,7 +94,21 @@ function playMyTurn(stagedpieces) { if (!MyTurn) return false; - + // TODO: THE SERVER SHOULD NOTTTTTT TRUST THIS + // but the it's 7pm on the sunday before the deadline + let boardtiles = [pastTurns[pastTurns.length-1]]; + for (const piece of stagedpieces) + { + const pos = JSON.parse(piece.dataset.coords); + boardtiles.push({ + pos: pos, + modifier: BoardLocations[`${pos.x},${pos.y}`] || 'NONE', + letter: piece.dataset.letter, + // TBD (by the server) + score: -1 + }); + console.log(piece); + } const turn = { playeruid: Users.filter(e => e.me)[0].uid, @@ -101,9 +117,10 @@ function playMyTurn(stagedpieces) turntype: 'PLACE', // servers job outcome: {}, + oldboardtiles: pastTurns[pastTurns.length-1], + boardtiles: boardtiles } - console.log(stagedpieces); console.log(turn); return true; diff --git a/client/public/scrabble/network.js b/client/public/scrabble/network.js index 97ba789..5d983e2 100644 --- a/client/public/scrabble/network.js +++ b/client/public/scrabble/network.js @@ -30,6 +30,7 @@ function initMultiplayer() socket.on('game-begin', args => onGameBegin(socket, args)); socket.on('game-your-turn', args => onStartTurn(socket, args)); // my turn socket.on('game-turn-start', args => onTurnStart(socket, args)); // others turn + socket.on('game-new-pieces', args => onTurnStart(socket, args)); console.log('multiplayer ready'); } @@ -201,20 +202,21 @@ function onGameBegin(socket, args) } console.log(args); + const oldboardstates = args.game; const boardstate = args.game.gamestates[args.game.gamestates.length-1]; const tileset = args.tileset; const myplayer = args.gameuser; const players = args.game.players; - if (!boardstate || !myplayer || !players || !tileset) + if (!oldboardstates || !boardstate || !myplayer || !players || !tileset) { ConnectionState.forEach(e => { e.innerHTML = localeString('error-game-begin'); - }); + }); return; } - const status = initGame(boardstate, tileset, myplayer, players); + const status = initGame(oldboardstates, boardstate, tileset, myplayer, players); if (!status) { diff --git a/client/public/scrabble/pieces.js b/client/public/scrabble/pieces.js index 4351bca..12dd9ed 100644 --- a/client/public/scrabble/pieces.js +++ b/client/public/scrabble/pieces.js @@ -34,6 +34,9 @@ function addPiecesToDrawer(pieces) const score = document.createElement('score'); score.innerText = piece.score; + domPiece.dataset.letter = piece.letter; + domPiece.dataset.score = piece.score; + domPiece.appendChild(score); Drawer.appendChild(domPiece); @@ -116,6 +119,8 @@ function renderBoardState(pieces) score.innerText = piece.score; domPiece.dataset.coords = JSON.stringify(piece.pos); + domPiece.dataset.letter = piece.letter; + domPiece.dataset.score = piece.score; domPiece.appendChild(score); Drawer.appendChild(domPiece); diff --git a/client/public/scrabble/ui.js b/client/public/scrabble/ui.js index 796bad4..58d197b 100644 --- a/client/public/scrabble/ui.js +++ b/client/public/scrabble/ui.js @@ -73,7 +73,7 @@ function updateUsersUI(users) function onExchangeTiles() { - let tiles = prompt('Enter the tiles you would like to exchange seperated by commas (this will use your turn)') + let tiles = prompt('Enter the tiles you would like to exchange seperated by commas or type all for all of them (this will use your turn)') // no error, user escaped do not change state if (tiles === null)