Erneutes Spielen sicherer Gemacht
This commit is contained in:
@@ -186,16 +186,16 @@ class Snake{
|
|||||||
const exsitingtile = this.playground.getTile(tile.x, tile.y);
|
const exsitingtile = this.playground.getTile(tile.x, tile.y);
|
||||||
|
|
||||||
// TODO: Klammert man das ein Kann man alleine Spielen, da es keine Kolisionserkennung gibt
|
// TODO: Klammert man das ein Kann man alleine Spielen, da es keine Kolisionserkennung gibt
|
||||||
// if(exsitingtile === undefined){
|
if(exsitingtile === undefined){
|
||||||
// // End Game weil außerhalb des Spielfeldes
|
// End Game weil außerhalb des Spielfeldes
|
||||||
// await this.game.endGame(`${this.player.username} hat die Wand berührt!`);
|
await this.game.endGame(`${this.player.username} hat die Wand berührt!`);
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
// if(exsitingtile?.class === "Snake"){
|
if(exsitingtile?.class === "Snake"){
|
||||||
// // Eng Game weil schon belegt mit anderer oder eigender Schlange
|
// Eng Game weil schon belegt mit anderer oder eigender Schlange
|
||||||
// await this.game.endGame(`Es gab eine Kollision!`);
|
await this.game.endGame(`Es gab eine Kollision!`);
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
|
|
||||||
this.playground.setTile(tile.x, tile.y, tile);
|
this.playground.setTile(tile.x, tile.y, tile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,9 @@ class Game{
|
|||||||
Nur wenn noch beide Spieler da sind
|
Nur wenn noch beide Spieler da sind
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
let replayPossible = false;
|
||||||
|
const replayTime = 5000;
|
||||||
|
|
||||||
if(this.players.length === 2){
|
if(this.players.length === 2){
|
||||||
const lobbyManager = this.gameManager.lobbyManager;
|
const lobbyManager = this.gameManager.lobbyManager;
|
||||||
|
|
||||||
@@ -92,16 +95,22 @@ class Game{
|
|||||||
0,
|
0,
|
||||||
newUserList,
|
newUserList,
|
||||||
lobbyManager,
|
lobbyManager,
|
||||||
10000
|
replayTime
|
||||||
);
|
);
|
||||||
|
|
||||||
lobbyManager.oldLobbys.push(tempLobby);
|
lobbyManager.oldLobbys.push(tempLobby);
|
||||||
|
|
||||||
|
replayPossible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.io.to(`game-${this.code}`).emit("gameEnd", {
|
this.io.to(`game-${this.code}`).emit("gameEnd", {
|
||||||
msg: msg,
|
msg: msg,
|
||||||
score: this.score,
|
score: this.score,
|
||||||
rang: scoreDb?.rank || "-"
|
rang: scoreDb?.rank || "-",
|
||||||
|
replay: {
|
||||||
|
possible: replayPossible,
|
||||||
|
time: replayTime
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -118,9 +118,14 @@ class UIManager{
|
|||||||
|
|
||||||
endDiv.appendChild(scoreDiv);
|
endDiv.appendChild(scoreDiv);
|
||||||
|
|
||||||
const replayButton = document.createElement("button");
|
if(data.replay.possible){
|
||||||
replayButton.id = "replayBtn";
|
this.replayContainer = document.createElement("div");
|
||||||
replayButton.innerHTML = `
|
this.replayContainer.id = "replayContainer"; // ID für den Container
|
||||||
|
endDiv.appendChild(this.replayContainer);
|
||||||
|
|
||||||
|
this.replayButton = document.createElement("button");
|
||||||
|
this.replayButton.id = "replayBtn";
|
||||||
|
this.replayButton.innerHTML = `
|
||||||
<div class="buttonIcon">
|
<div class="buttonIcon">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="40px" viewBox="0 -960 960 960" width="40px" fill="#FFFFFF">
|
<svg xmlns="http://www.w3.org/2000/svg" height="40px" viewBox="0 -960 960 960" width="40px" fill="#FFFFFF">
|
||||||
<path d="M447.33-122Q325-133.67 242.5-224.5 160-315.33 160-439.33q0-73.34 32.33-138.84 32.34-65.5
|
<path d="M447.33-122Q325-133.67 242.5-224.5 160-315.33 160-439.33q0-73.34 32.33-138.84 32.34-65.5
|
||||||
@@ -134,8 +139,20 @@ class UIManager{
|
|||||||
Neue Runde
|
Neue Runde
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
replayButton.addEventListener("click", () => { window.location.href = "/game" })
|
this.replayButton.addEventListener("click", () => { window.location.href = "/game"; });
|
||||||
endDiv.appendChild(replayButton);
|
this.replayContainer.appendChild(this.replayButton);
|
||||||
|
|
||||||
|
this.timeText = document.createElement("p");
|
||||||
|
this.timeText.id = "timeText";
|
||||||
|
this.timeText.innerText = `Möglichkeit für nächste: ${data.replay.time / 1000} Sekunden`;
|
||||||
|
this.replayContainer.appendChild(this.timeText);
|
||||||
|
|
||||||
|
this.time = data.replay.time;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this.timerTimeOut();
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
const dashButton = document.createElement("button");
|
const dashButton = document.createElement("button");
|
||||||
dashButton.id = "leaveBtn";
|
dashButton.id = "leaveBtn";
|
||||||
@@ -155,6 +172,20 @@ class UIManager{
|
|||||||
dashButton.addEventListener("click", () => { window.location.href = "/dashboard" })
|
dashButton.addEventListener("click", () => { window.location.href = "/dashboard" })
|
||||||
endDiv.appendChild(dashButton);
|
endDiv.appendChild(dashButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timerTimeOut(){
|
||||||
|
this.time -= 1000;
|
||||||
|
|
||||||
|
const newTime = this.time / 1000;
|
||||||
|
this.timeText.innerText = `Möglichkeit für nächste: ${newTime} Sekunden`
|
||||||
|
if(newTime <= 0){
|
||||||
|
this.replayContainer.style.display = "none";
|
||||||
|
}else{
|
||||||
|
setTimeout(() => {
|
||||||
|
this.timerTimeOut();
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default UIManager;
|
export default UIManager;
|
||||||
@@ -107,3 +107,10 @@ img{
|
|||||||
#replayBtn{
|
#replayBtn{
|
||||||
background-color: orange;
|
background-color: orange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#replayContainer{
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user