]> git.cworth.org Git - empires-server/blobdiff - tictactoe.js
Move some checks from TicTacToe.add_move to Game.add_move
[empires-server] / tictactoe.js
index 256afecde34d86fd12af215d089c0b6cae9edcee..d123c5718f01b5fb93280447d003f91e4eac1e1a 100644 (file)
@@ -15,19 +15,12 @@ class TicTacToe extends Game {
   /* Returns true if move was legal and added, false otherwise. */
   add_move(player, square) {
 
-    /* Cannot move if you are not on a team. */
-    if (player.team === "")
-    {
-      return { legal: false,
-               message: "You must be on a team to take a turn" };
-    }
+    const result = super.add_move(player, square);
 
-    /* Cannot move if it's not this player's team's turn. */
-    if (player.team !== this.state.team_to_play)
-    {
-      return { legal: false,
-               message: "It's not your turn to move" };
-    }
+    /* If the generic Game class can reject this move, then we don't
+     * need to look at it any further. */
+    if (! result.legal)
+      return result;
 
     /* Cannot move to an occupied square. */
     if (this.state.board[square])