From 960203b5976f3be1ad96d91281258f834ca4f730 Mon Sep 17 00:00:00 2001 From: Evan Powell Date: Tue, 8 Sep 2020 20:16:43 -0500 Subject: [PATCH] added the logic of handling player one's turn then switching to player two's turn (#2) --- src/services/GameState.service.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/services/GameState.service.js b/src/services/GameState.service.js index 572a635..388b73a 100644 --- a/src/services/GameState.service.js +++ b/src/services/GameState.service.js @@ -253,12 +253,27 @@ export class GameStateService { //wait // because the place_ship handles all the validation // all you need to do is make sure they have placed all the appropriate ships - // e.g. if ( this.get_ship_entities(this.current_player).length === this.n_boats ) { ... } + if ( this.get_ship_entities(this.current_player).length === this.n_boats ) { + this.current_player = Player.Two; + this.current_opponent = Player.One; + } + else{ + throw new InvalidAdvanceStateError("Player One has a problem with the number of boats selected"); + } } if (this.current_player === Player.Two) { //wait for now + if ( this.get_ship_entities(this.current_player).length === this.n_boats ) { + this.current_state = GameState.PlayerTurn; + this.current_player = Player.One; + this.current_opponent = Player.Two; + } + else{ + throw new InvalidAdvanceStateError("Player Two has a problem with the number of boats selected"); + } } } + } /**