From 48026578b36151fdb09186f4fd5166db6c67c09a Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sun, 31 May 2020 17:47:28 -0700 Subject: [PATCH] Plumb a game's ID value down into the base class Since, whenever anyone has a reference to a game, it can be handy to be able to query its ID value. --- empires.js | 4 ++-- game.js | 3 ++- lmno.js | 2 +- tictactoe.js | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/empires.js b/empires.js index 3072a12..cb7571d 100644 --- a/empires.js +++ b/empires.js @@ -32,8 +32,8 @@ function shuffle(a) { } class Empires extends Game { - constructor() { - super(); + constructor(id) { + super(id); this._spectators = []; this.next_spectator_id = 1; this._players = []; diff --git a/game.js b/game.js index fb2d75a..706bfc7 100644 --- a/game.js +++ b/game.js @@ -1,6 +1,7 @@ /* Base class providing common code for game engine implementations. */ class Game { - constructor() { + constructor(id) { + this.id = id; this.clients = []; this.next_client_id = 1; } diff --git a/lmno.js b/lmno.js index 69e445a..0fd491a 100644 --- a/lmno.js +++ b/lmno.js @@ -68,7 +68,7 @@ class LMNO { const engine = engines[engine_name]; - const game = new engine.Game(); + const game = new engine.Game(id); this.games[id] = { id: id, diff --git a/tictactoe.js b/tictactoe.js index 11b4295..aba043c 100644 --- a/tictactoe.js +++ b/tictactoe.js @@ -4,8 +4,8 @@ const Game = require("./game.js"); const router = express.Router(); class TicTacToe extends Game { - constructor() { - super(); + constructor(id) { + super(id); this.moves = []; this.board = Array(9).fill(null); } -- 2.43.0