From a7b8d60c1e6cb2bacecd906a690da6103ae85065 Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Fri, 22 Apr 2022 09:36:21 +0200 Subject: [PATCH] refactor: multiplier always increased by 1 --- lib/game/bloc/game_bloc.dart | 4 +++- lib/game/bloc/game_event.dart | 8 ++------ pubspec.lock | 27 +++++++++++++++++---------- test/game/bloc/game_bloc_test.dart | 6 +++--- test/game/bloc/game_event_test.dart | 16 +++------------- 5 files changed, 28 insertions(+), 33 deletions(-) diff --git a/lib/game/bloc/game_bloc.dart b/lib/game/bloc/game_bloc.dart index dce20813..28c04902 100644 --- a/lib/game/bloc/game_bloc.dart +++ b/lib/game/bloc/game_bloc.dart @@ -32,7 +32,9 @@ class GameBloc extends Bloc { void _onIncreasedMultiplier(MultiplierIncreased event, Emitter emit) { if (!state.isGameOver) { - emit(state.copyWith(multiplier: state.multiplier + event.increase)); + // TODO(ruimiguel): confirm that x6 is going to be the max value, to add + // assertion here or at MultiplierIncreased event const. + emit(state.copyWith(multiplier: state.multiplier + 1)); } } diff --git a/lib/game/bloc/game_event.dart b/lib/game/bloc/game_event.dart index 983012de..7b30aace 100644 --- a/lib/game/bloc/game_event.dart +++ b/lib/game/bloc/game_event.dart @@ -54,14 +54,10 @@ class SparkyTurboChargeActivated extends GameEvent { /// {@endtemplate} class MultiplierIncreased extends GameEvent { /// {@macro multiplier_increased_game_event} - const MultiplierIncreased({ - required this.increase, - }) : assert(increase > 0, 'Increase must be greater than 0'); - - final int increase; + const MultiplierIncreased(); @override - List get props => [increase]; + List get props => []; } /// {@template multiplier_applied_game_event} diff --git a/pubspec.lock b/pubspec.lock index 31aed6af..1a502f37 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,14 +7,14 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "39.0.0" + version: "31.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "2.8.0" args: dependency: transitive description: @@ -71,6 +71,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.1" + cli_util: + dependency: transitive + description: + name: cli_util + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.5" clock: dependency: transitive description: @@ -314,7 +321,7 @@ packages: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.4" + version: "0.6.3" json_annotation: dependency: transitive description: @@ -349,7 +356,7 @@ packages: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.3" meta: dependency: transitive description: @@ -412,7 +419,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.0" path_provider: dependency: transitive description: @@ -585,7 +592,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -627,21 +634,21 @@ packages: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.21.1" + version: "1.19.5" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.8" test_core: dependency: transitive description: name: test_core url: "https://pub.dartlang.org" source: hosted - version: "0.4.13" + version: "0.4.9" typed_data: dependency: transitive description: @@ -662,7 +669,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.2" + version: "2.1.1" very_good_analysis: dependency: "direct dev" description: diff --git a/test/game/bloc/game_bloc_test.dart b/test/game/bloc/game_bloc_test.dart index b31ea0d5..45f68bdb 100644 --- a/test/game/bloc/game_bloc_test.dart +++ b/test/game/bloc/game_bloc_test.dart @@ -91,8 +91,8 @@ void main() { 'when game is not over', build: GameBloc.new, act: (bloc) => bloc - ..add(const MultiplierIncreased(increase: 1)) - ..add(const MultiplierIncreased(increase: 1)), + ..add(const MultiplierIncreased()) + ..add(const MultiplierIncreased()), expect: () => [ const GameState( score: 0, @@ -117,7 +117,7 @@ void main() { for (var i = 0; i < bloc.state.balls; i++) { bloc.add(const BallLost()); } - bloc.add(const MultiplierIncreased(increase: 1)); + bloc.add(const MultiplierIncreased()); }, expect: () => [ const GameState( diff --git a/test/game/bloc/game_event_test.dart b/test/game/bloc/game_event_test.dart index 7ed4b6f4..ce0712ff 100644 --- a/test/game/bloc/game_event_test.dart +++ b/test/game/bloc/game_event_test.dart @@ -43,24 +43,14 @@ void main() { group('MultiplierIncreased', () { test('can be instantiated', () { - expect(const MultiplierIncreased(increase: 1), isNotNull); + expect(const MultiplierIncreased(), isNotNull); }); test('supports value equality', () { expect( - MultiplierIncreased(increase: 1), - equals(const MultiplierIncreased(increase: 1)), + MultiplierIncreased(), + equals(const MultiplierIncreased()), ); - expect( - const MultiplierIncreased(increase: 1), - isNot(equals(const MultiplierIncreased(increase: 2))), - ); - }); - - test( - 'throws AssertionError ' - 'when increase is smaller than 1', () { - expect(() => MultiplierIncreased(increase: 0), throwsAssertionError); }); });