From: Carl Worth Date: Tue, 26 May 2020 03:36:09 +0000 (-0700) Subject: Add the barest template of an implementation of a tictactoe game X-Git-Url: https://git.cworth.org/git?p=empires-server;a=commitdiff_plain;h=d04124365041fb3d9606a0aa56b49a2147565038 Add the barest template of an implementation of a tictactoe game This supports only the ability to select a nickname (which is provided by lmno.js), and then the serving of minimal HTML into which the tictactoe React cient can render itself. There is not yet here any implementation of API endpoints specific to the tictactoe game. Those will have to come later. (So, for now, each player that joins a game of Tic Tac Toe will have an independent game without any communication between them.) --- diff --git a/lmno.js b/lmno.js index 61c7f5c..8e84473 100644 --- a/lmno.js +++ b/lmno.js @@ -48,6 +48,7 @@ nunjucks.configure("templates", { /* Load each of our game mini-apps. */ var empires = require("./empires"); +var tictactoe = require("./tictactoe"); class LMNO { constructor() { @@ -240,6 +241,7 @@ app.get('/admin/', auth_admin, (request, response) => { /* Mount sub apps. only _after_ we have done all the middleware we need. */ app.use('/empires/[a-zA-Z0-9]{4}/', empires.app); +app.use('/tictactoe/[a-zA-Z0-9]{4}/', tictactoe.app); app.listen(4000, function () { console.log('LMNO server listening on localhost:4000'); diff --git a/templates/tictactoe-game.html b/templates/tictactoe-game.html new file mode 100644 index 0000000..f80ebf4 --- /dev/null +++ b/templates/tictactoe-game.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} + +{% block head %} + + + + + +{% endblock %} + +{% block page %} +

Tic Tac Toe

+ +

+ Just the classic game. +

+ +
+ +{% endblock %} diff --git a/tictactoe.js b/tictactoe.js new file mode 100644 index 0000000..18fe342 --- /dev/null +++ b/tictactoe.js @@ -0,0 +1,26 @@ +const express = require("express"); +const cors = require("cors"); +const body_parser = require("body-parser"); +const path = require("path"); +const nunjucks = require("nunjucks"); + +const app = express(); +app.use(cors()); +app.use(body_parser.urlencoded({ extended: false })); +app.use(body_parser.json()); + +nunjucks.configure("templates", { + autoescape: true, + express: app +}); + +app.get('/', (request, response) => { + const game = request.game; + + if (! request.session.nickname) + response.render('choose-nickname.html', { game_name: "Tic Tac Toe" }); + else + response.render('tictactoe-game.html'); +}); + +exports.app = app;