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<BonusLetterActivated>(_onBonusLetterActivated);
on<DashNestActivated>(_onDashNestActivated);
on<SparkyFireActivated>(_onSparkyFireActivated);
}
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
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.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,7 +31,6 @@ class GameState extends Equatable {
balls = 3,
activatedBonusLetters = const [],
activatedDashNests = const {},
activatedSparkyFires = const {},
bonusHistory = const [];
/// The current score of the game.
@ -49,9 +47,6 @@ class GameState extends Equatable {
/// Active dash nests.
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
/// PinballGame.
final List<GameBonus> bonusHistory;
@ -68,7 +63,6 @@ class GameState extends Equatable {
int? balls,
List<int>? activatedBonusLetters,
Set<String>? activatedDashNests,
Set<String>? activatedSparkyFires,
List<GameBonus>? bonusHistory,
}) {
assert(
@ -82,7 +76,6 @@ class GameState extends Equatable {
activatedBonusLetters:
activatedBonusLetters ?? this.activatedBonusLetters,
activatedDashNests: activatedDashNests ?? this.activatedDashNests,
activatedSparkyFires: activatedSparkyFires ?? this.activatedSparkyFires,
bonusHistory: bonusHistory ?? this.bonusHistory,
);
}
@ -93,7 +86,6 @@ class GameState extends Equatable {
balls,
activatedBonusLetters,
activatedDashNests,
activatedSparkyFires,
bonusHistory,
];
}

@ -25,7 +25,6 @@ void main() {
balls: 2,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
],
@ -46,7 +45,6 @@ void main() {
balls: 3,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
const GameState(
@ -54,7 +52,6 @@ void main() {
balls: 3,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
],
@ -76,7 +73,6 @@ void main() {
balls: 2,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
const GameState(
@ -84,7 +80,6 @@ void main() {
balls: 1,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
const GameState(
@ -92,7 +87,6 @@ void main() {
balls: 0,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
],
@ -113,7 +107,6 @@ void main() {
balls: 3,
activatedBonusLetters: [0],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
GameState(
@ -121,7 +114,6 @@ void main() {
balls: 3,
activatedBonusLetters: [0, 1],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
GameState(
@ -129,7 +121,6 @@ void main() {
balls: 3,
activatedBonusLetters: [0, 1, 2],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
],
@ -151,7 +142,6 @@ void main() {
balls: 3,
activatedBonusLetters: [0],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
GameState(
@ -159,7 +149,6 @@ void main() {
balls: 3,
activatedBonusLetters: [0, 1],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
GameState(
@ -167,7 +156,6 @@ void main() {
balls: 3,
activatedBonusLetters: [0, 1, 2],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
GameState(
@ -175,7 +163,6 @@ void main() {
balls: 3,
activatedBonusLetters: [0, 1, 2, 3],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
GameState(
@ -183,7 +170,6 @@ void main() {
balls: 3,
activatedBonusLetters: [0, 1, 2, 3, 4],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
GameState(
@ -191,7 +177,6 @@ void main() {
balls: 3,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [GameBonus.word],
),
GameState(
@ -199,7 +184,6 @@ void main() {
balls: 3,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [GameBonus.word],
),
],
@ -220,7 +204,6 @@ void main() {
balls: 3,
activatedBonusLetters: [],
activatedDashNests: {'0'},
activatedSparkyFires: {},
bonusHistory: [],
),
GameState(
@ -228,7 +211,6 @@ void main() {
balls: 3,
activatedBonusLetters: [],
activatedDashNests: {'0', '1'},
activatedSparkyFires: {},
bonusHistory: [],
),
GameState(
@ -236,45 +218,10 @@ void main() {
balls: 4,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
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,
activatedBonusLetters: const [],
activatedDashNests: const {},
activatedSparkyFires: const {},
bonusHistory: const [],
),
equals(
@ -21,7 +20,6 @@ void main() {
balls: 0,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
),
@ -36,7 +34,6 @@ void main() {
balls: 0,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
),
isNotNull,
@ -54,7 +51,6 @@ void main() {
score: 0,
activatedBonusLetters: const [],
activatedDashNests: const {},
activatedSparkyFires: const {},
bonusHistory: const [],
),
throwsAssertionError,
@ -72,7 +68,6 @@ void main() {
score: -1,
activatedBonusLetters: const [],
activatedDashNests: const {},
activatedSparkyFires: const {},
bonusHistory: const [],
),
throwsAssertionError,
@ -89,7 +84,6 @@ void main() {
score: 0,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
);
expect(gameState.isGameOver, isTrue);
@ -103,7 +97,6 @@ void main() {
score: 0,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
);
expect(gameState.isGameOver, isFalse);
@ -119,7 +112,6 @@ void main() {
score: 0,
activatedBonusLetters: [1],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
);
expect(gameState.isLetterActivated(1), isTrue);
@ -134,7 +126,6 @@ void main() {
score: 0,
activatedBonusLetters: [1],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
);
expect(gameState.isLetterActivated(0), isFalse);
@ -152,7 +143,6 @@ void main() {
score: 2,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
);
expect(
@ -171,7 +161,6 @@ void main() {
score: 2,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
);
expect(
@ -190,7 +179,6 @@ void main() {
balls: 0,
activatedBonusLetters: [],
activatedDashNests: {},
activatedSparkyFires: {},
bonusHistory: [],
);
final otherGameState = GameState(
@ -198,7 +186,6 @@ void main() {
balls: gameState.balls + 1,
activatedBonusLetters: const [0],
activatedDashNests: const {'1'},
activatedSparkyFires: const {'1'},
bonusHistory: const [GameBonus.word],
);
expect(gameState, isNot(equals(otherGameState)));
@ -209,7 +196,6 @@ void main() {
balls: otherGameState.balls,
activatedBonusLetters: otherGameState.activatedBonusLetters,
activatedDashNests: otherGameState.activatedDashNests,
activatedSparkyFires: otherGameState.activatedSparkyFires,
bonusHistory: otherGameState.bonusHistory,
),
equals(otherGameState),

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

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

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

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

Loading…
Cancel
Save