gonne call it done

This commit is contained in:
Ben
2021-05-10 22:22:15 +01:00
parent f89b11f6aa
commit 4da8332992
7 changed files with 106 additions and 23 deletions

View File

@@ -29,6 +29,8 @@ To play singleplayer, simply press the singleplayer button, but note that there
To play multiplayer, simply find (or force) a friend to also load the site from your private IP or whatever other networking solution you may have, both enter your name on the home page. One of you needs to create a lobby and the other needs to join it with the buttons labled as such, press ready then bam, you're in a game. Turns are denoted by the colour on the person at the top left, if it's your turn. your name will be green, if it's theirs, their name will be blue.
PLEASE REMEMBER TO RESTART THE SERVER IF THE HOST OF THE GAME DISCONNECTS DURING THE GAME
### Implementation Rationale
These are some of my thoughts behind why I implemeneted stuff the way I did. To see more, take a look at TODO.

View File

@@ -155,6 +155,54 @@ function processTurn(turn)
{
removeStagedPieces();
renderBoardState(turn.boardtiles);
/*
OUTCOME OBJECT
{
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;
if (!outcome.valid) return;
// GAMEUSERS OBJECT
// {
// uid: uid,
// name: name,
// score: int,
// me: bool,
// turn: bool
// }
// NOTES
let newpoints = 0;
let lastuser = {};
for (const user in Users)
{
if(Users[user].uid != turn.playeruid) continue;
Users[user].score += turn.outcome.points;
lastuser = Users[user];
}
changePlayerScore(lastuser.uid, lastuser.score);
for (const word of turn.outcome.words)
{
addTurnDesc(word.word, lastuser.name, word.points);
}
}
function newPieces(pieces)

View File

@@ -24,12 +24,12 @@
</svg>
</div>
<div class="connection-state"><script>document.write(localeString('status'))</script>:</div>
<div id="chat">
<!-- <div id="chat">
<textarea id="game-chat" rows="10" cols=auto placeholder="chat" disabled></textarea>
<div id="chat-input">
<input id="game-chat-input" type="text" placeholder="message"> <input id="game-chat-button" type="button" value="send" onclick="sendMessage()">
</div>
</div>
</div> -->
</div>
<div id="game-container">

View File

@@ -282,7 +282,14 @@ function netSkipTurn()
function onTurnError(socket, args)
{
console.log('error', args);
alert('Error in your turn: ' + args.error);
if (args.error === 'error-game-word-not-exist')
{
alert(`${args.word} is not a word!`);
} else
{
alert('Error in your turn: ' + args.error);
}
putPiecesBack();
}
function onturnProcessed(socket, args)

View File

@@ -63,6 +63,18 @@ function removePiecesFromDrawer(pieces)
}
}
function putPiecesBack()
{
for (const piece of document.querySelectorAll('.staged-piece'))
{
piece.classList.remove('staged-piece');
piece.classList.remove('small-piece');
delete piece.dataset.coords;
DrawerSounds[Math.floor(Math.random() * 3)].play();
}
setupPieces();
}
function updateBoardCoords()
{

View File

@@ -1,9 +1,9 @@
// DOES NOT DEAL WITH GAME BOARD
// chat
const ChatBox = document.querySelector('#game-chat');
const ChatMessageBox = document.querySelector('#game-chat-input');
const ChatMessageSubmit = document.querySelector('#game-chat-button');
// const ChatBox = document.querySelector('#game-chat');
// const ChatMessageBox = document.querySelector('#game-chat-input');
// const ChatMessageSubmit = document.querySelector('#game-chat-button');
// players
const IPlayerScores = document.querySelectorAll('.player-scores');
@@ -22,7 +22,7 @@ function initUI()
e.innerHTML = '';
});
PlayLog.innerHTML = '';
ChatBox.value = '';
// ChatBox.value = '';
IExchangeButton.forEach(e => {
e.disabled = true;
@@ -90,6 +90,15 @@ function updateUsersUI(users)
}
}
function changePlayerScore(playeruid, score)
{
document.querySelectorAll(`.player${playeruid}`).forEach(e => {
const scoreElement = e.querySelector('.player-score');
scoreElement.innerText = score;
});
}
function startMyTurnUI()
{
for (const piece of document.querySelectorAll('piece, nopiece'))
@@ -169,17 +178,7 @@ function onPlayTurn()
}
}
function onMessageSend()
function addTurnDesc(word, player, points )
{
}
function onTurnProcess()
{
}
function onTurnPlay(oldturnuser, newturnuser, newboardstate)
{
PlayLog.innerText += `${player} played ${word} for ${points} points!\n`;
}

View File

@@ -411,13 +411,27 @@ function PlayTurn(gameuid, playeruid, turn)
}
// check dictionary
for (const word in wordbasic)
for (const word in wordsbasic)
{
let reversedword = word.split('').reverse().join('');
let reversedword = wordsbasic[word].split('').reverse().join('');
const doesexist = Dict.FindWord(game.locale, wordsbasic[word].toUpperCase());
const doesreversedexist = Dict.FindWord(game.locale, reversedword.toUpperCase());
if (!doesexist && !doesreversedexist)
{
const error = {
error: 'error-game-word-not-exist',
word: wordsbasic[word]
};
return [error, undefined, undefined, undefined]
}
if (doesreversedexist)
{
wordsbasic[word] = reversedword;
words[word].reverse();
}
Logger.game(`WORD ${wordsbasic[word]} FOUND`);
}
// update tiles with scores
turn.boardtiles = turn.oldboardtiles.concat(turn.boardtiles);
for (const tile in turn.boardtiles)
@@ -496,6 +510,7 @@ function PlayTurn(gameuid, playeruid, turn)
}
turn.outcome = outcome;
gameplayer.score += outcome.points;
ActiveGames[gameuid].gamestates.push(turn);
ActiveGames[gameuid].turn = turninfo.newTurn;
ActiveGames[gameuid].turntotal = turninfo.newTotalTurn;