Change results page labels and add a leave game link

This commit is contained in:
Andrio Celos
2022-10-05 16:55:28 +11:00
parent 59dc677077
commit 1d29356107
4 changed files with 21 additions and 11 deletions

View File

@@ -68,7 +68,7 @@
</label>
</div>
<div id="resultContainer" hidden>
<div id="result">Result</div>
<a id="resultLeaveButton" href="#">Leave game</a>
</div>
<div class="playerBar" data-index="0">

View File

@@ -140,6 +140,7 @@ function showResult() {
if (currentGame == null) return;
midGameContainer.hidden = true;
resultContainer.hidden = false;
turnNumberLabel.setTurnNumber(null);
let winners = [ 0 ]; let maxPoints = playerBars[0].points;
for (let i = 1; i < currentGame.players.length; i++) {
@@ -158,18 +159,18 @@ function showResult() {
el.classList.add('win');
el.classList.remove('lose');
el.classList.remove('draw');
el.innerText = 'Win!';
el.innerText = 'Victory';
} else {
el.classList.remove('win');
el.classList.remove('lose');
el.classList.add('draw');
el.innerText = 'Draw!';
el.innerText = 'Draw';
}
} else {
el.classList.remove('win');
el.classList.add('lose');
el.classList.remove('draw');
el.innerText = 'Lose...';
el.innerText = 'Defeat';
}
}
}
@@ -306,3 +307,14 @@ board.onclick = (x, y) => {
board.autoHighlight = false;
}
};
document.getElementById('resultLeaveButton')!.addEventListener('click', e => {
e.preventDefault();
document.getElementById('preGameDefaultSection')!.hidden = false;
document.getElementById('preGameJoinSection')!.hidden = true;
window.location.hash = '#';
currentGame = null;
gameIDBox.value = '';
showSection('preGame');
newGameButton.focus();
});

View File

@@ -1,14 +1,16 @@
const newGameButton = document.getElementById('newGameButton')!;
const joinGameButton = document.getElementById('joinGameButton')!;
const nameBox = document.getElementById('nameBox') as HTMLInputElement;
const gameIDBox = document.getElementById('gameIDBox') as HTMLInputElement;
(document.getElementById('preGameForm') as HTMLFormElement).addEventListener('submit', e => {
e.preventDefault();
if (e.submitter?.id == 'joinGameButton') {
const name = (document.getElementById('nameBox') as HTMLInputElement).value;
const name = nameBox.value;
window.localStorage.setItem('name', name);
tryJoinGame(name, (document.getElementById('gameIDBox') as HTMLInputElement).value);
tryJoinGame(name, gameIDBox.value);
} else {
const name = (document.getElementById('nameBox') as HTMLInputElement).value;
const name = nameBox.value;
window.localStorage.setItem('name', name);
let request = new XMLHttpRequest();

View File

@@ -322,10 +322,6 @@ footer {
height: 28em;
}
#resultContainer {
display: none;
}
/* Score bar */
#scoreSection {