turn display
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user