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

Border Game Code

parent cc5116b3
No related branches found
No related tags found
Loading
...@@ -11,6 +11,7 @@ class WebSocketModel { ...@@ -11,6 +11,7 @@ class WebSocketModel {
type: "public", type: "public",
started: false, started: false,
readyPlayers: 0, readyPlayers: 0,
borderCounter: 0,
}; };
this.games["game2"] = { this.games["game2"] = {
gameBoard: gameModule.createGameBoard(10, 10), gameBoard: gameModule.createGameBoard(10, 10),
...@@ -18,6 +19,7 @@ class WebSocketModel { ...@@ -18,6 +19,7 @@ class WebSocketModel {
type: "public", type: "public",
started: false, started: false,
readyPlayers: 0, readyPlayers: 0,
borderCounter: 0,
}; };
this.games["game3"] = { this.games["game3"] = {
gameBoard: gameModule.createGameBoard(10, 10), gameBoard: gameModule.createGameBoard(10, 10),
...@@ -25,6 +27,7 @@ class WebSocketModel { ...@@ -25,6 +27,7 @@ class WebSocketModel {
type: "public", type: "public",
started: false, started: false,
readyPlayers: 0, readyPlayers: 0,
borderCounter: 0,
}; };
this.sockserver = new WebSocketServer({ port: 3001 }); this.sockserver = new WebSocketServer({ port: 3001 });
...@@ -37,6 +40,22 @@ class WebSocketModel { ...@@ -37,6 +40,22 @@ class WebSocketModel {
this.games[game].gameBoard = gameModule.moveOneStep( this.games[game].gameBoard = gameModule.moveOneStep(
this.games[game].gameBoard, 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) { for (let conn of this.games[game].players) {
conn.send( conn.send(
JSON.stringify({ JSON.stringify({
...@@ -68,6 +87,7 @@ class WebSocketModel { ...@@ -68,6 +87,7 @@ class WebSocketModel {
type: gameType, type: gameType,
started: false, started: false,
readyPlayers: 0, readyPlayers: 0,
borderCounter: 0,
}; };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment