Skip to content
Snippets Groups Projects
Commit 23860e8b authored by zm343's avatar zm343
Browse files

Restart code

parent 4f81a10e
No related branches found
No related tags found
1 merge request!16Potential restart
......@@ -41,6 +41,27 @@ class WebSocketModel {
}
}
const alivePlayers = this.games[game].players.filter(
(player) => !player.spectating
);
if (alivePlayers.length === 1) {
const winner = alivePlayers[0].pid;;
for (let conn of this.games[game].players) {
conn.connection.send(
JSON.stringify({
type: "restart",
pid: winner
}),
);
}
this.resetGame(game);
return;
}
for (let conn of this.games[game].players) {
let playerView = null;
if (conn.spectating) {
......@@ -100,6 +121,18 @@ class WebSocketModel {
this.createInterval(gameId);
}
resetGame(gameId) {
this.games[gameId].gameBoard = gameModule.createGameBoard(100, 100);
this.games[gameId].players.forEach((player) => {
player.spectating = false;
});
this.games[gameId].started = false;
this.games[gameId].readyPlayers = 0;
this.games[gameId].borderCounter = 0;
this.games[gameId].numPlayers = 0;
this.games[gameId].elapsedTime = 0;
}
moveHandler(connection, message) {
console.log("Received move: " + message.data);
let movement = message.data;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment