From: Carl Worth Date: Mon, 1 Jun 2020 00:47:28 +0000 (-0700) Subject: Plumb a game's ID value down into the base class X-Git-Url: https://git.cworth.org/git?p=empires-server;a=commitdiff_plain;h=48026578b36151fdb09186f4fd5166db6c67c09a 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. --- 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); }