Started clientside turn communication

This commit is contained in:
Ben
2021-05-06 03:16:38 +01:00
parent 66edbbf51e
commit b5f6d678e1
6 changed files with 31 additions and 6 deletions

View File

@@ -1 +1 @@
COPYRIGHT 2021 BENJAMIN KYD ALL RIGHTS RESERVED
COPYRIGHT 2021 BENJAMIN KYD - ALL RIGHTS RESERVED

3
TODO
View File

@@ -30,6 +30,9 @@
☐ Game logic
✔ Game creation @done(21-04-26 17:38)
☐ Multiplayer game logic
☐ Process turns
☐ Display turns on client
✘ Singleplayer game logic - OUT OF SCOPE @cancelled(21-04-11 01:04)
✘ AI CPU player @cancelled(21-04-11 01:07)

View File

@@ -33,4 +33,3 @@ document.querySelectorAll('piece').forEach(element => {
element.addEventListener('mousedown', e => mouseDown(e, element));
element.addEventListener('touchstart', e => mouseDown(e, element));
});

View File

@@ -24,7 +24,9 @@ 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));
console.log('multiplayer ready')
}
@@ -61,7 +63,7 @@ function onIdentify(socket, args)
return;
}
const lobbyUID = urlParser.get('uid')
const lobbyUID = urlParser.get('uid');
if (!lobbyUID)
{
@@ -103,7 +105,6 @@ function onDisconnect()
function onGameBegin(socket, args)
{
if (!args)
{
ConnectionState.innerHTML = localeString('error-game-begin');
@@ -118,6 +119,13 @@ function onGameBegin(socket, args)
console.log(args);
}
function onStartTurn(socket, args)
{
console.log('my turn')
}

View File

@@ -71,6 +71,13 @@ NOTES
let ActiveGames = [];
function GetTurnUser(gameuid)
{
if (!ActiveGames[gameuid]) return false;
return ActiveGames[gameuid].players[ActiveGames[gameuid].turn];
}
function BeginGame(lobby)
{
// game uses the owners language - assumes it's valid
@@ -180,6 +187,7 @@ module.exports = {
// Game validation exports
// Get game exports
GetTurnUser: GetTurnUser,
// Change game state exports
BeginGame: BeginGame,

View File

@@ -424,10 +424,17 @@ function EmitGameBegin(game)
const gameuserconnection = Game.Registrar.GetConnectionByUser(gameuser.uid);
// TODO: consider not sending all users the entire game state
// due to cheating
// due to cheating - a few more considerations and maybe a
// getsafegame function is needed
io.to(gameuserconnection).emit('game-begin', {
game: game,
gameuser: gameuser
})
});
}
// Let starting player know it's their turn
const userturnstart = Game.Logic.GetTurnUser(game.uid).uid;
const userturnstartconnection = Game.Registrar.GetConnectionByUser(userturnstart);
io.to(userturnstartconnection).emit('game-your-turn');
}