mirror of https://github.com/flutter/pinball.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
616 B
26 lines
616 B
3 years ago
|
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<GameEvent, GameState> {
|
||
|
GameBloc() : super(const GameState.initial()) {
|
||
|
on<BallLost>(_onBallLost);
|
||
|
on<Scored>(_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));
|
||
|
}
|
||
|
}
|
||
|
}
|