diff --git a/lib/game/bloc/game_bloc.dart b/lib/game/bloc/game_bloc.dart index c02417a7..524329b2 100644 --- a/lib/game/bloc/game_bloc.dart +++ b/lib/game/bloc/game_bloc.dart @@ -13,6 +13,7 @@ class GameBloc extends Bloc { on(_onScored); on(_onBonusLetterActivated); on(_onDashNestActivated); + on(_onSparkyFireActivated); } static const bonusWord = 'GOOGLE'; @@ -77,4 +78,23 @@ class GameBloc extends Bloc { ); } } + + void _onSparkyFireActivated(SparkyFireActivated event, Emitter emit) { + var newFires = {}; + + if (state.activatedSparkyFires.contains(event.fireId)) { + newFires = state.activatedSparkyFires.difference({event.fireId}); + } else { + newFires = { + ...state.activatedSparkyFires, + event.fireId, + }; + } + + emit( + state.copyWith( + activatedSparkyFires: newFires, + ), + ); + } } diff --git a/lib/game/bloc/game_event.dart b/lib/game/bloc/game_event.dart index b05c5336..fc5dcdb6 100644 --- a/lib/game/bloc/game_event.dart +++ b/lib/game/bloc/game_event.dart @@ -54,3 +54,12 @@ class DashNestActivated extends GameEvent { @override List get props => [nestId]; } + +class SparkyFireActivated extends GameEvent { + const SparkyFireActivated(this.fireId); + + final String fireId; + + @override + List get props => [fireId]; +} diff --git a/lib/game/bloc/game_state.dart b/lib/game/bloc/game_state.dart index d08ba04b..63892e2c 100644 --- a/lib/game/bloc/game_state.dart +++ b/lib/game/bloc/game_state.dart @@ -24,6 +24,7 @@ class GameState extends Equatable { required this.activatedBonusLetters, required this.bonusHistory, required this.activatedDashNests, + required this.activatedSparkyFires, }) : assert(score >= 0, "Score can't be negative"), assert(balls >= 0, "Number of balls can't be negative"); @@ -32,6 +33,7 @@ class GameState extends Equatable { balls = 3, activatedBonusLetters = const [], activatedDashNests = const {}, + activatedSparkyFires = const {}, bonusHistory = const []; /// The current score of the game. @@ -48,6 +50,9 @@ class GameState extends Equatable { /// Active dash nests. final Set activatedDashNests; + /// Active sparky fires. + final Set activatedSparkyFires; + /// Holds the history of all the [GameBonus]es earned by the player during a /// PinballGame. final List bonusHistory; @@ -64,6 +69,7 @@ class GameState extends Equatable { int? balls, List? activatedBonusLetters, Set? activatedDashNests, + Set? activatedSparkyFires, List? bonusHistory, }) { assert( @@ -77,6 +83,7 @@ class GameState extends Equatable { activatedBonusLetters: activatedBonusLetters ?? this.activatedBonusLetters, activatedDashNests: activatedDashNests ?? this.activatedDashNests, + activatedSparkyFires: activatedSparkyFires ?? this.activatedSparkyFires, bonusHistory: bonusHistory ?? this.bonusHistory, ); } @@ -87,6 +94,7 @@ class GameState extends Equatable { balls, activatedBonusLetters, activatedDashNests, + activatedSparkyFires, bonusHistory, ]; }