|
|
@ -34,8 +34,6 @@ void main() {
|
|
|
|
Assets.images.score.oneMillion.keyName,
|
|
|
|
Assets.images.score.oneMillion.keyName,
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
group('ScoringBehavior', () {
|
|
|
|
|
|
|
|
group('beginContact', () {
|
|
|
|
|
|
|
|
late GameBloc bloc;
|
|
|
|
late GameBloc bloc;
|
|
|
|
late Ball ball;
|
|
|
|
late Ball ball;
|
|
|
|
late BodyComponent parent;
|
|
|
|
late BodyComponent parent;
|
|
|
@ -65,16 +63,47 @@ void main() {
|
|
|
|
assets: assets,
|
|
|
|
assets: assets,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
group('ScoringBehavior', () {
|
|
|
|
|
|
|
|
test('can be instantiated', () {
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
|
|
|
ScoringBehavior(
|
|
|
|
|
|
|
|
points: Points.fiveThousand,
|
|
|
|
|
|
|
|
position: Vector2.zero(),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
isA<ScoringBehavior>(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
'emits Scored event with points',
|
|
|
|
'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 {
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
const points = Points.oneMillion;
|
|
|
|
const points = Points.oneMillion;
|
|
|
|
final scoringBehavior = ScoringBehavior(points: points);
|
|
|
|
|
|
|
|
await parent.add(scoringBehavior);
|
|
|
|
|
|
|
|
final canvas = ZCanvasComponent(children: [parent]);
|
|
|
|
final canvas = ZCanvasComponent(children: [parent]);
|
|
|
|
await game.ensureAdd(canvas);
|
|
|
|
await game.ensureAdd(canvas);
|
|
|
|
|
|
|
|
|
|
|
|
scoringBehavior.beginContact(ball, _MockContact());
|
|
|
|
final behavior = ScoringBehavior(
|
|
|
|
|
|
|
|
points: points,
|
|
|
|
|
|
|
|
position: Vector2(0, 0),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await parent.ensureAdd(behavior);
|
|
|
|
|
|
|
|
|
|
|
|
verify(
|
|
|
|
verify(
|
|
|
|
() => bloc.add(
|
|
|
|
() => bloc.add(
|
|
|
@ -85,16 +114,18 @@ void main() {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
flameBlocTester.testGameWidget(
|
|
|
|
"adds a ScoreComponent at Ball's position with points",
|
|
|
|
'correctly renders text',
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
const points = Points.oneMillion;
|
|
|
|
|
|
|
|
final scoringBehavior = ScoringBehavior(points: points);
|
|
|
|
|
|
|
|
await parent.add(scoringBehavior);
|
|
|
|
|
|
|
|
final canvas = ZCanvasComponent(children: [parent]);
|
|
|
|
final canvas = ZCanvasComponent(children: [parent]);
|
|
|
|
await game.ensureAdd(canvas);
|
|
|
|
await game.ensureAdd(canvas);
|
|
|
|
|
|
|
|
|
|
|
|
scoringBehavior.beginContact(ball, _MockContact());
|
|
|
|
const points = Points.oneMillion;
|
|
|
|
await game.ready();
|
|
|
|
final position = Vector2.all(1);
|
|
|
|
|
|
|
|
final behavior = ScoringBehavior(
|
|
|
|
|
|
|
|
points: points,
|
|
|
|
|
|
|
|
position: position,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await parent.ensureAdd(behavior);
|
|
|
|
|
|
|
|
|
|
|
|
final scoreText = game.descendants().whereType<ScoreComponent>();
|
|
|
|
final scoreText = game.descendants().whereType<ScoreComponent>();
|
|
|
|
expect(scoreText.length, equals(1));
|
|
|
|
expect(scoreText.length, equals(1));
|
|
|
@ -104,10 +135,76 @@ void main() {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
scoreText.first.position,
|
|
|
|
scoreText.first.position,
|
|
|
|
equals(ball.body.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),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|