X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=tictactoe.js;h=5b8729e48568ff114bc3acc9884495ff61081062;hb=de78893aec1d5a4a0ae84610f2f01f78e9455f18;hp=766c1e4ed569cf9d2efb52bae9e7d70ffc6ce6fa;hpb=20ab7f84abd07b744d0c73f0dd54879ff884e534;p=empires-server diff --git a/tictactoe.js b/tictactoe.js index 766c1e4..5b8729e 100644 --- a/tictactoe.js +++ b/tictactoe.js @@ -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;