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