const express = require("express");
const Game = require("./game.js");
-const engine_name = "tictactoe";
-
const router = express.Router();
class TicTacToe extends Game {
- constructor() {
- super(engine_name);
+ constructor(id) {
+ super(id);
this.moves = [];
- this.board = Array(9).fill(null);
+ this.board = Array(9).fill("");
+ this.next_player = "X";
}
/* Returns Boolean indicating whether move was legal and added. */
if (this.board[square])
return false;
- this.board[square] = 'X';
+ this.board[square] = this.next_player;
this.moves.push(square);
+ if (this.next_player === "X")
+ this.next_player = "O";
+ else
+ this.next_player = "X";
+
return true;
}
}
}
-router.get('/', (request, response) => {
- const game = request.game;
-
- if (! request.session.nickname)
- response.render('choose-nickname.html', { game_name: game.meta.name });
- else
- response.render('tictactoe-game.html');
-});
-
router.post('/move', (request, response) => {
const game = request.game;
const square = request.body.square;
});
exports.router = router;
-exports.name = engine_name;
exports.Game = TicTacToe;
TicTacToe.meta = {
- name: "Tic Tac Toe"
+ name: "Tic Tac Toe",
+ identifier: "tictactoe"
};
-
-exports.meta = TicTacToe.meta;