]> git.cworth.org Git - empires-server/blobdiff - tictactoe.js
Add new game.js with a new parent class Game
[empires-server] / tictactoe.js
index 766c1e4ed569cf9d2efb52bae9e7d70ffc6ce6fa..5b8729e48568ff114bc3acc9884495ff61081062 100644 (file)
@@ -1,9 +1,13 @@
 const express = require("express");
+const Game = require("./game.js");
 
-const app = express.Router();
+const engine_name = "tictactoe";
 
-class TicTacToe {
+const router = express.Router();
+
+class TicTacToe extends Game {
   constructor() {
+    super(engine_name);
     this.moves = [];
     this.board = Array(9).fill(null);
     this.clients = [];
@@ -54,7 +58,7 @@ class TicTacToe {
   }
 }
 
-app.get('/', (request, response) => {
+router.get('/', (request, response) => {
   const game = request.game;
 
   if (! request.session.nickname)
@@ -63,7 +67,7 @@ app.get('/', (request, response) => {
     response.render('tictactoe-game.html');
 });
 
-app.post('/move', (request, response) => {
+router.post('/move', (request, response) => {
   const game = request.game;
   const square = request.body.square;
 
@@ -79,7 +83,7 @@ app.post('/move', (request, response) => {
   game.broadcast_move(square);
 });
 
-app.get('/events', (request, response) => {
+router.get('/events', (request, response) => {
   const game = request.game;
 
   /* These headers will keep the connection open so we can stream events. */
@@ -99,6 +103,6 @@ app.get('/events', (request, response) => {
   });
 });
 
-exports.app = app;
-exports.name = "tictactoe";
+exports.router = router;
+exports.name = engine_name;
 exports.Game = TicTacToe;