]> git.cworth.org Git - empires-server/commitdiff
Plumb a game's ID value down into the base class
authorCarl Worth <cworth@cworth.org>
Mon, 1 Jun 2020 00:47:28 +0000 (17:47 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 1 Jun 2020 00:47:28 +0000 (17:47 -0700)
Since, whenever anyone has a reference to a game, it can be handy to
be able to query its ID value.

empires.js
game.js
lmno.js
tictactoe.js

index 3072a121e68c98d0ac060218437c4e53860ae0a5..cb7571d67ef3ff81934593cf76c8b5c407c65ce6 100644 (file)
@@ -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 fb2d75afa87214f1eaa4fe426772ca59f39e24f3..706bfc7a153353358d0064f0b15deed18f44f09e 100644 (file)
--- 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 69e445a24e3ab1fde24bdc4df4a0e50c059ff993..0fd491a6293bf01672ba7d896ecea16689ce89b5 100644 (file)
--- 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,
index 11b4295df247ced277c82d8f1501369483a7a4e0..aba043c65eba8c1dbe04ef6034c6d54b8fa8fee1 100644 (file)
@@ -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);
   }