ive only gone and actually processed a turn *in full*
This commit is contained in:
@@ -79,22 +79,30 @@ function initGame(boardstates, tileset, myplayer, players)
|
|||||||
|
|
||||||
function startMyTurn()
|
function startMyTurn()
|
||||||
{
|
{
|
||||||
|
MyTurn = true;
|
||||||
for (const user in Users)
|
for (const user in Users)
|
||||||
{
|
{
|
||||||
|
Users[user].turn = false;
|
||||||
if (Users[user].me) Users[user].turn = true;
|
if (Users[user].me) Users[user].turn = true;
|
||||||
else Users[user].turn = false;
|
else Users[user].turn = false;
|
||||||
}
|
}
|
||||||
updateUsersUI(Users);
|
updateUsersUI(Users);
|
||||||
|
startMyTurnUI();
|
||||||
|
console.log('my turn', Users);
|
||||||
}
|
}
|
||||||
|
|
||||||
function startOthersTurn(useruid)
|
function startOthersTurn(useruid)
|
||||||
{
|
{
|
||||||
|
MyTurn = false;
|
||||||
for (const user in Users)
|
for (const user in Users)
|
||||||
{
|
{
|
||||||
|
Users[user].turn = false;
|
||||||
if (Users[user].uid === useruid) Users[user].turn = true;
|
if (Users[user].uid === useruid) Users[user].turn = true;
|
||||||
else Users[user].turn = false;
|
else Users[user].turn = false;
|
||||||
}
|
}
|
||||||
updateUsersUI(Users);
|
updateUsersUI(Users);
|
||||||
|
stopMyTurnUI();
|
||||||
|
console.log('not my turn', Users);
|
||||||
}
|
}
|
||||||
|
|
||||||
function playMyTurn(stagedpieces)
|
function playMyTurn(stagedpieces)
|
||||||
|
|||||||
@@ -312,9 +312,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="connection-state"><script>document.write(localeString('status'))</script>:</div>
|
<div class="connection-state"><script>document.write(localeString('status'))</script>:</div>
|
||||||
<div id="game-controls">
|
<div id="game-controls">
|
||||||
<input type="button" value="Exchange tiles" onclick="onExchangeTiles()">
|
<input class="button-exchange" type="button" value="Exchange tiles" onclick="onExchangeTiles()">
|
||||||
<input type="button" value="Skip turn" onclick="onSkipTurn()">
|
<input class="button-skip" type="button" value="Skip turn" onclick="onSkipTurn()">
|
||||||
<input type="button" value="Play turn" onclick="onPlayTurn()">
|
<input class="button-play" type="button" value="Play turn" onclick="onPlayTurn()">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -328,9 +328,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="game-controls">
|
<div id="game-controls">
|
||||||
<input type="button" value="Exchange tiles" onclick="onExchangeTiles()">
|
<input class="button-exchange" type="button" value="Exchange tiles" onclick="onExchangeTiles()">
|
||||||
<input type="button" value="Skip turn" onclick="onSkipTurn()">
|
<input class="button-skip" type="button" value="Skip turn" onclick="onSkipTurn()">
|
||||||
<input type="button" value="Play turn" onclick="onPlayTurn()">
|
<input class="button-play" type="button" value="Play turn" onclick="onPlayTurn()">
|
||||||
</div>
|
</div>
|
||||||
<div id="moves">
|
<div id="moves">
|
||||||
<div class="move">Jerry played OXYPHENBUTAZONE for 40 points</div>
|
<div class="move">Jerry played OXYPHENBUTAZONE for 40 points</div>
|
||||||
|
|||||||
@@ -271,17 +271,18 @@ function netSkipTurn()
|
|||||||
|
|
||||||
function onTurnError(socket, args)
|
function onTurnError(socket, args)
|
||||||
{
|
{
|
||||||
|
console.log(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onturnProcessed(socket, args)
|
function onturnProcessed(socket, args)
|
||||||
{
|
{
|
||||||
|
console.log('proc', args);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTurnStart(socket, args)
|
function onTurnStart(socket, args)
|
||||||
{
|
{
|
||||||
|
console.log('start', args);
|
||||||
|
startOthersTurn(args.turninfo.turnplayer.uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// is game singleplayer?
|
// is game singleplayer?
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ const IPlayerScores = document.querySelectorAll('.player-scores');
|
|||||||
// playlog
|
// playlog
|
||||||
const PlayLog = document.querySelector('#moves');
|
const PlayLog = document.querySelector('#moves');
|
||||||
|
|
||||||
|
// buttons
|
||||||
|
const IExchangeButton = document.querySelectorAll('.button-exchange');
|
||||||
|
const ISkipButton = document.querySelectorAll('.button-skip');
|
||||||
|
const IPlayButton = document.querySelectorAll('.button-play');
|
||||||
|
|
||||||
function initUI()
|
function initUI()
|
||||||
{
|
{
|
||||||
IPlayerScores.forEach(e => {
|
IPlayerScores.forEach(e => {
|
||||||
@@ -18,6 +23,16 @@ function initUI()
|
|||||||
});
|
});
|
||||||
PlayLog.innerHTML = '';
|
PlayLog.innerHTML = '';
|
||||||
ChatBox.value = '';
|
ChatBox.value = '';
|
||||||
|
|
||||||
|
IExchangeButton.forEach(e => {
|
||||||
|
e.disabled = true;
|
||||||
|
});
|
||||||
|
ISkipButton.forEach(e => {
|
||||||
|
e.disabled = true;
|
||||||
|
});
|
||||||
|
IPlayButton.forEach(e => {
|
||||||
|
e.disabled = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const UserUIReplacer = (p, u, n, s) => `<div class="p${p} player${u} player">
|
const UserUIReplacer = (p, u, n, s) => `<div class="p${p} player${u} player">
|
||||||
@@ -71,6 +86,32 @@ function updateUsersUI(users)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function startMyTurnUI()
|
||||||
|
{
|
||||||
|
IExchangeButton.forEach(e => {
|
||||||
|
e.disabled = false;
|
||||||
|
});
|
||||||
|
ISkipButton.forEach(e => {
|
||||||
|
e.disabled = false;
|
||||||
|
});
|
||||||
|
IPlayButton.forEach(e => {
|
||||||
|
e.disabled = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopMyTurnUI()
|
||||||
|
{
|
||||||
|
IExchangeButton.forEach(e => {
|
||||||
|
e.disabled = true;
|
||||||
|
});
|
||||||
|
ISkipButton.forEach(e => {
|
||||||
|
e.disabled = true;
|
||||||
|
});
|
||||||
|
IPlayButton.forEach(e => {
|
||||||
|
e.disabled = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function onExchangeTiles()
|
function onExchangeTiles()
|
||||||
{
|
{
|
||||||
let tiles = prompt('Enter the tiles you would like to exchange seperated by commas or type all for all of them (this will use your turn)')
|
let tiles = prompt('Enter the tiles you would like to exchange seperated by commas or type all for all of them (this will use your turn)')
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ GAME OBJECT
|
|||||||
}],
|
}],
|
||||||
// Index of players whos turn it is
|
// Index of players whos turn it is
|
||||||
turn: int,
|
turn: int,
|
||||||
|
turntotal: int,
|
||||||
// Array of GAMESTATEs, latest at head of array
|
// Array of GAMESTATEs, latest at head of array
|
||||||
gamestates: [],
|
gamestates: [],
|
||||||
tilebag: [],
|
tilebag: [],
|
||||||
@@ -204,6 +205,7 @@ function BeginGame(lobby)
|
|||||||
locale: gameowner.locale,
|
locale: gameowner.locale,
|
||||||
players: players,
|
players: players,
|
||||||
turn: 0,
|
turn: 0,
|
||||||
|
turntotal: 0,
|
||||||
gamestates: [gamestate],
|
gamestates: [gamestate],
|
||||||
tilebag: tilebag,
|
tilebag: tilebag,
|
||||||
tileset: Dist.GetTileSet(gameowner.locale)
|
tileset: Dist.GetTileSet(gameowner.locale)
|
||||||
@@ -259,9 +261,7 @@ function PlayTurn(gameuid, playeruid, turn)
|
|||||||
{
|
{
|
||||||
const game = ActiveGames[gameuid];
|
const game = ActiveGames[gameuid];
|
||||||
|
|
||||||
ActiveGames[gameuid].gamestate.push(turn);
|
ActiveGames[gameuid].gamestates.push(turn);
|
||||||
|
|
||||||
console.log(turn);
|
|
||||||
|
|
||||||
const turninfo = gameNextTurn(gameuid);
|
const turninfo = gameNextTurn(gameuid);
|
||||||
|
|
||||||
@@ -271,11 +271,19 @@ function PlayTurn(gameuid, playeruid, turn)
|
|||||||
function SkipTurn(gameuid, playeruid)
|
function SkipTurn(gameuid, playeruid)
|
||||||
{
|
{
|
||||||
console.log('skip');
|
console.log('skip');
|
||||||
|
gameNextTurn(gameuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
function gameNextTurn(gameuid)
|
function gameNextTurn(gameuid)
|
||||||
{
|
{
|
||||||
|
const PlayerCount = ActiveGames[gameuid].players.length;
|
||||||
|
ActiveGames[gameuid].turn++;
|
||||||
|
ActiveGames[gameuid].turn %= PlayerCount;
|
||||||
|
ActiveGames[gameuid].turntotal++;
|
||||||
|
return {
|
||||||
|
// i forgot why this is an object, there's more attributes i forgot about
|
||||||
|
turnplayer: ActiveGames[gameuid].players[ActiveGames[gameuid].turn],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns tuple ([newtileset], [newusertiles])
|
// returns tuple ([newtileset], [newusertiles])
|
||||||
|
|||||||
@@ -398,18 +398,33 @@ function GamePlayTurn(socket, args)
|
|||||||
if (!user || !game)
|
if (!user || !game)
|
||||||
{
|
{
|
||||||
// do something bad
|
// do something bad
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.game(`USER ${user.uid} (${user.name}) IS ATTEMPTING TO PLAY A TURN IN GAME ${game.uid}`);
|
||||||
|
|
||||||
if (args.skip === true)
|
if (args.skip === true)
|
||||||
{
|
{
|
||||||
const [outcome, turninfo] = Game.Logic.SkipTurn(game.uid, user.uid);
|
const {outcome, turninfo} = Game.Logic.SkipTurn(game.uid, user.uid);
|
||||||
|
|
||||||
io.to(game.uid).emit()
|
|
||||||
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
// TODO: validate args
|
// TODO: validate args
|
||||||
outcome = Game.Logic.PlayTurn(game.uid, user.uid, args)
|
const [outcome, turninfo] = Game.Logic.PlayTurn(game.uid, user.uid, args)
|
||||||
|
|
||||||
|
// give user new tiles
|
||||||
|
// process errorsq
|
||||||
|
|
||||||
|
io.to(game.uid).emit('game-turn-processed', {
|
||||||
|
outcome: outcome
|
||||||
|
});
|
||||||
|
|
||||||
|
const nextuser = Game.Registrar.GetConnectionByUser(turninfo.turnplayer.uid);
|
||||||
|
|
||||||
|
io.to(game.uid).emit('game-turn-start', {
|
||||||
|
turninfo: turninfo
|
||||||
|
});
|
||||||
|
|
||||||
|
io.to(nextuser).emit('game-your-turn');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user