]> git.cworth.org Git - empires-server/commitdiff
Add the barest template of an implementation of a tictactoe game
authorCarl Worth <cworth@cworth.org>
Tue, 26 May 2020 03:36:09 +0000 (20:36 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 26 May 2020 03:55:29 +0000 (20:55 -0700)
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.)

lmno.js
templates/tictactoe-game.html [new file with mode: 0644]
tictactoe.js [new file with mode: 0644]

diff --git a/lmno.js b/lmno.js
index 61c7f5cce5eed2f4cb84c1dd75d4e779ff9888b1..8e84473e148abf29d777dc7965941104d0bcd72d 100644 (file)
--- 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 (file)
index 0000000..f80ebf4
--- /dev/null
@@ -0,0 +1,20 @@
+{% extends "base.html" %}
+
+{% block head %}
+<link rel="stylesheet" href="/tictactoe/tictactoe.css" type="text/css" />
+
+<script src="/react.js"></script>
+<script src="/react-dom.js"></script>
+<script type="module" src="/tictactoe/tictactoe.js"></script>
+{% endblock %}
+
+{% block page %}
+<h1>Tic Tac Toe</h1>
+
+<p>
+  Just the classic game.
+</p>
+
+<div id="tictactoe"></div>
+
+{% endblock %}
diff --git a/tictactoe.js b/tictactoe.js
new file mode 100644 (file)
index 0000000..18fe342
--- /dev/null
@@ -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;