refactor: removed active sparky bumper from game bloc logic

pull/154/head
RuiAlonso 4 years ago
parent 4aa67f62d5
commit ecae568d97

@ -13,7 +13,6 @@ class GameBloc extends Bloc<GameEvent, GameState> {
on<Scored>(_onScored); on<Scored>(_onScored);
on<BonusLetterActivated>(_onBonusLetterActivated); on<BonusLetterActivated>(_onBonusLetterActivated);
on<DashNestActivated>(_onDashNestActivated); on<DashNestActivated>(_onDashNestActivated);
on<SparkyFireActivated>(_onSparkyFireActivated);
} }
static const bonusWord = 'GOOGLE'; static const bonusWord = 'GOOGLE';
@ -78,23 +77,4 @@ class GameBloc extends Bloc<GameEvent, GameState> {
); );
} }
} }
void _onSparkyFireActivated(SparkyFireActivated event, Emitter emit) {
var newFires = <String>{};
if (state.activatedSparkyFires.contains(event.fireId)) {
newFires = state.activatedSparkyFires.difference({event.fireId});
} else {
newFires = {
...state.activatedSparkyFires,
event.fireId,
};
}
emit(
state.copyWith(
activatedSparkyFires: newFires,
),
);
}
} }

@ -54,12 +54,3 @@ class DashNestActivated extends GameEvent {
@override @override
List<Object?> get props => [nestId]; List<Object?> get props => [nestId];
} }
class SparkyFireActivated extends GameEvent {
const SparkyFireActivated(this.fireId);
final String fireId;
@override
List<Object?> get props => [fireId];
}

@ -23,7 +23,6 @@ class GameState extends Equatable {
required this.activatedBonusLetters, required this.activatedBonusLetters,
required this.bonusHistory, required this.bonusHistory,
required this.activatedDashNests, required this.activatedDashNests,
required this.activatedSparkyFires,
}) : assert(score >= 0, "Score can't be negative"), }) : assert(score >= 0, "Score can't be negative"),
assert(balls >= 0, "Number of balls can't be negative"); assert(balls >= 0, "Number of balls can't be negative");
@ -32,7 +31,6 @@ class GameState extends Equatable {
balls = 3, balls = 3,
activatedBonusLetters = const [], activatedBonusLetters = const [],
activatedDashNests = const {}, activatedDashNests = const {},
activatedSparkyFires = const {},
bonusHistory = const []; bonusHistory = const [];
/// The current score of the game. /// The current score of the game.
@ -49,9 +47,6 @@ class GameState extends Equatable {
/// Active dash nests. /// Active dash nests.
final Set<String> activatedDashNests; final Set<String> activatedDashNests;
/// Active sparky fires.
final Set<String> activatedSparkyFires;
/// Holds the history of all the [GameBonus]es earned by the player during a /// Holds the history of all the [GameBonus]es earned by the player during a
/// PinballGame. /// PinballGame.
final List<GameBonus> bonusHistory; final List<GameBonus> bonusHistory;
@ -68,7 +63,6 @@ class GameState extends Equatable {
int? balls, int? balls,
List<int>? activatedBonusLetters, List<int>? activatedBonusLetters,
Set<String>? activatedDashNests, Set<String>? activatedDashNests,
Set<String>? activatedSparkyFires,
List<GameBonus>? bonusHistory, List<GameBonus>? bonusHistory,
}) { }) {
assert( assert(
@ -82,7 +76,6 @@ class GameState extends Equatable {
activatedBonusLetters: activatedBonusLetters:
activatedBonusLetters ?? this.activatedBonusLetters, activatedBonusLetters ?? this.activatedBonusLetters,
activatedDashNests: activatedDashNests ?? this.activatedDashNests, activatedDashNests: activatedDashNests ?? this.activatedDashNests,
activatedSparkyFires: activatedSparkyFires ?? this.activatedSparkyFires,
bonusHistory: bonusHistory ?? this.bonusHistory, bonusHistory: bonusHistory ?? this.bonusHistory,
); );
} }
@ -93,7 +86,6 @@ class GameState extends Equatable {
balls, balls,
activatedBonusLetters, activatedBonusLetters,
activatedDashNests, activatedDashNests,
activatedSparkyFires,
bonusHistory, bonusHistory,
]; ];
} }

@ -25,7 +25,6 @@ void main() {
balls: 2, balls: 2,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
], ],
@ -46,7 +45,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
const GameState( const GameState(
@ -54,7 +52,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
], ],
@ -76,7 +73,6 @@ void main() {
balls: 2, balls: 2,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
const GameState( const GameState(
@ -84,7 +80,6 @@ void main() {
balls: 1, balls: 1,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
const GameState( const GameState(
@ -92,7 +87,6 @@ void main() {
balls: 0, balls: 0,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
], ],
@ -113,7 +107,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [0], activatedBonusLetters: [0],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
GameState( GameState(
@ -121,7 +114,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [0, 1], activatedBonusLetters: [0, 1],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
GameState( GameState(
@ -129,7 +121,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [0, 1, 2], activatedBonusLetters: [0, 1, 2],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
], ],
@ -151,7 +142,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [0], activatedBonusLetters: [0],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
GameState( GameState(
@ -159,7 +149,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [0, 1], activatedBonusLetters: [0, 1],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
GameState( GameState(
@ -167,7 +156,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [0, 1, 2], activatedBonusLetters: [0, 1, 2],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
GameState( GameState(
@ -175,7 +163,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [0, 1, 2, 3], activatedBonusLetters: [0, 1, 2, 3],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
GameState( GameState(
@ -183,7 +170,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [0, 1, 2, 3, 4], activatedBonusLetters: [0, 1, 2, 3, 4],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
GameState( GameState(
@ -191,7 +177,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [GameBonus.word], bonusHistory: [GameBonus.word],
), ),
GameState( GameState(
@ -199,7 +184,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [GameBonus.word], bonusHistory: [GameBonus.word],
), ),
], ],
@ -220,7 +204,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {'0'}, activatedDashNests: {'0'},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
GameState( GameState(
@ -228,7 +211,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {'0', '1'}, activatedDashNests: {'0', '1'},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
GameState( GameState(
@ -236,45 +218,10 @@ void main() {
balls: 4, balls: 4,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [GameBonus.dashNest], bonusHistory: [GameBonus.dashNest],
), ),
], ],
); );
}); });
group('SparkyFireActivated', () {
const fireId = '0';
blocTest<GameBloc, GameState>(
'adds fireId to collection when activate',
build: GameBloc.new,
act: (bloc) => bloc..add(const SparkyFireActivated(fireId)),
expect: () => [
isA<GameState>()
..having(
(state) => state.activatedSparkyFires,
'activatedSparkyFires',
contains(fireId),
),
],
);
blocTest<GameBloc, GameState>(
'removes fireId from collection when deactivate',
build: GameBloc.new,
seed: () =>
GameState.initial().copyWith(activatedSparkyFires: {fireId}),
act: (bloc) => bloc..add(const SparkyFireActivated(fireId)),
expect: () => [
isA<GameState>()
..having(
(state) => state.activatedSparkyFires,
'activatedSparkyFires',
isNot(contains(fireId)),
),
],
);
});
}); });
} }

@ -84,22 +84,5 @@ void main() {
); );
}); });
}); });
group('SparkyFireActivated', () {
test('can be instantiated', () {
expect(const SparkyFireActivated('0'), isNotNull);
});
test('supports value equality', () {
expect(
SparkyFireActivated('0'),
equals(SparkyFireActivated('0')),
);
expect(
SparkyFireActivated('0'),
isNot(equals(SparkyFireActivated('1'))),
);
});
});
}); });
} }

@ -12,7 +12,6 @@ void main() {
balls: 0, balls: 0,
activatedBonusLetters: const [], activatedBonusLetters: const [],
activatedDashNests: const {}, activatedDashNests: const {},
activatedSparkyFires: const {},
bonusHistory: const [], bonusHistory: const [],
), ),
equals( equals(
@ -21,7 +20,6 @@ void main() {
balls: 0, balls: 0,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
), ),
@ -36,7 +34,6 @@ void main() {
balls: 0, balls: 0,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
), ),
isNotNull, isNotNull,
@ -54,7 +51,6 @@ void main() {
score: 0, score: 0,
activatedBonusLetters: const [], activatedBonusLetters: const [],
activatedDashNests: const {}, activatedDashNests: const {},
activatedSparkyFires: const {},
bonusHistory: const [], bonusHistory: const [],
), ),
throwsAssertionError, throwsAssertionError,
@ -72,7 +68,6 @@ void main() {
score: -1, score: -1,
activatedBonusLetters: const [], activatedBonusLetters: const [],
activatedDashNests: const {}, activatedDashNests: const {},
activatedSparkyFires: const {},
bonusHistory: const [], bonusHistory: const [],
), ),
throwsAssertionError, throwsAssertionError,
@ -89,7 +84,6 @@ void main() {
score: 0, score: 0,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
); );
expect(gameState.isGameOver, isTrue); expect(gameState.isGameOver, isTrue);
@ -103,7 +97,6 @@ void main() {
score: 0, score: 0,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
); );
expect(gameState.isGameOver, isFalse); expect(gameState.isGameOver, isFalse);
@ -119,7 +112,6 @@ void main() {
score: 0, score: 0,
activatedBonusLetters: [1], activatedBonusLetters: [1],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
); );
expect(gameState.isLetterActivated(1), isTrue); expect(gameState.isLetterActivated(1), isTrue);
@ -134,7 +126,6 @@ void main() {
score: 0, score: 0,
activatedBonusLetters: [1], activatedBonusLetters: [1],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
); );
expect(gameState.isLetterActivated(0), isFalse); expect(gameState.isLetterActivated(0), isFalse);
@ -152,7 +143,6 @@ void main() {
score: 2, score: 2,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
); );
expect( expect(
@ -171,7 +161,6 @@ void main() {
score: 2, score: 2,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
); );
expect( expect(
@ -190,7 +179,6 @@ void main() {
balls: 0, balls: 0,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
); );
final otherGameState = GameState( final otherGameState = GameState(
@ -198,7 +186,6 @@ void main() {
balls: gameState.balls + 1, balls: gameState.balls + 1,
activatedBonusLetters: const [0], activatedBonusLetters: const [0],
activatedDashNests: const {'1'}, activatedDashNests: const {'1'},
activatedSparkyFires: const {'1'},
bonusHistory: const [GameBonus.word], bonusHistory: const [GameBonus.word],
); );
expect(gameState, isNot(equals(otherGameState))); expect(gameState, isNot(equals(otherGameState)));
@ -209,7 +196,6 @@ void main() {
balls: otherGameState.balls, balls: otherGameState.balls,
activatedBonusLetters: otherGameState.activatedBonusLetters, activatedBonusLetters: otherGameState.activatedBonusLetters,
activatedDashNests: otherGameState.activatedDashNests, activatedDashNests: otherGameState.activatedDashNests,
activatedSparkyFires: otherGameState.activatedSparkyFires,
bonusHistory: otherGameState.bonusHistory, bonusHistory: otherGameState.bonusHistory,
), ),
equals(otherGameState), equals(otherGameState),

@ -264,7 +264,6 @@ void main() {
balls: 2, balls: 2,
activatedBonusLetters: [0], activatedBonusLetters: [0],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
); );
whenListen( whenListen(
@ -293,7 +292,6 @@ void main() {
balls: 2, balls: 2,
activatedBonusLetters: [0], activatedBonusLetters: [0],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
); );
@ -337,7 +335,6 @@ void main() {
balls: 2, balls: 2,
activatedBonusLetters: [index], activatedBonusLetters: [index],
activatedDashNests: const {}, activatedDashNests: const {},
activatedSparkyFires: const {},
bonusHistory: const [], bonusHistory: const [],
); );

@ -88,7 +88,6 @@ void main() {
balls: 3, balls: 3,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [GameBonus.dashNest], bonusHistory: [GameBonus.dashNest],
); );

@ -14,7 +14,6 @@ void main() {
balls: 2, balls: 2,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
); );

@ -89,7 +89,6 @@ void main() {
balls: 0, balls: 0,
activatedBonusLetters: [], activatedBonusLetters: [],
activatedDashNests: {}, activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [], bonusHistory: [],
); );

Loading…
Cancel
Save