chore: update round lost logic

pull/408/head
Allison Ryan 3 years ago
parent 931bf54cb8
commit f66fe176b8

@ -16,7 +16,7 @@ class GameBloc extends Bloc<GameEvent, GameState> {
on<GameStarted>(_onGameStarted); on<GameStarted>(_onGameStarted);
} }
final _maxScore = 9999999999; static const _maxScore = 9999999999;
void _onGameStarted(GameStarted _, Emitter emit) { void _onGameStarted(GameStarted _, Emitter emit) {
emit(state.copyWith(status: GameStatus.playing)); emit(state.copyWith(status: GameStatus.playing));
@ -27,7 +27,10 @@ class GameBloc extends Bloc<GameEvent, GameState> {
} }
void _onRoundLost(RoundLost event, Emitter emit) { void _onRoundLost(RoundLost event, Emitter emit) {
final score = state.totalScore + state.roundScore * state.multiplier; final score = math.min(
state.totalScore + state.roundScore * state.multiplier,
_maxScore,
);
final roundsLeft = math.max(state.rounds - 1, 0); final roundsLeft = math.max(state.rounds - 1, 0);
emit( emit(

@ -91,6 +91,28 @@ void main() {
], ],
); );
blocTest<GameBloc, GameState>(
"multiplier doesn't increase score above the max score",
build: GameBloc.new,
seed: () => const GameState(
totalScore: 9999999998,
roundScore: 1,
multiplier: 2,
rounds: 1,
bonusHistory: [],
status: GameStatus.playing,
),
act: (bloc) => bloc.add(const RoundLost()),
expect: () => [
isA<GameState>()
..having(
(state) => state.totalScore,
'totalScore',
9999999999,
)
],
);
blocTest<GameBloc, GameState>( blocTest<GameBloc, GameState>(
'resets multiplier when round is lost', 'resets multiplier when round is lost',
build: GameBloc.new, build: GameBloc.new,

Loading…
Cancel
Save