refactor: renamed ballsLeft to balls

pull/3/head
alestiago 4 years ago
parent 27c0f322af
commit 870dafd77f

@ -6,14 +6,14 @@ part 'game_event.dart';
part 'game_state.dart';
class GameBloc extends Bloc<GameEvent, GameState> {
GameBloc() : super(const GameState(score: 0, ballsLeft: 3)) {
GameBloc() : super(const GameState(score: 0, balls: 3)) {
on<BallLost>(_onBallLost);
on<Scored>(_onScored);
}
void _onBallLost(BallLost event, Emitter emit) {
if (state.ballsLeft > 0) {
emit(state.copyWith(ballsLeft: state.ballsLeft - 1));
if (state.balls > 0) {
emit(state.copyWith(balls: state.balls - 1));
}
}

@ -3,27 +3,27 @@ part of 'game_bloc.dart';
class GameState extends Equatable {
const GameState({
required this.score,
required this.ballsLeft,
required this.balls,
});
final int score;
final int ballsLeft;
final int balls;
bool get isGameOver => ballsLeft == 0;
bool get isGameOver => balls == 0;
GameState copyWith({
int? score,
int? ballsLeft,
int? balls,
}) {
return GameState(
score: score ?? this.score,
ballsLeft: ballsLeft ?? this.ballsLeft,
balls: balls ?? this.balls,
);
}
@override
List<Object?> get props => [
score,
ballsLeft,
balls,
];
}

Loading…
Cancel
Save