]> git.cworth.org Git - empires-server/commitdiff
Rename "next_player" property to "team_to_play"
authorCarl Worth <cworth@cworth.org>
Fri, 5 Jun 2020 20:54:28 +0000 (13:54 -0700)
committerCarl Worth <cworth@cworth.org>
Fri, 5 Jun 2020 20:54:28 +0000 (13:54 -0700)
The game object already has two distinct notions of players and
teams. And this property will only be compared to team values, not
player values, so this name is more accurate and less confusing.

tictactoe.js

index f9198432826376426d5d5a527e145bfe71f9e172..256afecde34d86fd12af215d089c0b6cae9edcee 100644 (file)
@@ -7,7 +7,7 @@ class TicTacToe extends Game {
     this.state = {
       moves: [],
       board: Array(9).fill(""),
-      next_player: "X",
+      team_to_play: "X",
     };
     this.teams = ["X", "O"];
   }
@@ -23,7 +23,7 @@ class TicTacToe extends Game {
     }
 
     /* Cannot move if it's not this player's team's turn. */
-    if (player.team !== this.state.next_player)
+    if (player.team !== this.state.team_to_play)
     {
       return { legal: false,
                message: "It's not your turn to move" };
@@ -36,13 +36,13 @@ class TicTacToe extends Game {
                message: "Square is already occupied" };
     }
 
-    this.state.board[square] = this.state.next_player;
+    this.state.board[square] = this.state.team_to_play;
     this.state.moves.push(square);
 
-    if (this.state.next_player === "X")
-      this.state.next_player = "O";
+    if (this.state.team_to_play === "X")
+      this.state.team_to_play = "O";
     else
-      this.state.next_player = "X";
+      this.state.team_to_play = "X";
 
     return { legal: true };
   }