import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:meta/meta.dart'; part 'game_event.dart'; part 'game_state.dart'; class GameBloc extends Bloc { GameBloc() : super(const GameState.initial()) { on(_onBallLost); on(_onScored); } void _onBallLost(BallLost event, Emitter emit) { if (state.balls > 0) { emit(state.copyWith(balls: state.balls - 1)); } } void _onScored(Scored event, Emitter emit) { if (!state.isGameOver) { emit(state.copyWith(score: state.score + event.points)); } } }