From ce030c346e1d6dc5f186d16787071173aec8d5d2 Mon Sep 17 00:00:00 2001 From: Evan Powell Date: Tue, 8 Sep 2020 20:35:06 -0500 Subject: [PATCH] added the logic for ensuring the player had fired a missle and the flow of the game in terms of the players' turns (#2) --- src/services/GameState.service.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/services/GameState.service.js b/src/services/GameState.service.js index 78e030d..f491215 100644 --- a/src/services/GameState.service.js +++ b/src/services/GameState.service.js @@ -278,8 +278,31 @@ export class GameStateService { throw new InvalidAdvanceStateError("Player Two has a problem with the number of boats selected"); } } + + + } + if (this.current_state === GameState.PlayerTurn && this.current_player === Player.One) { + + if (this.current_turn_had_missile_attempt === true) { + this.current_player = Player.Two; + this.current_opponent = Player.One; + } + else { + throw new InvalidAdvanceStateError("the player has not fired a missle"); + } + } + if (this.current_state === GameState.PlayerTurn && this.current_player === Player.Two) { + + if (this.current_turn_had_missile_attempt === true) { + this.current_player = Player.One; + this.current_opponent = Player.Two; + } + else { + throw new InvalidAdvanceStateError("the player has not fired a missle"); + } } + } /**