X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=tictactoe.js;h=f9198432826376426d5d5a527e145bfe71f9e172;hb=92382a8dd4bfc9c83b7cf5fa1c0981b01096efd0;hp=35019840cc13a68fa225482610876e9c5c3b5932;hpb=b5a5c28f09756d7a7e65dd2bc75de130bc71e0dd;p=lmno-server diff --git a/tictactoe.js b/tictactoe.js index 3501984..f919843 100644 --- a/tictactoe.js +++ b/tictactoe.js @@ -13,10 +13,28 @@ class TicTacToe extends Game { } /* Returns true if move was legal and added, false otherwise. */ - add_move(square) { + 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" }; + } + + /* Cannot move if it's not this player's team's turn. */ + if (player.team !== this.state.next_player) + { + return { legal: false, + message: "It's not your turn to move" }; + } + /* Cannot move to an occupied square. */ if (this.state.board[square]) - return { legal: false, message: "Square is already occupied" }; + { + return { legal: false, + message: "Square is already occupied" }; + } this.state.board[square] = this.state.next_player; this.state.moves.push(square);