});
/* Load each of our game mini-apps. */
-var empires = require("./empires");
-var tictactoe = require("./tictactoe");
+const engines = {
+ empires: require("./empires"),
+ tictactoe: require("./tictactoe")
+};
class LMNO {
constructor() {
return Array(4).fill(null).map(() => LMNO.letters.charAt(Math.floor(Math.random() * LMNO.letters.length))).join('');
}
- create_game(engine) {
+ create_game(engine_name) {
do {
var id = this.generate_id();
} while (id in this.ids);
- const game = new empires.Game();
+ const engine = engines[engine_name];
+
+ const game = new engine.Game();
this.ids[id] = {
- id: id,
- engine: engine,
- game: game
+ id: id,
+ engine: engine.name,
+ game: game
};
return id;
/* 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);
+for (let key in engines) {
+ const engine = engines[key];
+ app.use(`/${engine.name}/[a-zA-Z0-9]{4}/`, engine.app);
+}
app.listen(4000, function () {
console.log('LMNO server listening on localhost:4000');