logic game creation
This commit is contained in:
12
TODO
12
TODO
@@ -24,13 +24,17 @@
|
||||
|
||||
[ ] Dictionary
|
||||
→ Find appropriate scrabble dictionary for
|
||||
→ Portuagese
|
||||
→ Spanish
|
||||
→ French
|
||||
✔ Portuagese @done(21-04-19 02:10)
|
||||
✔ Spanish @done(21-04-19 02:10)
|
||||
✔ French @done(21-04-19 02:10)
|
||||
→ Czech
|
||||
→ Optimise! nary tree
|
||||
→ Optimise! n-ary tree
|
||||
|
||||
[ ] Game logic
|
||||
→ Game creation
|
||||
✘ Singleplayer game logic - OUT OF SCOPE @cancelled(21-04-11 01:04)
|
||||
✘ AI CPU player @cancelled(21-04-11 01:07)
|
||||
|
||||
[ ] Code
|
||||
→ Refactor to code portsoc eslint
|
||||
→ Refactor game client
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
|
||||
let turn = 0; // 0 = player 1 = scrabble
|
||||
|
||||
|
||||
function computeTurn()
|
||||
{
|
||||
if (!isSingleplayer) return;
|
||||
|
||||
@@ -8,82 +8,92 @@ function initMultiplayer()
|
||||
// init socket
|
||||
const socket = io(window.location.host);
|
||||
|
||||
socket.on('connect', (...args) => {
|
||||
socket.on('connect', args => {
|
||||
console.log('Socket Connected');
|
||||
ConnectionState.innerHTML = `${localeString('status')}: Waiting for identify`;
|
||||
});
|
||||
|
||||
socket.on('disconnect', (...args) => {
|
||||
socket.on('disconnect', args => {
|
||||
console.log('Socket Disconnected');
|
||||
ConnectionState.innerHTML = `${localeString('status')}: ${localeString('status-disconnected')}`;
|
||||
onDisconnect();
|
||||
});
|
||||
|
||||
socket.on('identify', args => onIdentify(socket, args));
|
||||
socket.on('identify-success', args => onIdentifySuccess(socket, args));
|
||||
socket.on('identify-error', args => onIdentifyError(socket, args));
|
||||
|
||||
|
||||
socket.on('identify', (...args) => {
|
||||
ConnectionState.innerHTML = 'Identify recived'
|
||||
|
||||
if (!sessionStorage.user)
|
||||
{
|
||||
socket.disconnect();
|
||||
ConnectionState.innerHTML = 'Identify cannot proceed, no user';
|
||||
document.location.href += '../';
|
||||
return;
|
||||
}
|
||||
|
||||
let user = {};
|
||||
try
|
||||
{
|
||||
user = JSON.parse(sessionStorage.user);
|
||||
} catch (e)
|
||||
{
|
||||
socket.disconnect();
|
||||
ConnectionState.innerHTML = 'Identify cannot proceed, corrupted user';
|
||||
document.location.href += '../';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.uid)
|
||||
{
|
||||
socket.disconnect();
|
||||
ConnectionState.innerHTML = 'Identify cannot proceed, corrupted user';
|
||||
document.location.href += '../';
|
||||
return;
|
||||
}
|
||||
|
||||
const lobbyUID = urlParser.get('uid')
|
||||
|
||||
if (!lobbyUID)
|
||||
{
|
||||
socket.disconnect();
|
||||
ConnectionState.innerHTML = 'Identify cannot proceed, corrupted lobby';
|
||||
document.location.href += '../';
|
||||
return;
|
||||
}
|
||||
|
||||
socket.emit('identify', { userid: user.uid, lobbyuid: lobbyUID, intent: 'GAME' });
|
||||
ConnectionState.innerHTML = 'Identify response';
|
||||
});
|
||||
|
||||
|
||||
socket.on('identify-success', (...args) => {
|
||||
console.log(args[0]);
|
||||
ConnectionState.innerHTML = localeString('status-connected-as') + ' ' + args[0].user.username;
|
||||
onConnect();
|
||||
});
|
||||
|
||||
socket.on('identify-error', (...args) => {
|
||||
console.log(args[0]);
|
||||
ConnectionState.innerHTML = JSON.stringify(args[0]);
|
||||
onDisconnect();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function onIdentify(socket, args)
|
||||
{
|
||||
ConnectionState.innerHTML = 'Identify recived'
|
||||
|
||||
if (!sessionStorage.user)
|
||||
{
|
||||
socket.disconnect();
|
||||
ConnectionState.innerHTML = 'Identify cannot proceed, no user';
|
||||
document.location.href += '../';
|
||||
return;
|
||||
}
|
||||
|
||||
let user = {};
|
||||
try
|
||||
{
|
||||
user = JSON.parse(sessionStorage.user);
|
||||
} catch (e)
|
||||
{
|
||||
socket.disconnect();
|
||||
ConnectionState.innerHTML = 'Identify cannot proceed, corrupted user';
|
||||
document.location.href += '../';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.uid)
|
||||
{
|
||||
socket.disconnect();
|
||||
ConnectionState.innerHTML = 'Identify cannot proceed, corrupted user';
|
||||
document.location.href += '../';
|
||||
return;
|
||||
}
|
||||
|
||||
const lobbyUID = urlParser.get('uid')
|
||||
|
||||
if (!lobbyUID)
|
||||
{
|
||||
socket.disconnect();
|
||||
ConnectionState.innerHTML = 'Identify cannot proceed, corrupted lobby';
|
||||
document.location.href += '../';
|
||||
return;
|
||||
}
|
||||
|
||||
socket.emit('identify', { userid: user.uid, lobbyuid: lobbyUID, intent: 'GAME' });
|
||||
ConnectionState.innerHTML = 'Identify response';
|
||||
}
|
||||
|
||||
function onIdentifySuccess(socket, args)
|
||||
{
|
||||
console.log(args);
|
||||
ConnectionState.innerHTML = localeString('status-connected-as') + ' ' + args.user.username;
|
||||
onConnect();
|
||||
}
|
||||
|
||||
function onIdentifyError(socket, args)
|
||||
{
|
||||
console.log(args);
|
||||
ConnectionState.innerHTML = JSON.stringify(args);
|
||||
onDisconnect();
|
||||
}
|
||||
|
||||
// get ready for game begin packet
|
||||
function onConnect()
|
||||
{
|
||||
PieceDrawer.innerHTML = '';
|
||||
// TODO: Other drawing here
|
||||
}
|
||||
|
||||
function onDisconnect()
|
||||
|
||||
@@ -13,16 +13,24 @@ GAME OBJECT
|
||||
players: [{
|
||||
uid: uid,
|
||||
name: username,
|
||||
activetiles: [],
|
||||
activetiles: [tile: {
|
||||
tile: tile,
|
||||
score: int
|
||||
}],
|
||||
score: int
|
||||
}],
|
||||
// index of players
|
||||
turn: int,
|
||||
tilebag: []
|
||||
tilebag: [],
|
||||
tileset: []
|
||||
}
|
||||
NOTES
|
||||
- The locale is the language of the *owner of the lobby*, the dictionary
|
||||
will reflect this language choice
|
||||
- TILESET is a lookup table for tiles: scores, derived from the locale's
|
||||
score thing in letter-distributions.js TILEBAG is not to be confused
|
||||
with tileset as those are active game tiles and are modified as turns
|
||||
are played
|
||||
*/
|
||||
let ActiveGames = [];
|
||||
|
||||
@@ -44,10 +52,18 @@ function StartGame(lobby)
|
||||
// shuffle for turn order
|
||||
players = Helpers.ShuffleArray(players);
|
||||
|
||||
console.log(players)
|
||||
|
||||
// populate users tile drawer
|
||||
|
||||
for (const player in players)
|
||||
{
|
||||
// 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];
|
||||
tilebag.splice(r, 1);
|
||||
players[player].activetiles.push(t);
|
||||
}
|
||||
}
|
||||
|
||||
ActiveGames[lobby.uid] = {
|
||||
lobbyuid: lobby.uid,
|
||||
@@ -57,6 +73,8 @@ function StartGame(lobby)
|
||||
tilebag: tilebag
|
||||
};
|
||||
|
||||
console.log(ActiveGames[lobby.uid]);
|
||||
|
||||
return ActiveGames[lobby.uid];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user