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'; part 'game_state.dart';
class GameBloc extends Bloc<GameEvent, GameState> { 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<BallLost>(_onBallLost);
on<Scored>(_onScored); on<Scored>(_onScored);
} }
void _onBallLost(BallLost event, Emitter emit) { void _onBallLost(BallLost event, Emitter emit) {
if (state.ballsLeft > 0) { if (state.balls > 0) {
emit(state.copyWith(ballsLeft: state.ballsLeft - 1)); emit(state.copyWith(balls: state.balls - 1));
} }
} }

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

Loading…
Cancel
Save