From fbf333f8b26cb74d30d3f2991211da7169a81d6e Mon Sep 17 00:00:00 2001 From: alestiago Date: Mon, 18 Apr 2022 10:47:05 +0100 Subject: [PATCH] feat: properly deactivated bumpers --- lib/game/components/flutter_forest.dart | 13 ++++---- test/game/components/flutter_forest_test.dart | 31 +++++++++++++++++-- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/lib/game/components/flutter_forest.dart b/lib/game/components/flutter_forest.dart index 667e4f8e..bccd27f3 100644 --- a/lib/game/components/flutter_forest.dart +++ b/lib/game/components/flutter_forest.dart @@ -28,11 +28,11 @@ class FlutterForest extends Component final signPost = FlutterSignPost()..initialPosition = Vector2(8.35, 58.3); final bigNest = _BigDashNestBumper() - ..initialPosition = Vector2(18.55, 59.35); + ..initialPosition = Vector2(18.55, -59.35); final smallLeftNest = _SmallDashNestBumper.a() - ..initialPosition = Vector2(8.95, 51.95); + ..initialPosition = Vector2(8.95, -51.95); final smallRightNest = _SmallDashNestBumper.b() - ..initialPosition = Vector2(23.3, 46.75); + ..initialPosition = Vector2(23.3, -46.75); final dashAnimatronic = DashAnimatronic()..position = Vector2(20, -66); await addAll([ @@ -58,12 +58,11 @@ class _FlutterForestController extends ComponentController final activatedBonus = _activatedBumpers.length == 3; if (activatedBonus) { - children.whereType().forEach( - (dashNestBumper) => dashNestBumper.deactivate(), - ); gameRef.read().add(const BonusActivated(GameBonus.dashNest)); _addBonusBall(); - _activatedBumpers.clear(); + _activatedBumpers + ..forEach((bumper) => bumper.deactivate()) + ..clear(); } } diff --git a/test/game/components/flutter_forest_test.dart b/test/game/components/flutter_forest_test.dart index db52610e..d3296029 100644 --- a/test/game/components/flutter_forest_test.dart +++ b/test/game/components/flutter_forest_test.dart @@ -1,6 +1,7 @@ // ignore_for_file: cascade_invocations import 'package:bloc_test/bloc_test.dart'; +import 'package:flame/components.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -121,14 +122,14 @@ void main() { ); flameBlocTester.testGameWidget( - 'adds GameBonus.dashNest to the game when all bumpers are activated', + 'adds GameBonus.dashNest to the game when 3 bumpers are activated', setUp: (game, _) async { final ball = Ball(baseColor: const Color(0xFFFF0000)); final flutterForest = FlutterForest(); await game.ensureAddAll([flutterForest, ball]); final bumpers = flutterForest.children.whereType(); - expect(bumpers, isNotEmpty); + expect(bumpers.length, equals(3)); for (final bumper in bumpers) { beginContact(game, bumper, ball); await game.ready(); @@ -145,6 +146,32 @@ void main() { } }, ); + + flameBlocTester.testGameWidget( + 'deactivates bumpers when 3 are active', + setUp: (game, _) async { + final ball = Ball(baseColor: const Color(0xFFFF0000)); + final flutterForest = FlutterForest(); + await game.ensureAddAll([flutterForest, ball]); + + final bumpers = [ + MockDashNestBumper(), + MockDashNestBumper(), + MockDashNestBumper(), + ]; + + for (final bumper in bumpers) { + flutterForest.controller.activateBumper(bumper); + await game.ready(); + + if (bumper == bumpers.last) { + for (final bumper in bumpers) { + verify(bumper.deactivate).called(1); + } + } + } + }, + ); }); }); }