turn processing but like not yet
This commit is contained in:
@@ -131,11 +131,17 @@ function playMyTurn(stagedpieces)
|
||||
boardtiles: boardtiles
|
||||
}
|
||||
|
||||
console.log(turn, pastTurns);
|
||||
|
||||
netPlayTurn(turn);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function skipMyTurn()
|
||||
{
|
||||
if (!MyTurn) return false;
|
||||
netSkipTurn();
|
||||
}
|
||||
|
||||
function processOthersTurn()
|
||||
{
|
||||
|
||||
|
||||
@@ -3,10 +3,25 @@ const urlParser = new URLSearchParams(window.location.search);
|
||||
const ConnectionState = document.querySelectorAll('.connection-state');
|
||||
const PieceDrawer = document.querySelector('#piece-drawer');
|
||||
|
||||
// like a singleton in c++ or what have you
|
||||
// but not
|
||||
let socketinit = false;
|
||||
let socket = {};
|
||||
function getSocket()
|
||||
{
|
||||
if (!socketinit)
|
||||
{
|
||||
socket = io(window.location.host);
|
||||
socketinit = true;
|
||||
}
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
function initMultiplayer()
|
||||
{
|
||||
// init socket
|
||||
const socket = io(window.location.host);
|
||||
const socket = getSocket();
|
||||
|
||||
socket.on('connect', args => {
|
||||
console.log('Socket Connected');
|
||||
@@ -28,8 +43,12 @@ 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)); // my turn
|
||||
socket.on('game-turn-error', args => onTurnError(socket, args)); // my turn had an error, game does not continue
|
||||
socket.on('game-turn-processed', args => onturnProcessed(socket, args)); // server returns turn (to all users)
|
||||
socket.on('game-turn-start', args => onTurnStart(socket, args)); // others turn
|
||||
|
||||
socket.on('game-new-pieces', args => onTurnStart(socket, args));
|
||||
|
||||
console.log('multiplayer ready');
|
||||
@@ -232,6 +251,34 @@ function onStartTurn(socket, args)
|
||||
startMyTurn();
|
||||
}
|
||||
|
||||
function netPlayTurn(turn)
|
||||
{
|
||||
if (!isSingleplayer)
|
||||
{
|
||||
const socket = getSocket();
|
||||
socket.emit('game-play-turn', turn);
|
||||
}
|
||||
}
|
||||
|
||||
function netSkipTurn()
|
||||
{
|
||||
if (!isSingleplayer)
|
||||
{
|
||||
const socket = getSocket();
|
||||
socket.emit('game-skip-turn');
|
||||
}
|
||||
}
|
||||
|
||||
function onTurnError(socket, args)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function onturnProcessed(socket, args)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function onTurnStart(socket, args)
|
||||
{
|
||||
|
||||
|
||||
@@ -95,7 +95,10 @@ function onExchangeTiles()
|
||||
|
||||
function onSkipTurn()
|
||||
{
|
||||
|
||||
if(confirm('Are you sure you want to skip your turn?'))
|
||||
{
|
||||
skipMyTurn();
|
||||
}
|
||||
}
|
||||
|
||||
function onPlayTurn()
|
||||
|
||||
@@ -138,6 +138,7 @@ const BoardLocations = {
|
||||
"14,14": "TW"
|
||||
};
|
||||
|
||||
|
||||
function GetGameByUserUID(useruid)
|
||||
{
|
||||
for (const game in ActiveGames)
|
||||
@@ -177,8 +178,11 @@ function BeginGame(lobby)
|
||||
// start all players with 7 random tiles
|
||||
for (let i = 0; i < 7; i++)
|
||||
{
|
||||
let r = Math.floor(Math.random() * tilebag.length + 1);
|
||||
let t = tilebag[r];
|
||||
let t, r;
|
||||
do {
|
||||
r = Math.floor(Math.random() * tilebag.length + 1);
|
||||
t = tilebag[r];
|
||||
} while (t === null)
|
||||
tilebag.splice(r, 1);
|
||||
players[player].activetiles.push(t);
|
||||
}
|
||||
@@ -251,10 +255,26 @@ NOTES
|
||||
turn
|
||||
*/
|
||||
// Does not trust client's oldboardtiles
|
||||
function PlayTurn(gameuid, playeruid, newstate)
|
||||
function PlayTurn(gameuid, playeruid, turn)
|
||||
{
|
||||
const game = ActiveGames[gameuid];
|
||||
|
||||
ActiveGames[gameuid].gamestate.push(turn);
|
||||
|
||||
console.log(turn);
|
||||
|
||||
const turninfo = gameNextTurn(gameuid);
|
||||
|
||||
return [turn, turninfo];
|
||||
}
|
||||
|
||||
function SkipTurn(gameuid, playeruid)
|
||||
{
|
||||
console.log('skip');
|
||||
}
|
||||
|
||||
function gameNextTurn(gameuid)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -286,5 +306,6 @@ module.exports = {
|
||||
// Change game state exports
|
||||
BeginGame: BeginGame,
|
||||
PlayTurn: PlayTurn,
|
||||
SkipTurn: SkipTurn,
|
||||
EndGame: EndGame
|
||||
}
|
||||
|
||||
@@ -392,9 +392,24 @@ function LobbyGameBegin(socket, args)
|
||||
|
||||
function GamePlayTurn(socket, args)
|
||||
{
|
||||
const user = Game.Registrar.GetUserbyConnection(socket.id);
|
||||
const game = Game.Logic.GetGameByUserUID(user.uid);
|
||||
|
||||
if (!user || !game)
|
||||
{
|
||||
// do something bad
|
||||
}
|
||||
|
||||
if (args.skip === true)
|
||||
{
|
||||
const [outcome, turninfo] = Game.Logic.SkipTurn(game.uid, user.uid);
|
||||
|
||||
io.to(game.uid).emit()
|
||||
|
||||
} else
|
||||
{
|
||||
// TODO: validate args
|
||||
outcome = Game.Logic.PlayTurn(game.uid, user.uid, args)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user