Skip to content
Snippets Groups Projects
Commit 444f763a authored by zm343's avatar zm343
Browse files

Border Game Code

parent cc5116b3
Branches
No related tags found
1 merge request!138 deadplayers
......@@ -11,6 +11,7 @@ class WebSocketModel {
type: "public",
started: false,
readyPlayers: 0,
borderCounter: 0,
};
this.games["game2"] = {
gameBoard: gameModule.createGameBoard(10, 10),
......@@ -18,6 +19,7 @@ class WebSocketModel {
type: "public",
started: false,
readyPlayers: 0,
borderCounter: 0,
};
this.games["game3"] = {
gameBoard: gameModule.createGameBoard(10, 10),
......@@ -25,6 +27,7 @@ class WebSocketModel {
type: "public",
started: false,
readyPlayers: 0,
borderCounter: 0,
};
this.sockserver = new WebSocketServer({ port: 3001 });
......@@ -37,6 +40,22 @@ class WebSocketModel {
this.games[game].gameBoard = gameModule.moveOneStep(
this.games[game].gameBoard,
);
if (!this.games[game].elapsedTime) {
this.games[game].elapsedTime = 0;
}
this.games[game].elapsedTime++;
//Every 10 seconds, generate borders
if (this.games[game].elapsedTime % 10 === 0) {
this.games[game].gameBoard = gameModule.applyBorders(
this.games[game].gameBoard,
this.games[game].borderCounter
);
this.games[game].borderCounter++;
}
for (let conn of this.games[game].players) {
conn.send(
JSON.stringify({
......@@ -68,6 +87,7 @@ class WebSocketModel {
type: gameType,
started: false,
readyPlayers: 0,
borderCounter: 0,
};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment