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()
|
||||
{
|
||||
MyTurn = true;
|
||||
for (const user in Users)
|
||||
{
|
||||
Users[user].turn = false;
|
||||
if (Users[user].me) Users[user].turn = true;
|
||||
else Users[user].turn = false;
|
||||
}
|
||||
updateUsersUI(Users);
|
||||
startMyTurnUI();
|
||||
console.log('my turn', Users);
|
||||
}
|
||||
|
||||
function startOthersTurn(useruid)
|
||||
{
|
||||
MyTurn = false;
|
||||
for (const user in Users)
|
||||
{
|
||||
Users[user].turn = false;
|
||||
if (Users[user].uid === useruid) Users[user].turn = true;
|
||||
else Users[user].turn = false;
|
||||
}
|
||||
updateUsersUI(Users);
|
||||
stopMyTurnUI();
|
||||
console.log('not my turn', Users);
|
||||
}
|
||||
|
||||
function playMyTurn(stagedpieces)
|
||||
|
||||
@@ -312,9 +312,9 @@
|
||||
</div>
|
||||
<div class="connection-state"><script>document.write(localeString('status'))</script>:</div>
|
||||
<div id="game-controls">
|
||||
<input type="button" value="Exchange tiles" onclick="onExchangeTiles()">
|
||||
<input type="button" value="Skip turn" onclick="onSkipTurn()">
|
||||
<input type="button" value="Play turn" onclick="onPlayTurn()">
|
||||
<input class="button-exchange" type="button" value="Exchange tiles" onclick="onExchangeTiles()">
|
||||
<input class="button-skip" type="button" value="Skip turn" onclick="onSkipTurn()">
|
||||
<input class="button-play" type="button" value="Play turn" onclick="onPlayTurn()">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -328,9 +328,9 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id="game-controls">
|
||||
<input type="button" value="Exchange tiles" onclick="onExchangeTiles()">
|
||||
<input type="button" value="Skip turn" onclick="onSkipTurn()">
|
||||
<input type="button" value="Play turn" onclick="onPlayTurn()">
|
||||
<input class="button-exchange" type="button" value="Exchange tiles" onclick="onExchangeTiles()">
|
||||
<input class="button-skip" type="button" value="Skip turn" onclick="onSkipTurn()">
|
||||
<input class="button-play" type="button" value="Play turn" onclick="onPlayTurn()">
|
||||
</div>
|
||||
<div id="moves">
|
||||
<div class="move">Jerry played OXYPHENBUTAZONE for 40 points</div>
|
||||
|
||||
@@ -271,17 +271,18 @@ function netSkipTurn()
|
||||
|
||||
function onTurnError(socket, args)
|
||||
{
|
||||
|
||||
console.log(args);
|
||||
}
|
||||
|
||||
function onturnProcessed(socket, args)
|
||||
{
|
||||
|
||||
console.log('proc', args);
|
||||
}
|
||||
|
||||
function onTurnStart(socket, args)
|
||||
{
|
||||
|
||||
console.log('start', args);
|
||||
startOthersTurn(args.turninfo.turnplayer.uid);
|
||||
}
|
||||
|
||||
// is game singleplayer?
|
||||
|
||||
@@ -11,6 +11,11 @@ const IPlayerScores = document.querySelectorAll('.player-scores');
|
||||
// playlog
|
||||
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()
|
||||
{
|
||||
IPlayerScores.forEach(e => {
|
||||
@@ -18,6 +23,16 @@ function initUI()
|
||||
});
|
||||
PlayLog.innerHTML = '';
|
||||
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">
|
||||
@@ -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()
|
||||
{
|
||||
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
|
||||
turn: int,
|
||||
turntotal: int,
|
||||
// Array of GAMESTATEs, latest at head of array
|
||||
gamestates: [],
|
||||
tilebag: [],
|
||||
@@ -204,6 +205,7 @@ function BeginGame(lobby)
|
||||
locale: gameowner.locale,
|
||||
players: players,
|
||||
turn: 0,
|
||||
turntotal: 0,
|
||||
gamestates: [gamestate],
|
||||
tilebag: tilebag,
|
||||
tileset: Dist.GetTileSet(gameowner.locale)
|
||||
@@ -259,9 +261,7 @@ function PlayTurn(gameuid, playeruid, turn)
|
||||
{
|
||||
const game = ActiveGames[gameuid];
|
||||
|
||||
ActiveGames[gameuid].gamestate.push(turn);
|
||||
|
||||
console.log(turn);
|
||||
ActiveGames[gameuid].gamestates.push(turn);
|
||||
|
||||
const turninfo = gameNextTurn(gameuid);
|
||||
|
||||
@@ -271,11 +271,19 @@ function PlayTurn(gameuid, playeruid, turn)
|
||||
function SkipTurn(gameuid, playeruid)
|
||||
{
|
||||
console.log('skip');
|
||||
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])
|
||||
|
||||
@@ -398,18 +398,33 @@ function GamePlayTurn(socket, args)
|
||||
if (!user || !game)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
const [outcome, turninfo] = Game.Logic.SkipTurn(game.uid, user.uid);
|
||||
|
||||
io.to(game.uid).emit()
|
||||
|
||||
const {outcome, turninfo} = Game.Logic.SkipTurn(game.uid, user.uid);
|
||||
} else
|
||||
{
|
||||
// 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