Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Blocking new users from joining a game in progress.

  • Loading branch information...
commit 05ded426b0e06c4e67382b2754554c3834bcc8f6 1 parent a3cda57
@rhussmann rhussmann authored
Showing with 8 additions and 1 deletion.
  1. +8 −1 lib/gamemanager.js
View
9 lib/gamemanager.js
@@ -82,6 +82,11 @@ GameManager.prototype.addUser = function(client, username) {
}
var existingGame = this.getCurrentGame();
+ // Is the game in progress?
+ if (existingGame.inProgress) {
+ return {success: false, reason: "Game in progress"};
+ }
+
// Is the game full?
if (existingGame.isFull()) {
return {success: false, reason: "Game is full"};
@@ -284,6 +289,7 @@ GameManager.prototype.placeShips = function(client, locations) {
var startGameMsg = {type: "gamestart", msg: "FRUIT!!!"};
game.playas.forEach(function(element) {
console.log("Alerting " + element.username + " game is starting");
+ game.inProgress = true;
var aConnection = manager.connections[element.username];
aConnection.client.send(JSON.stringify(startGameMsg));
});
@@ -312,7 +318,8 @@ function Game() {
this.name = this.battleNames[Math.floor(Math.random()*this.battleNames.length)];
this.playas = [];
this.currentPlaya = 0;
- this.maxPlayers = 5;
+ this.maxPlayers = 3;
+ this.inProgress = false;
// listeners
this.on("winner", function () {
Please sign in to comment.
Something went wrong with that request. Please try again.