From 60bd974314eab573bc4029f1a97a0938f286e8e6 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Sat, 12 Sep 2020 14:50:35 -0500 Subject: [PATCH] Load in victory states when appropriate (#5) --- src/components/TopLevel.component.js | 6 ++++++ src/services/GameState.service.js | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/components/TopLevel.component.js b/src/components/TopLevel.component.js index e47d87c..2b8611d 100644 --- a/src/components/TopLevel.component.js +++ b/src/components/TopLevel.component.js @@ -162,6 +162,12 @@ export default class TopLevelComponent extends Component { this.ships_to_place = game_service.get_possible_boats() } + if ( next_state === GameState.PlayerVictory ) { + const [victor_state, loser_state] = game_service.get_player_victory_state() + this.player_rows = victor_state + this.opponent_rows = loser_state + } + this.instructions = instructions[this.current_state] }) } diff --git a/src/services/GameState.service.js b/src/services/GameState.service.js index 6e94f99..b84a3ea 100644 --- a/src/services/GameState.service.js +++ b/src/services/GameState.service.js @@ -203,6 +203,11 @@ export class GameStateService { }) } + /** + * Get the states that should be shown on the victory screen. + * First element is the winner's state, second element is the loser's state. + * @return {object[][][]} + */ get_player_victory_state(){ return [clone(this.player_x_game_board[this.current_player]), clone(this.player_x_game_board[this.current_opponent])] }