turn display

This commit is contained in:
Ben Kyd
2021-05-09 15:52:29 +01:00
parent 73859987b5
commit eb557a0392
5 changed files with 96 additions and 12 deletions

View File

@@ -121,10 +121,18 @@ score {
flex-grow: 2; flex-grow: 2;
} }
.theirturn { .myturn {
background-color: aquamarine; background-color: aquamarine;
} }
.myturnprocessing {
background-color: lightcoral;
}
.theirturn {
background-color: lightblue;
}
#game-controls { #game-controls {
border: 1px dotted black; border: 1px dotted black;

View File

@@ -2,11 +2,23 @@
function computeTurn() function computeTurn()
{ {
if (!isSingleplayer) return; 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) function initGame(boardstate, tileset, myplayer, players)
{ {
// construct piece array // construct piece array
@@ -46,3 +58,20 @@ function initGame(boardstate, tileset, myplayer, players)
return true; return true;
} }
function startMyTurn()
{
}
function
function playMyTurn(stagedpieces)
{
if (!MyTurn) return;
}
function processOthersTurn()
{
}

View File

@@ -28,9 +28,10 @@ function initMultiplayer()
socket.on('identify-error', args => onIdentifyError(socket, args)); socket.on('identify-error', args => onIdentifyError(socket, args));
socket.on('game-begin', args => onGameBegin(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 // UID of the player that played the turn
playeruid: uid, playeruid: uid,
turn: int, turn: int,
// SKIP, PLACE, EXCHANGE
turntype: 'SKIP',
// Generated after turn is processed // Generated after turn is processed
outcome: { outcome: {
valid: bool, valid: bool,
@@ -223,9 +226,14 @@ function onGameBegin(socket, args)
function onStartTurn(socket, args) function onStartTurn(socket, args)
{ {
console.log('my turn') console.log('my turn');
startMyTurn();
} }
function onTurnStart(socket, args)
{
}
// is game singleplayer? // is game singleplayer?
let isSingleplayer = false; let isSingleplayer = false;

View File

@@ -37,9 +37,19 @@ function setupUsersUI(users, turn)
e.innerHTML += elements.join(''); e.innerHTML += elements.join('');
}); });
document.querySelectorAll(`.p${turn}`).forEach(e => { console.log(users[turn].uid, JSON.parse(sessionStorage.getItem('user')).uid)
e.classList.toggle('theirturn');
}); 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) function updateUsersUI(users, turn)
@@ -47,13 +57,33 @@ function updateUsersUI(users, turn)
} }
function changeTurn()
{
if (MyTurn) {
}
}
function onExchangeTiles() 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 (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() function onSkipTurn()
@@ -63,7 +93,9 @@ function onSkipTurn()
function onPlayTurn() function onPlayTurn()
{ {
// get all staged pieces
const stagedPieces = getAllStagedPieces();
playMyTurn(stagedPieces);
} }
function onMessageSend() function onMessageSend()

View File

@@ -31,6 +31,8 @@ GAMESTATE OBJECT
// UID of the player that played the turn // UID of the player that played the turn
playeruid: uid, playeruid: uid,
turn: int, turn: int,
// SKIP, PLACE, EXCHANGE
turntype: 'SKIP',
// Generated after turn is processed // Generated after turn is processed
outcome: { outcome: {
valid: bool, valid: bool,
@@ -120,6 +122,7 @@ function BeginGame(lobby)
const gamestate = { const gamestate = {
playeruid: -1, playeruid: -1,
turn: 0, turn: 0,
turntype: '',
outcome: { outcome: {
valid: false valid: false
}, },
@@ -146,6 +149,8 @@ TURN OBJECT - Un-filled in GAMESTATE object
// UID of the player that played the turn // UID of the player that played the turn
playeruid: uid, playeruid: uid,
turn: int, turn: int,
// SKIP, PLACE, EXCHANGE
turntype: 'SKIP',
// Generated after turn is processed // Generated after turn is processed
outcome: { outcome: {
valid: bool, valid: bool,
@@ -180,10 +185,12 @@ NOTES
returning an error or a validation object including the next players returning an error or a validation object including the next players
turn turn
*/ */
// Does not trust client's oldboardtiles
function PlayTurn(gameuid, playeruid, newstate) function PlayTurn(gameuid, playeruid, newstate)
{ {
const game = ActiveGames[gameuid]; const game = ActiveGames[gameuid];
} }
// returns tuple ([newtileset], [newusertiles]) // returns tuple ([newtileset], [newusertiles])