chore: set max score

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

@ -16,6 +16,8 @@ class GameBloc extends Bloc<GameEvent, GameState> {
on<GameStarted>(_onGameStarted); on<GameStarted>(_onGameStarted);
} }
final _maxScore = 9999999999;
void _onGameStarted(GameStarted _, Emitter emit) { void _onGameStarted(GameStarted _, Emitter emit) {
emit(state.copyWith(status: GameStatus.playing)); emit(state.copyWith(status: GameStatus.playing));
} }
@ -41,9 +43,11 @@ class GameBloc extends Bloc<GameEvent, GameState> {
void _onScored(Scored event, Emitter emit) { void _onScored(Scored event, Emitter emit) {
if (state.status.isPlaying) { if (state.status.isPlaying) {
emit( final combinedScore = math.min(
state.copyWith(roundScore: state.roundScore + event.points), state.totalScore + state.roundScore + event.points,
_maxScore,
); );
emit(state.copyWith(roundScore: combinedScore - state.totalScore));
} }
} }

@ -167,6 +167,23 @@ void main() {
), ),
], ],
); );
blocTest<GameBloc, GameState>(
"doesn't increase score above the max score",
build: GameBloc.new,
seed: () => const GameState(
totalScore: 9999999998,
roundScore: 0,
multiplier: 1,
rounds: 1,
bonusHistory: [],
status: GameStatus.playing,
),
act: (bloc) => bloc.add(const Scored(points: 2)),
expect: () => [
isA<GameState>()..having((state) => state.roundScore, 'roundScore', 1)
],
);
}); });
group('MultiplierIncreased', () { group('MultiplierIncreased', () {

Loading…
Cancel
Save