proper game start logic
This commit is contained in:
@@ -116,7 +116,7 @@ function onGameBegin(socket, args)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(args);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ let ActiveGames = [];
|
|||||||
|
|
||||||
function BeginGame(lobby)
|
function BeginGame(lobby)
|
||||||
{
|
{
|
||||||
// game uses the owners language
|
// game uses the owners language - assumes it's valid
|
||||||
const gameowner = Registrar.GetUserByUID(lobby.owneruid);
|
const gameowner = Registrar.GetUserByUID(lobby.owneruid);
|
||||||
|
|
||||||
let tilebag = Dist.GenerateStartStateDistribution(gameowner.locale);
|
let tilebag = Dist.GenerateStartStateDistribution(gameowner.locale);
|
||||||
@@ -101,11 +101,22 @@ function BeginGame(lobby)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gamestate = {
|
||||||
|
playeruid: -1,
|
||||||
|
turn: 0,
|
||||||
|
outcome: {
|
||||||
|
valid: false
|
||||||
|
},
|
||||||
|
oldboardtiles: [],
|
||||||
|
boardtiles: []
|
||||||
|
};
|
||||||
|
|
||||||
ActiveGames[lobby.uid] = {
|
ActiveGames[lobby.uid] = {
|
||||||
uid: lobby.uid,
|
uid: lobby.uid,
|
||||||
locale: gameowner.locale,
|
locale: gameowner.locale,
|
||||||
players: players,
|
players: players,
|
||||||
turn: 0,
|
turn: 0,
|
||||||
|
gamestates: [gamestate],
|
||||||
tilebag: tilebag,
|
tilebag: tilebag,
|
||||||
tileset: Dist.GetTileSet(gameowner.locale)
|
tileset: Dist.GetTileSet(gameowner.locale)
|
||||||
};
|
};
|
||||||
@@ -114,9 +125,38 @@ function BeginGame(lobby)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TURN OBJECT
|
TURN OBJECT - Un-filled in GAMESTATE object
|
||||||
{
|
{
|
||||||
|
// UID of the player that played the turn
|
||||||
|
playeruid: uid,
|
||||||
|
turn: int,
|
||||||
|
// Generated after turn is processed
|
||||||
|
outcome: {
|
||||||
|
valid: bool,
|
||||||
|
points: pointsgained,
|
||||||
|
words: [{
|
||||||
|
word: word,
|
||||||
|
points: points,
|
||||||
|
tiles: [{
|
||||||
|
pos: {x: x, y: y},
|
||||||
|
modifier: modifier,
|
||||||
|
letter: letter,
|
||||||
|
score: int
|
||||||
|
}]
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
oldboardtiles: [{
|
||||||
|
pos: {x: x, y: y},
|
||||||
|
modifier: modifier,
|
||||||
|
letter: letter,
|
||||||
|
score: int
|
||||||
|
}]
|
||||||
|
boardtiles: [{
|
||||||
|
pos: {x: x, y: y},
|
||||||
|
modifier: modifier,
|
||||||
|
letter: letter,
|
||||||
|
score: int
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
NOTES
|
NOTES
|
||||||
- Turns are handled a little weird, client sends turn on turn end and
|
- Turns are handled a little weird, client sends turn on turn end and
|
||||||
@@ -135,12 +175,6 @@ function ExchangeTiles(tileset, tilesToExchange)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// does not alter tileset
|
|
||||||
function SelectTilesFromBag(tileset, num)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// Game validation exports
|
// Game validation exports
|
||||||
|
|||||||
@@ -160,6 +160,14 @@ function GetUserbyConnection(connectionid)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function GetConnectionByUser(useruid)
|
||||||
|
{
|
||||||
|
for (const user in OnlineUsers)
|
||||||
|
if (OnlineUsers[user].uid === useruid && OnlineUsers[user].state === 'CONNECTED')
|
||||||
|
return OnlineUsers[user].connectionid;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: User intent
|
// TODO: User intent
|
||||||
function UserConnect(useruid, connectionid, intent)
|
function UserConnect(useruid, connectionid, intent)
|
||||||
{
|
{
|
||||||
@@ -209,6 +217,7 @@ module.exports = {
|
|||||||
|
|
||||||
// Get user connection exports
|
// Get user connection exports
|
||||||
GetUserbyConnection: GetUserbyConnection,
|
GetUserbyConnection: GetUserbyConnection,
|
||||||
|
GetConnectionByUser: GetConnectionByUser,
|
||||||
|
|
||||||
// Change user connection state exports
|
// Change user connection state exports
|
||||||
UserConnect: UserConnect,
|
UserConnect: UserConnect,
|
||||||
|
|||||||
@@ -416,14 +416,18 @@ function LobbyUpdateCallback(user, lobby, state)
|
|||||||
// send the client their user as well as the rest of the game
|
// send the client their user as well as the rest of the game
|
||||||
function EmitGameBegin(game)
|
function EmitGameBegin(game)
|
||||||
{
|
{
|
||||||
// TODO: consider not sending all users the entire game state
|
// Instead of using io.to(room), i'm sending an individual packet to everyone
|
||||||
// due to cheating
|
// in the game so that i can customise the game object that they recieve
|
||||||
io.to(game.uid).emit('game-begin', {
|
for (const user of game.players)
|
||||||
game: game
|
{
|
||||||
});
|
const gameuser = game.players.filter(i => i.uid === user.uid)[0];
|
||||||
|
const gameuserconnection = Game.Registrar.GetConnectionByUser(gameuser.uid);
|
||||||
|
|
||||||
// for (const user of game.players)
|
// TODO: consider not sending all users the entire game state
|
||||||
// {
|
// due to cheating
|
||||||
// const gameuser = game.players.filter(i => i.uid === user.uid)[0];
|
io.to(gameuserconnection).emit('game-begin', {
|
||||||
// }
|
game: game,
|
||||||
|
gameuser: gameuser
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user