|
|
@ -34,80 +34,177 @@ void main() {
|
|
|
|
Assets.images.score.oneMillion.keyName,
|
|
|
|
Assets.images.score.oneMillion.keyName,
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
group('ScoringContactBehavior', () {
|
|
|
|
late GameBloc bloc;
|
|
|
|
group('beginContact', () {
|
|
|
|
late Ball ball;
|
|
|
|
late GameBloc bloc;
|
|
|
|
late BodyComponent parent;
|
|
|
|
late Ball ball;
|
|
|
|
|
|
|
|
late BodyComponent parent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
|
|
|
|
ball = _MockBall();
|
|
|
|
|
|
|
|
final ballBody = _MockBody();
|
|
|
|
|
|
|
|
when(() => ball.body).thenReturn(ballBody);
|
|
|
|
|
|
|
|
when(() => ballBody.position).thenReturn(Vector2.all(4));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parent = _TestBodyComponent();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final flameBlocTester = FlameBlocTester<EmptyPinballTestGame, GameBloc>(
|
|
|
|
|
|
|
|
gameBuilder: EmptyPinballTestGame.new,
|
|
|
|
|
|
|
|
blocBuilder: () {
|
|
|
|
|
|
|
|
bloc = _MockGameBloc();
|
|
|
|
|
|
|
|
const state = GameState(
|
|
|
|
|
|
|
|
score: 0,
|
|
|
|
|
|
|
|
multiplier: 1,
|
|
|
|
|
|
|
|
rounds: 3,
|
|
|
|
|
|
|
|
bonusHistory: [],
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
whenListen(bloc, Stream.value(state), initialState: state);
|
|
|
|
|
|
|
|
return bloc;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
assets: assets,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
setUp(() {
|
|
|
|
'emits Scored event with points',
|
|
|
|
ball = _MockBall();
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
final ballBody = _MockBody();
|
|
|
|
const points = Points.oneMillion;
|
|
|
|
when(() => ball.body).thenReturn(ballBody);
|
|
|
|
final behavior = ScoringContactBehavior(points: points);
|
|
|
|
when(() => ballBody.position).thenReturn(Vector2.all(4));
|
|
|
|
await parent.add(behavior);
|
|
|
|
|
|
|
|
final canvas = ZCanvasComponent(children: [parent]);
|
|
|
|
parent = _TestBodyComponent();
|
|
|
|
await game.ensureAdd(canvas);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
behavior.beginContact(ball, _MockContact());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify(
|
|
|
|
|
|
|
|
() => bloc.add(
|
|
|
|
|
|
|
|
Scored(points: points.value),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
).called(1);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
final flameBlocTester = FlameBlocTester<EmptyPinballTestGame, GameBloc>(
|
|
|
|
"adds a ScoreComponent at Ball's position with points",
|
|
|
|
gameBuilder: EmptyPinballTestGame.new,
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
blocBuilder: () {
|
|
|
|
const points = Points.oneMillion;
|
|
|
|
bloc = _MockGameBloc();
|
|
|
|
final behavior = ScoringContactBehavior(points: points);
|
|
|
|
const state = GameState(
|
|
|
|
await parent.add(behavior);
|
|
|
|
score: 0,
|
|
|
|
final canvas = ZCanvasComponent(children: [parent]);
|
|
|
|
multiplier: 1,
|
|
|
|
await game.ensureAdd(canvas);
|
|
|
|
rounds: 3,
|
|
|
|
|
|
|
|
bonusHistory: [],
|
|
|
|
behavior.beginContact(ball, _MockContact());
|
|
|
|
);
|
|
|
|
await game.ready();
|
|
|
|
whenListen(bloc, Stream.value(state), initialState: state);
|
|
|
|
|
|
|
|
return bloc;
|
|
|
|
final scoreText = game.descendants().whereType<ScoreComponent>();
|
|
|
|
},
|
|
|
|
expect(scoreText.length, equals(1));
|
|
|
|
assets: assets,
|
|
|
|
expect(
|
|
|
|
);
|
|
|
|
scoreText.first.points,
|
|
|
|
|
|
|
|
equals(points),
|
|
|
|
group('ScoringBehavior', () {
|
|
|
|
);
|
|
|
|
test('can be instantiated', () {
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
scoreText.first.position,
|
|
|
|
ScoringBehavior(
|
|
|
|
equals(ball.body.position),
|
|
|
|
points: Points.fiveThousand,
|
|
|
|
);
|
|
|
|
position: Vector2.zero(),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
isA<ScoringBehavior>(),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
|
|
|
|
'can be loaded',
|
|
|
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
|
|
|
final canvas = ZCanvasComponent(children: [parent]);
|
|
|
|
|
|
|
|
final behavior = ScoringBehavior(
|
|
|
|
|
|
|
|
points: Points.fiveThousand,
|
|
|
|
|
|
|
|
position: Vector2.zero(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await parent.add(behavior);
|
|
|
|
|
|
|
|
await game.ensureAdd(canvas);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
|
|
|
parent.firstChild<ScoringBehavior>(),
|
|
|
|
|
|
|
|
equals(behavior),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
|
|
|
|
'emits Scored event with points when added',
|
|
|
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
|
|
|
const points = Points.oneMillion;
|
|
|
|
|
|
|
|
final canvas = ZCanvasComponent(children: [parent]);
|
|
|
|
|
|
|
|
await game.ensureAdd(canvas);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final behavior = ScoringBehavior(
|
|
|
|
|
|
|
|
points: points,
|
|
|
|
|
|
|
|
position: Vector2(0, 0),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await parent.ensureAdd(behavior);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify(
|
|
|
|
|
|
|
|
() => bloc.add(
|
|
|
|
|
|
|
|
Scored(points: points.value),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
).called(1);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
|
|
|
|
'correctly renders text',
|
|
|
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
|
|
|
final canvas = ZCanvasComponent(children: [parent]);
|
|
|
|
|
|
|
|
await game.ensureAdd(canvas);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const points = Points.oneMillion;
|
|
|
|
|
|
|
|
final position = Vector2.all(1);
|
|
|
|
|
|
|
|
final behavior = ScoringBehavior(
|
|
|
|
|
|
|
|
points: points,
|
|
|
|
|
|
|
|
position: position,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await parent.ensureAdd(behavior);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final scoreText = game.descendants().whereType<ScoreComponent>();
|
|
|
|
|
|
|
|
expect(scoreText.length, equals(1));
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
|
|
|
scoreText.first.points,
|
|
|
|
|
|
|
|
equals(points),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
|
|
|
scoreText.first.position,
|
|
|
|
|
|
|
|
equals(position),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
|
|
|
|
'is removed after duration',
|
|
|
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
|
|
|
final canvas = ZCanvasComponent(children: [parent]);
|
|
|
|
|
|
|
|
await game.ensureAdd(canvas);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const duration = 2.0;
|
|
|
|
|
|
|
|
final behavior = ScoringBehavior(
|
|
|
|
|
|
|
|
points: Points.oneMillion,
|
|
|
|
|
|
|
|
position: Vector2(0, 0),
|
|
|
|
|
|
|
|
duration: duration,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await parent.ensureAdd(behavior);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
game.update(duration);
|
|
|
|
|
|
|
|
game.update(0);
|
|
|
|
|
|
|
|
await tester.pump();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
verify: (game, _) async {
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
|
|
|
game.descendants().whereType<ScoringBehavior>(),
|
|
|
|
|
|
|
|
isEmpty,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
group('ScoringContactBehavior', () {
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
|
|
|
|
'beginContact adds a ScoringBehavior',
|
|
|
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
|
|
|
final canvas = ZCanvasComponent(children: [parent]);
|
|
|
|
|
|
|
|
await game.ensureAdd(canvas);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final behavior = ScoringContactBehavior(points: Points.oneMillion);
|
|
|
|
|
|
|
|
await parent.ensureAdd(behavior);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
behavior.beginContact(ball, _MockContact());
|
|
|
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
|
|
|
parent.firstChild<ScoringBehavior>(),
|
|
|
|
|
|
|
|
isNotNull,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
|
|
|
|
"beginContact positions text at contact's position",
|
|
|
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
|
|
|
final canvas = ZCanvasComponent(children: [parent]);
|
|
|
|
|
|
|
|
await game.ensureAdd(canvas);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final behavior = ScoringContactBehavior(points: Points.oneMillion);
|
|
|
|
|
|
|
|
await parent.ensureAdd(behavior);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
behavior.beginContact(ball, _MockContact());
|
|
|
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final scoreText = game.descendants().whereType<ScoreComponent>();
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
|
|
|
scoreText.first.position,
|
|
|
|
|
|
|
|
equals(ball.body.position),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|