refactor: multiplier max value 6 at game bloc

pull/213/head
RuiAlonso 3 years ago
parent 1658c895f5
commit 3e2e5fbae0

@ -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<GameEvent, GameState> {
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),
),
);
}
}

@ -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<Object?> get props => [];

@ -160,6 +160,31 @@ void main() {
],
);
blocTest<GameBloc, GameState>(
"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<GameBloc, GameState>(
"doesn't increase multiplier "
'when game is over',

Loading…
Cancel
Save