-
Notifications
You must be signed in to change notification settings - Fork 6
/
games.js
39 lines (31 loc) · 873 Bytes
/
games.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
const Game = require('./game');
const Games = function() {
this.games = {};
};
Games.prototype.getGame = function(gameId) {
return this.games[gameId];
};
Games.prototype.createGame = function(width, height, mines, name) {
var game = new Game(width, height, mines, name);
this.games[game.gameId] = game;
return game;
};
Games.prototype.removeUnoccupiedGames = function() {
for (let gameId in this.games) {
if (!this.games[gameId].hasConnectedPlayers() && !this.games[gameId].doNotDelete)
delete this.games[gameId];
}
};
Games.prototype.getGames = function() {
return this.games;
};
Games.prototype.getAvailableGames = function() {
var available = {};
for (let gameId in this.games) {
if (!this.games[gameId].hidden)
available[gameId] = this.games[gameId];
}
return available;
};
module.exports = new Games();