This commit is contained in:
Ben
2021-05-10 21:02:47 +01:00
parent 6928876168
commit ab85155a90
2 changed files with 36 additions and 11 deletions

View File

@@ -63,6 +63,7 @@ To see what needs to be completed code-wise, take a look at `TODO`, there you wi
### Acknowledgements ### Acknowledgements
Express.js - HTTP Routing and Management Express.js - HTTP Routing and Management
Socket.io - Socket Routing and Management Socket.io - Socket Routing and Management
Inês Filipa Baiõa Antunes - Tranlations (Portuguese, Spanish) Inês Filipa Baiõa Antunes - Tranlations (Portuguese, Spanish)

View File

@@ -186,7 +186,7 @@ function BeginGame(lobby)
for (const player in players) for (const player in players)
{ {
// start all players with 7 random tiles // start all players with 7 random tiles
for (let i = 0; i < 6; i++) for (let i = 0; i < 7; i++)
{ {
let t, r; let t, r;
do { do {
@@ -197,8 +197,6 @@ function BeginGame(lobby)
tilebag.splice(r, 1); tilebag.splice(r, 1);
players[player].activetiles.push(t); players[player].activetiles.push(t);
} }
players[player].activetiles.push('_');
} }
const gamestate = { const gamestate = {
@@ -434,6 +432,7 @@ function PlayTurn(gameuid, playeruid, turn)
// no recursion this time // no recursion this time
let words = []; let words = [];
let wordsbasic = [];
for (const newpiece of diff) for (const newpiece of diff)
{ {
@@ -466,7 +465,8 @@ function PlayTurn(gameuid, playeruid, turn)
for (let i = 0; i < 4; i++) for (let i = 0; i < 4; i++)
{ {
let word = ''; let word = [];
let wordbasic = '';
const direction = directions[i]; const direction = directions[i];
let coords = {x: newpiece.pos.x, y: newpiece.pos.y}; let coords = {x: newpiece.pos.x, y: newpiece.pos.y};
@@ -476,26 +476,28 @@ function PlayTurn(gameuid, playeruid, turn)
// console.log(ret); // console.log(ret);
if (ret === false) if (ret === false)
break; break;
word += ret.letter; word.push(ret);
wordbasic += ret.letter;
coords.x += direction.x; coords.x += direction.x;
coords.y += direction.y; coords.y += direction.y;
} }
if (word.length === 1) continue; if (word.length === 1) continue;
words.push(word); words.push(word);
console.log(word); wordsbasic.push(wordbasic);
} }
} }
// remove same-in-reverse words // remove same-in-reverse words
for (const word in words) for (const word in wordsbasic)
{ {
const reverse = words[word].split('').reverse().join(''); const reverse = wordsbasic[word].split('').reverse().join('');
if (words.includes(reverse)) if (wordsbasic.includes(reverse))
{
wordsbasic.splice(word, 1);
words.splice(word, 1); words.splice(word, 1);
}
} }
console.log(words);
// update tiles with scores // update tiles with scores
turn.boardtiles = turn.oldboardtiles.concat(turn.boardtiles); turn.boardtiles = turn.oldboardtiles.concat(turn.boardtiles);
for (const tile in turn.boardtiles) for (const tile in turn.boardtiles)
@@ -514,6 +516,7 @@ function PlayTurn(gameuid, playeruid, turn)
// process turn and allocate scores // process turn and allocate scores
// for every new word // for every new word
// calculate based on TL/DL/DW/TW and tile score the score // calculate based on TL/DL/DW/TW and tile score the score
// send to client // send to client
@@ -521,7 +524,28 @@ function PlayTurn(gameuid, playeruid, turn)
// give user new tiles // give user new tiles
/*
outcome: {
valid: bool,
points: pointsgained,
words: [{
word: word,
points: points,
tiles: [{
pos: {x: x, y: y},
modifier: modifier,
letter: letter,
score: int
}]
}],
}
*/
const outcome = {
};
turn.outcome = outcome;
ActiveGames[gameuid].gamestates.push(turn); ActiveGames[gameuid].gamestates.push(turn);
ActiveGames[gameuid].turn = turninfo.newTurn; ActiveGames[gameuid].turn = turninfo.newTurn;
ActiveGames[gameuid].turntotal = turninfo.newTotalTurn; ActiveGames[gameuid].turntotal = turninfo.newTotalTurn;