gonne call it done
This commit is contained in:
@@ -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.
|
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
|
### 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.
|
These are some of my thoughts behind why I implemeneted stuff the way I did. To see more, take a look at TODO.
|
||||||
|
|||||||
@@ -155,6 +155,54 @@ function processTurn(turn)
|
|||||||
{
|
{
|
||||||
removeStagedPieces();
|
removeStagedPieces();
|
||||||
renderBoardState(turn.boardtiles);
|
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)
|
function newPieces(pieces)
|
||||||
|
|||||||
@@ -24,12 +24,12 @@
|
|||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<div class="connection-state"><script>document.write(localeString('status'))</script>:</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>
|
<textarea id="game-chat" rows="10" cols=auto placeholder="chat" disabled></textarea>
|
||||||
<div id="chat-input">
|
<div id="chat-input">
|
||||||
<input id="game-chat-input" type="text" placeholder="message"> <input id="game-chat-button" type="button" value="send" onclick="sendMessage()">
|
<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>
|
</div>
|
||||||
|
|
||||||
<div id="game-container">
|
<div id="game-container">
|
||||||
|
|||||||
@@ -282,7 +282,14 @@ function netSkipTurn()
|
|||||||
function onTurnError(socket, args)
|
function onTurnError(socket, args)
|
||||||
{
|
{
|
||||||
console.log('error', 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)
|
function onturnProcessed(socket, args)
|
||||||
|
|||||||
@@ -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()
|
function updateBoardCoords()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// DOES NOT DEAL WITH GAME BOARD
|
// DOES NOT DEAL WITH GAME BOARD
|
||||||
|
|
||||||
// chat
|
// chat
|
||||||
const ChatBox = document.querySelector('#game-chat');
|
// const ChatBox = document.querySelector('#game-chat');
|
||||||
const ChatMessageBox = document.querySelector('#game-chat-input');
|
// const ChatMessageBox = document.querySelector('#game-chat-input');
|
||||||
const ChatMessageSubmit = document.querySelector('#game-chat-button');
|
// const ChatMessageSubmit = document.querySelector('#game-chat-button');
|
||||||
|
|
||||||
// players
|
// players
|
||||||
const IPlayerScores = document.querySelectorAll('.player-scores');
|
const IPlayerScores = document.querySelectorAll('.player-scores');
|
||||||
@@ -22,7 +22,7 @@ function initUI()
|
|||||||
e.innerHTML = '';
|
e.innerHTML = '';
|
||||||
});
|
});
|
||||||
PlayLog.innerHTML = '';
|
PlayLog.innerHTML = '';
|
||||||
ChatBox.value = '';
|
// ChatBox.value = '';
|
||||||
|
|
||||||
IExchangeButton.forEach(e => {
|
IExchangeButton.forEach(e => {
|
||||||
e.disabled = true;
|
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()
|
function startMyTurnUI()
|
||||||
{
|
{
|
||||||
for (const piece of document.querySelectorAll('piece, nopiece'))
|
for (const piece of document.querySelectorAll('piece, nopiece'))
|
||||||
@@ -169,17 +178,7 @@ function onPlayTurn()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMessageSend()
|
function addTurnDesc(word, player, points )
|
||||||
{
|
{
|
||||||
|
PlayLog.innerText += `${player} played ${word} for ${points} points!\n`;
|
||||||
}
|
|
||||||
|
|
||||||
function onTurnProcess()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function onTurnPlay(oldturnuser, newturnuser, newboardstate)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -411,13 +411,27 @@ function PlayTurn(gameuid, playeruid, turn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check dictionary
|
// 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
|
// 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)
|
||||||
@@ -496,6 +510,7 @@ function PlayTurn(gameuid, playeruid, turn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
turn.outcome = outcome;
|
turn.outcome = outcome;
|
||||||
|
gameplayer.score += outcome.points;
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user