diff --git a/client/public/scrabble/game.js b/client/public/scrabble/game.js
index a69e366..1ed466f 100644
--- a/client/public/scrabble/game.js
+++ b/client/public/scrabble/game.js
@@ -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)
diff --git a/client/public/scrabble/index.html b/client/public/scrabble/index.html
index 6fa0392..4e3182c 100644
--- a/client/public/scrabble/index.html
+++ b/client/public/scrabble/index.html
@@ -312,9 +312,9 @@
Jerry played OXYPHENBUTAZONE for 40 points
diff --git a/client/public/scrabble/network.js b/client/public/scrabble/network.js
index 9d03af5..41f291e 100644
--- a/client/public/scrabble/network.js
+++ b/client/public/scrabble/network.js
@@ -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?
diff --git a/client/public/scrabble/ui.js b/client/public/scrabble/ui.js
index 40f72a8..d34b1ae 100644
--- a/client/public/scrabble/ui.js
+++ b/client/public/scrabble/ui.js
@@ -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) => `
@@ -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)')
diff --git a/server/src/game-logic.js b/server/src/game-logic.js
index deaaf91..693a362 100644
--- a/server/src/game-logic.js
+++ b/server/src/game-logic.js
@@ -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])
diff --git a/server/src/socketserver.js b/server/src/socketserver.js
index 6ca3181..30fe77c 100644
--- a/server/src/socketserver.js
+++ b/server/src/socketserver.js
@@ -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');
}
}