diff --git a/client/public/scrabble/game.css b/client/public/scrabble/game.css index 7c06583..bdc3c5a 100644 --- a/client/public/scrabble/game.css +++ b/client/public/scrabble/game.css @@ -121,10 +121,18 @@ score { flex-grow: 2; } -.theirturn { +.myturn { background-color: aquamarine; } +.myturnprocessing { + background-color: lightcoral; +} + +.theirturn { + background-color: lightblue; +} + #game-controls { border: 1px dotted black; diff --git a/client/public/scrabble/game.js b/client/public/scrabble/game.js index 50f5b6f..98611ca 100644 --- a/client/public/scrabble/game.js +++ b/client/public/scrabble/game.js @@ -2,11 +2,23 @@ function computeTurn() { if (!isSingleplayer) return; - - } +/* +GAMEUSERS OBJECT +{ + uid: uid, + username: name, + turn: bool, + +} +NOTES + - In play order +*/ +let Users = {}; +let MyTurn = false; + function initGame(boardstate, tileset, myplayer, players) { // construct piece array @@ -46,3 +58,20 @@ function initGame(boardstate, tileset, myplayer, players) return true; } + +function startMyTurn() +{ + +} + +function + +function playMyTurn(stagedpieces) +{ + if (!MyTurn) return; +} + +function processOthersTurn() +{ + +} diff --git a/client/public/scrabble/network.js b/client/public/scrabble/network.js index c4eeafa..4b115a5 100644 --- a/client/public/scrabble/network.js +++ b/client/public/scrabble/network.js @@ -28,9 +28,10 @@ function initMultiplayer() socket.on('identify-error', args => onIdentifyError(socket, args)); socket.on('game-begin', args => onGameBegin(socket, args)); - socket.on('game-your-turn', args => onStartTurn(socket, args)); + socket.on('game-your-turn', args => onStartTurn(socket, args)); // my turn + socket.on('game-turn-start', args => onTurnStart(socket, args)); // others turn - console.log('multiplayer ready') + console.log('multiplayer ready'); } @@ -150,6 +151,8 @@ GAMESTATE OBJECT // UID of the player that played the turn playeruid: uid, turn: int, + // SKIP, PLACE, EXCHANGE + turntype: 'SKIP', // Generated after turn is processed outcome: { valid: bool, @@ -223,9 +226,14 @@ function onGameBegin(socket, args) function onStartTurn(socket, args) { - console.log('my turn') + console.log('my turn'); + startMyTurn(); } +function onTurnStart(socket, args) +{ + +} // is game singleplayer? let isSingleplayer = false; diff --git a/client/public/scrabble/ui.js b/client/public/scrabble/ui.js index 234d3be..a3607e1 100644 --- a/client/public/scrabble/ui.js +++ b/client/public/scrabble/ui.js @@ -37,9 +37,19 @@ function setupUsersUI(users, turn) e.innerHTML += elements.join(''); }); - document.querySelectorAll(`.p${turn}`).forEach(e => { - e.classList.toggle('theirturn'); - }); + console.log(users[turn].uid, JSON.parse(sessionStorage.getItem('user')).uid) + + if (MyTurn) + { + document.querySelectorAll(`.p${turn}`).forEach(e => { + e.classList.toggle('myturn'); + }); + } else + { + document.querySelectorAll(`.p${turn}`).forEach(e => { + e.classList.toggle('theirturn'); + }); + } } function updateUsersUI(users, turn) @@ -47,13 +57,33 @@ function updateUsersUI(users, turn) } +function changeTurn() +{ + if (MyTurn) { + + } +} function onExchangeTiles() { let tiles = prompt('Enter the tiles you would like to exchange seperated by commas (this will use your turn)') - tiles = tiles.split(','); - console.log(tiles); + // no error, user escaped do not change state + if (tiles === null) + return; + + try { + tiles = tiles.split(','); + // remove null entries + tiles = tiles.filter(x => x); + } catch (e) { + alert('Incorrect usage, remember tiles need to be split with a comma (,)'); + onExchangeTiles(); + return; + } + + + console.log(tiles); } function onSkipTurn() @@ -63,7 +93,9 @@ function onSkipTurn() function onPlayTurn() { - + // get all staged pieces + const stagedPieces = getAllStagedPieces(); + playMyTurn(stagedPieces); } function onMessageSend() diff --git a/server/src/game-logic.js b/server/src/game-logic.js index b3617a2..bdd97c6 100644 --- a/server/src/game-logic.js +++ b/server/src/game-logic.js @@ -31,6 +31,8 @@ GAMESTATE OBJECT // UID of the player that played the turn playeruid: uid, turn: int, + // SKIP, PLACE, EXCHANGE + turntype: 'SKIP', // Generated after turn is processed outcome: { valid: bool, @@ -120,6 +122,7 @@ function BeginGame(lobby) const gamestate = { playeruid: -1, turn: 0, + turntype: '', outcome: { valid: false }, @@ -146,6 +149,8 @@ TURN OBJECT - Un-filled in GAMESTATE object // UID of the player that played the turn playeruid: uid, turn: int, + // SKIP, PLACE, EXCHANGE + turntype: 'SKIP', // Generated after turn is processed outcome: { valid: bool, @@ -180,10 +185,12 @@ NOTES returning an error or a validation object including the next players turn */ +// Does not trust client's oldboardtiles function PlayTurn(gameuid, playeruid, newstate) { const game = ActiveGames[gameuid]; + } // returns tuple ([newtileset], [newusertiles])