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) {
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}
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<Object?> get props => [increase];
List<Object?> get props => [];
}
/// {@template multiplier_applied_game_event}

@ -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:

@ -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(

@ -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);
});
});

Loading…
Cancel
Save