refactor: multiplier always increased by 1

pull/213/head
RuiAlonso 3 years ago
parent 52066c2eb8
commit a7b8d60c1e

@ -32,7 +32,9 @@ class GameBloc extends Bloc<GameEvent, GameState> {
void _onIncreasedMultiplier(MultiplierIncreased event, Emitter emit) { void _onIncreasedMultiplier(MultiplierIncreased event, Emitter emit) {
if (!state.isGameOver) { 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));
} }
} }

@ -54,14 +54,10 @@ class SparkyTurboChargeActivated extends GameEvent {
/// {@endtemplate} /// {@endtemplate}
class MultiplierIncreased extends GameEvent { class MultiplierIncreased extends GameEvent {
/// {@macro multiplier_increased_game_event} /// {@macro multiplier_increased_game_event}
const MultiplierIncreased({ const MultiplierIncreased();
required this.increase,
}) : assert(increase > 0, 'Increase must be greater than 0');
final int increase;
@override @override
List<Object?> get props => [increase]; List<Object?> get props => [];
} }
/// {@template multiplier_applied_game_event} /// {@template multiplier_applied_game_event}

@ -7,14 +7,14 @@ packages:
name: _fe_analyzer_shared name: _fe_analyzer_shared
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "39.0.0" version: "31.0.0"
analyzer: analyzer:
dependency: transitive dependency: transitive
description: description:
name: analyzer name: analyzer
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.0.0" version: "2.8.0"
args: args:
dependency: transitive dependency: transitive
description: description:
@ -71,6 +71,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.1" version: "1.3.1"
cli_util:
dependency: transitive
description:
name: cli_util
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.5"
clock: clock:
dependency: transitive dependency: transitive
description: description:
@ -314,7 +321,7 @@ packages:
name: js name: js
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.6.4" version: "0.6.3"
json_annotation: json_annotation:
dependency: transitive dependency: transitive
description: description:
@ -349,7 +356,7 @@ packages:
name: material_color_utilities name: material_color_utilities
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.4" version: "0.1.3"
meta: meta:
dependency: transitive dependency: transitive
description: description:
@ -412,7 +419,7 @@ packages:
name: path name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.1" version: "1.8.0"
path_provider: path_provider:
dependency: transitive dependency: transitive
description: description:
@ -585,7 +592,7 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.2" version: "1.8.1"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
@ -627,21 +634,21 @@ packages:
name: test name: test
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.21.1" version: "1.19.5"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.9" version: "0.4.8"
test_core: test_core:
dependency: transitive dependency: transitive
description: description:
name: test_core name: test_core
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.13" version: "0.4.9"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
@ -662,7 +669,7 @@ packages:
name: vector_math name: vector_math
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.2" version: "2.1.1"
very_good_analysis: very_good_analysis:
dependency: "direct dev" dependency: "direct dev"
description: description:

@ -91,8 +91,8 @@ void main() {
'when game is not over', 'when game is not over',
build: GameBloc.new, build: GameBloc.new,
act: (bloc) => bloc act: (bloc) => bloc
..add(const MultiplierIncreased(increase: 1)) ..add(const MultiplierIncreased())
..add(const MultiplierIncreased(increase: 1)), ..add(const MultiplierIncreased()),
expect: () => [ expect: () => [
const GameState( const GameState(
score: 0, score: 0,
@ -117,7 +117,7 @@ void main() {
for (var i = 0; i < bloc.state.balls; i++) { for (var i = 0; i < bloc.state.balls; i++) {
bloc.add(const BallLost()); bloc.add(const BallLost());
} }
bloc.add(const MultiplierIncreased(increase: 1)); bloc.add(const MultiplierIncreased());
}, },
expect: () => [ expect: () => [
const GameState( const GameState(

@ -43,24 +43,14 @@ void main() {
group('MultiplierIncreased', () { group('MultiplierIncreased', () {
test('can be instantiated', () { test('can be instantiated', () {
expect(const MultiplierIncreased(increase: 1), isNotNull); expect(const MultiplierIncreased(), isNotNull);
}); });
test('supports value equality', () { test('supports value equality', () {
expect( expect(
MultiplierIncreased(increase: 1), MultiplierIncreased(),
equals(const MultiplierIncreased(increase: 1)), 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);
}); });
}); });

Loading…
Cancel
Save