mirror of https://github.com/flutter/pinball.git
parent
424f35a958
commit
983b887172
@ -1,2 +1,2 @@
|
|||||||
export 'flipper_jointing_behavior.dart';
|
export 'flipper_jointing_behavior.dart';
|
||||||
export 'flipper_key_listening_behavior.dart';
|
export 'flipper_key_controlling_behavior.dart';
|
||||||
|
@ -1 +1,38 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_components/src/components/components.dart';
|
||||||
|
|
||||||
|
import '../../../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
group('FlipperJointingBehavior', () {
|
||||||
|
final flameTester = FlameTester(TestGame.new);
|
||||||
|
|
||||||
|
test('can be instantiated', () {
|
||||||
|
expect(
|
||||||
|
FlipperJointingBehavior(),
|
||||||
|
isA<FlipperJointingBehavior>(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
flameTester.test('can be loaded', (game) async {
|
||||||
|
final behavior = FlipperJointingBehavior();
|
||||||
|
final parent = Flipper.test(side: BoardSide.left);
|
||||||
|
await game.ensureAdd(parent);
|
||||||
|
await parent.ensureAdd(behavior);
|
||||||
|
expect(parent.contains(behavior), isTrue);
|
||||||
|
});
|
||||||
|
|
||||||
|
flameTester.test('joints', (game) async {
|
||||||
|
final behavior = FlipperJointingBehavior();
|
||||||
|
final parent = Flipper.test(side: BoardSide.left);
|
||||||
|
await game.ensureAdd(parent);
|
||||||
|
await parent.ensureAdd(behavior);
|
||||||
|
|
||||||
|
expect(parent.body.joints, isNotEmpty);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -0,0 +1,359 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'dart:collection';
|
||||||
|
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
import '../../../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
class _MockRawKeyDownEvent extends Mock implements RawKeyDownEvent {
|
||||||
|
@override
|
||||||
|
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MockRawKeyUpEvent extends Mock implements RawKeyUpEvent {
|
||||||
|
@override
|
||||||
|
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
group('FlipperKeyControllingBehavior', () {
|
||||||
|
final flameTester = FlameTester(TestGame.new);
|
||||||
|
|
||||||
|
group(
|
||||||
|
'onKeyEvent',
|
||||||
|
() {
|
||||||
|
late Flipper rightFlipper;
|
||||||
|
late Flipper leftFlipper;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
rightFlipper = Flipper.test(side: BoardSide.right);
|
||||||
|
leftFlipper = Flipper.test(side: BoardSide.left);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('on right Flipper', () {
|
||||||
|
flameTester.test(
|
||||||
|
'moves upwards when right arrow is pressed',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(rightFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await rightFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyDownEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.arrowRight,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(rightFlipper.body.linearVelocity.y, isNegative);
|
||||||
|
expect(rightFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'moves downwards when right arrow is released',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(rightFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await rightFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyUpEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.arrowRight,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(rightFlipper.body.linearVelocity.y, isPositive);
|
||||||
|
expect(rightFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'moves upwards when D is pressed',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(rightFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await rightFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyDownEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.keyD,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(rightFlipper.body.linearVelocity.y, isNegative);
|
||||||
|
expect(rightFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'moves downwards when D is released',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(rightFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await rightFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyUpEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.keyD,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(rightFlipper.body.linearVelocity.y, isPositive);
|
||||||
|
expect(rightFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
group("doesn't move when", () {
|
||||||
|
flameTester.test(
|
||||||
|
'left awrrow is pressed',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(rightFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await rightFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyDownEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.arrowLeft,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(rightFlipper.body.linearVelocity.y, isZero);
|
||||||
|
expect(rightFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'left arrow is released',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(rightFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await rightFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyUpEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.arrowLeft,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(rightFlipper.body.linearVelocity.y, isZero);
|
||||||
|
expect(rightFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'A is pressed',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(rightFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await rightFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyDownEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.keyA,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(rightFlipper.body.linearVelocity.y, isZero);
|
||||||
|
expect(rightFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'A is released',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(rightFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await rightFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyUpEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.keyA,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(rightFlipper.body.linearVelocity.y, isZero);
|
||||||
|
expect(rightFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('on left Flipper', () {
|
||||||
|
flameTester.test(
|
||||||
|
'moves upwards when left arrow is pressed',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(leftFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await leftFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyDownEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.arrowLeft,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(leftFlipper.body.linearVelocity.y, isNegative);
|
||||||
|
expect(leftFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'moves downwards when left arrow is released',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(leftFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await leftFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyUpEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.arrowLeft,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(leftFlipper.body.linearVelocity.y, isPositive);
|
||||||
|
expect(leftFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'moves upwards when A is pressed',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(leftFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await leftFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyDownEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.keyA,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(leftFlipper.body.linearVelocity.y, isNegative);
|
||||||
|
expect(leftFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'moves downwards when A is released',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(leftFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await leftFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyUpEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.keyA,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(leftFlipper.body.linearVelocity.y, isPositive);
|
||||||
|
expect(leftFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
group("doesn't move when", () {
|
||||||
|
flameTester.test(
|
||||||
|
'right awrrow is pressed',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(leftFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await leftFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyDownEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.arrowRight,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(leftFlipper.body.linearVelocity.y, isZero);
|
||||||
|
expect(leftFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'right arrow is released',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(leftFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await leftFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyUpEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.arrowRight,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(leftFlipper.body.linearVelocity.y, isZero);
|
||||||
|
expect(leftFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'D is pressed',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(leftFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await leftFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyDownEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.keyD,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(leftFlipper.body.linearVelocity.y, isZero);
|
||||||
|
expect(leftFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'D is released',
|
||||||
|
(game) async {
|
||||||
|
await game.ensureAdd(leftFlipper);
|
||||||
|
final behavior = FlipperKeyControllingBehavior();
|
||||||
|
await leftFlipper.ensureAdd(behavior);
|
||||||
|
|
||||||
|
final event = _MockRawKeyUpEvent();
|
||||||
|
when(() => event.logicalKey).thenReturn(
|
||||||
|
LogicalKeyboardKey.keyD,
|
||||||
|
);
|
||||||
|
|
||||||
|
behavior.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(leftFlipper.body.linearVelocity.y, isZero);
|
||||||
|
expect(leftFlipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
@ -1,194 +0,0 @@
|
|||||||
import 'dart:collection';
|
|
||||||
|
|
||||||
import 'package:bloc_test/bloc_test.dart';
|
|
||||||
import 'package:flame_test/flame_test.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
import 'package:mocktail/mocktail.dart';
|
|
||||||
import 'package:pinball/game/game.dart';
|
|
||||||
import 'package:pinball_components/pinball_components.dart';
|
|
||||||
|
|
||||||
import '../../helpers/helpers.dart';
|
|
||||||
|
|
||||||
class _MockGameBloc extends Mock implements GameBloc {}
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
TestWidgetsFlutterBinding.ensureInitialized();
|
|
||||||
final assets = [
|
|
||||||
Assets.images.flipper.left.keyName,
|
|
||||||
Assets.images.flipper.right.keyName,
|
|
||||||
];
|
|
||||||
final flameTester = FlameTester(
|
|
||||||
() => EmptyPinballTestGame(assets: assets),
|
|
||||||
);
|
|
||||||
|
|
||||||
final flameBlocTester = FlameBlocTester<EmptyPinballTestGame, GameBloc>(
|
|
||||||
gameBuilder: EmptyPinballTestGame.new,
|
|
||||||
blocBuilder: () {
|
|
||||||
final bloc = _MockGameBloc();
|
|
||||||
const state = GameState(
|
|
||||||
totalScore: 0,
|
|
||||||
roundScore: 0,
|
|
||||||
multiplier: 1,
|
|
||||||
rounds: 0,
|
|
||||||
bonusHistory: [],
|
|
||||||
);
|
|
||||||
whenListen(bloc, Stream.value(state), initialState: state);
|
|
||||||
return bloc;
|
|
||||||
},
|
|
||||||
assets: assets,
|
|
||||||
);
|
|
||||||
|
|
||||||
group('FlipperController', () {
|
|
||||||
group('onKeyEvent', () {
|
|
||||||
final leftKeys = UnmodifiableListView([
|
|
||||||
LogicalKeyboardKey.arrowLeft,
|
|
||||||
LogicalKeyboardKey.keyA,
|
|
||||||
]);
|
|
||||||
final rightKeys = UnmodifiableListView([
|
|
||||||
LogicalKeyboardKey.arrowRight,
|
|
||||||
LogicalKeyboardKey.keyD,
|
|
||||||
]);
|
|
||||||
|
|
||||||
group('and Flipper is left', () {
|
|
||||||
late Flipper flipper;
|
|
||||||
late FlipperController controller;
|
|
||||||
|
|
||||||
setUp(() {
|
|
||||||
flipper = Flipper(side: BoardSide.left);
|
|
||||||
controller = FlipperController(flipper);
|
|
||||||
flipper.add(controller);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyDownEvents(leftKeys, (event) {
|
|
||||||
flameTester.test(
|
|
||||||
'moves upwards '
|
|
||||||
'when ${event.logicalKey.keyLabel} is pressed',
|
|
||||||
(game) async {
|
|
||||||
await game.ready();
|
|
||||||
await game.add(flipper);
|
|
||||||
controller.onKeyEvent(event, {});
|
|
||||||
|
|
||||||
expect(flipper.body.linearVelocity.y, isNegative);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyDownEvents(leftKeys, (event) {
|
|
||||||
flameBlocTester.testGameWidget(
|
|
||||||
'does nothing when is game over',
|
|
||||||
setUp: (game, tester) async {
|
|
||||||
await game.ensureAdd(flipper);
|
|
||||||
controller.onKeyEvent(event, {});
|
|
||||||
},
|
|
||||||
verify: (game, tester) async {
|
|
||||||
expect(flipper.body.linearVelocity.y, isZero);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyUpEvents(leftKeys, (event) {
|
|
||||||
flameTester.test(
|
|
||||||
'moves downwards '
|
|
||||||
'when ${event.logicalKey.keyLabel} is released',
|
|
||||||
(game) async {
|
|
||||||
await game.ready();
|
|
||||||
await game.add(flipper);
|
|
||||||
controller.onKeyEvent(event, {});
|
|
||||||
|
|
||||||
expect(flipper.body.linearVelocity.y, isPositive);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyUpEvents(rightKeys, (event) {
|
|
||||||
flameTester.test(
|
|
||||||
'does nothing '
|
|
||||||
'when ${event.logicalKey.keyLabel} is released',
|
|
||||||
(game) async {
|
|
||||||
await game.ready();
|
|
||||||
await game.add(flipper);
|
|
||||||
controller.onKeyEvent(event, {});
|
|
||||||
|
|
||||||
expect(flipper.body.linearVelocity.y, isZero);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
group('and Flipper is right', () {
|
|
||||||
late Flipper flipper;
|
|
||||||
late FlipperController controller;
|
|
||||||
|
|
||||||
setUp(() {
|
|
||||||
flipper = Flipper(side: BoardSide.right);
|
|
||||||
controller = FlipperController(flipper);
|
|
||||||
flipper.add(controller);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyDownEvents(rightKeys, (event) {
|
|
||||||
flameTester.test(
|
|
||||||
'moves upwards '
|
|
||||||
'when ${event.logicalKey.keyLabel} is pressed',
|
|
||||||
(game) async {
|
|
||||||
await game.ready();
|
|
||||||
await game.add(flipper);
|
|
||||||
controller.onKeyEvent(event, {});
|
|
||||||
|
|
||||||
expect(flipper.body.linearVelocity.y, isNegative);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyUpEvents(rightKeys, (event) {
|
|
||||||
flameTester.test(
|
|
||||||
'moves downwards '
|
|
||||||
'when ${event.logicalKey.keyLabel} is released',
|
|
||||||
(game) async {
|
|
||||||
await game.ready();
|
|
||||||
await game.add(flipper);
|
|
||||||
controller.onKeyEvent(event, {});
|
|
||||||
|
|
||||||
expect(flipper.body.linearVelocity.y, isPositive);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyDownEvents(rightKeys, (event) {
|
|
||||||
flameBlocTester.testGameWidget(
|
|
||||||
'does nothing when is game over',
|
|
||||||
setUp: (game, tester) async {
|
|
||||||
await game.ensureAdd(flipper);
|
|
||||||
controller.onKeyEvent(event, {});
|
|
||||||
},
|
|
||||||
verify: (game, tester) async {
|
|
||||||
expect(flipper.body.linearVelocity.y, isZero);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyUpEvents(leftKeys, (event) {
|
|
||||||
flameTester.test(
|
|
||||||
'does nothing '
|
|
||||||
'when ${event.logicalKey.keyLabel} is released',
|
|
||||||
(game) async {
|
|
||||||
await game.ready();
|
|
||||||
await game.add(flipper);
|
|
||||||
controller.onKeyEvent(event, {});
|
|
||||||
|
|
||||||
expect(flipper.body.linearVelocity.y, isZero);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in new issue