From f66fe176b8ed7406c3400538f5b2fe652f41e2fc Mon Sep 17 00:00:00 2001 From: Allison Ryan Date: Sun, 8 May 2022 08:27:49 -0500 Subject: [PATCH] chore: update round lost logic --- lib/game/bloc/game_bloc.dart | 7 +++++-- test/game/bloc/game_bloc_test.dart | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/game/bloc/game_bloc.dart b/lib/game/bloc/game_bloc.dart index 08afb383..c63bf514 100644 --- a/lib/game/bloc/game_bloc.dart +++ b/lib/game/bloc/game_bloc.dart @@ -16,7 +16,7 @@ class GameBloc extends Bloc { on(_onGameStarted); } - final _maxScore = 9999999999; + static const _maxScore = 9999999999; void _onGameStarted(GameStarted _, Emitter emit) { emit(state.copyWith(status: GameStatus.playing)); @@ -27,7 +27,10 @@ class GameBloc extends Bloc { } void _onRoundLost(RoundLost event, Emitter emit) { - final score = state.totalScore + state.roundScore * state.multiplier; + final score = math.min( + state.totalScore + state.roundScore * state.multiplier, + _maxScore, + ); final roundsLeft = math.max(state.rounds - 1, 0); emit( diff --git a/test/game/bloc/game_bloc_test.dart b/test/game/bloc/game_bloc_test.dart index 74d852c1..2108b950 100644 --- a/test/game/bloc/game_bloc_test.dart +++ b/test/game/bloc/game_bloc_test.dart @@ -91,6 +91,28 @@ void main() { ], ); + blocTest( + "multiplier doesn't increase score above the max score", + build: GameBloc.new, + seed: () => const GameState( + totalScore: 9999999998, + roundScore: 1, + multiplier: 2, + rounds: 1, + bonusHistory: [], + status: GameStatus.playing, + ), + act: (bloc) => bloc.add(const RoundLost()), + expect: () => [ + isA() + ..having( + (state) => state.totalScore, + 'totalScore', + 9999999999, + ) + ], + ); + blocTest( 'resets multiplier when round is lost', build: GameBloc.new,