From 3e2e5fbae0410067bcb4fec2a6ad62a0f158d66c Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Fri, 22 Apr 2022 14:03:04 +0200 Subject: [PATCH] refactor: multiplier max value 6 at game bloc --- lib/game/bloc/game_bloc.dart | 8 ++++++-- lib/game/bloc/game_event.dart | 2 -- test/game/bloc/game_bloc_test.dart | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/game/bloc/game_bloc.dart b/lib/game/bloc/game_bloc.dart index dc31bbf3..3fff28f4 100644 --- a/lib/game/bloc/game_bloc.dart +++ b/lib/game/bloc/game_bloc.dart @@ -1,5 +1,5 @@ // ignore_for_file: public_member_api_docs - +import 'dart:math' as math; import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:meta/meta.dart'; @@ -49,7 +49,11 @@ class GameBloc extends Bloc { void _onIncreasedMultiplier(MultiplierIncreased event, Emitter emit) { if (!state.isGameOver) { - emit(state.copyWith(multiplier: state.multiplier + 1)); + emit( + state.copyWith( + multiplier: math.min(state.multiplier + 1, 6), + ), + ); } } diff --git a/lib/game/bloc/game_event.dart b/lib/game/bloc/game_event.dart index 39f7260b..8497669b 100644 --- a/lib/game/bloc/game_event.dart +++ b/lib/game/bloc/game_event.dart @@ -59,8 +59,6 @@ class SparkyTurboChargeActivated extends GameEvent { class MultiplierIncreased extends GameEvent { /// {@macro multiplier_increased_game_event} const MultiplierIncreased(); - // TODO(ruimiguel): confirm that x6 is going to be the max value, to add - // assertion here @override List get props => []; diff --git a/test/game/bloc/game_bloc_test.dart b/test/game/bloc/game_bloc_test.dart index 02752b07..8c46a52c 100644 --- a/test/game/bloc/game_bloc_test.dart +++ b/test/game/bloc/game_bloc_test.dart @@ -160,6 +160,31 @@ void main() { ], ); + blocTest( + "doesn't increase multiplier " + 'when multiplier is 6 and game is not over', + build: GameBloc.new, + seed: () => const GameState( + score: 0, + multiplier: 5, + balls: 3, + rounds: 3, + bonusHistory: [], + ), + act: (bloc) => bloc + ..add(const MultiplierIncreased()) + ..add(const MultiplierIncreased()), + expect: () => [ + const GameState( + score: 0, + multiplier: 6, + balls: 3, + rounds: 3, + bonusHistory: [], + ), + ], + ); + blocTest( "doesn't increase multiplier " 'when game is over',