From eb1f05f23dbd326bd9d2911f4602e4ba9b3e890d Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Wed, 27 Apr 2022 20:22:54 +0200 Subject: [PATCH] test: remove deleted balls property from GameState --- lib/game/components/controlled_ball.dart | 8 +++----- lib/game/pinball_game.dart | 2 -- lib/game/view/widgets/game_hud.dart | 2 +- test/game/components/controlled_ball_test.dart | 17 +++++++++++++---- .../components/controlled_flipper_test.dart | 1 - .../components/controlled_plunger_test.dart | 1 - .../components/game_flow_controller_test.dart | 2 -- test/game/pinball_game_test.dart | 11 ----------- test/game/view/widgets/game_hud_test.dart | 1 - .../view/widgets/round_count_display_test.dart | 1 - test/game/view/widgets/score_view_test.dart | 1 - 11 files changed, 17 insertions(+), 30 deletions(-) diff --git a/lib/game/components/controlled_ball.dart b/lib/game/components/controlled_ball.dart index 5ea28bff..08138461 100644 --- a/lib/game/components/controlled_ball.dart +++ b/lib/game/components/controlled_ball.dart @@ -7,12 +7,12 @@ import 'package:pinball_theme/pinball_theme.dart'; /// {@template controlled_ball} /// A [Ball] with a [BallController] attached. +/// +/// When a [Ball] is lost, if there aren't more [Ball]s and game is not over, +/// a new [Ball] will be spawned. /// {@endtemplate} class ControlledBall extends Ball with Controls { /// A [Ball] that launches from the [Plunger]. - /// - /// When a launched [Ball] is lost, it will decrease the [GameState.balls] - /// count, and a new [Ball] is spawned. ControlledBall.launch({ required CharacterTheme characterTheme, }) : super(baseColor: characterTheme.ballColor) { @@ -23,8 +23,6 @@ class ControlledBall extends Ball with Controls { /// {@template bonus_ball} /// {@macro controlled_ball} - /// - /// When a bonus [Ball] is lost, the [GameState.balls] doesn't change. /// {@endtemplate} ControlledBall.bonus({ required CharacterTheme characterTheme, diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index 30bd80e9..f35028fb 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -102,8 +102,6 @@ class _GameBallsController extends ComponentController final noBallsLeft = component.descendants().whereType().isEmpty; final notGameOver = !newState.isGameOver; - print("noBallsLeft $noBallsLeft"); - print("notGameOver $notGameOver"); return noBallsLeft && notGameOver; } diff --git a/lib/game/view/widgets/game_hud.dart b/lib/game/view/widgets/game_hud.dart index 3623e21f..9cfb2d67 100644 --- a/lib/game/view/widgets/game_hud.dart +++ b/lib/game/view/widgets/game_hud.dart @@ -7,7 +7,7 @@ import 'package:pinball/theme/app_colors.dart'; /// {@template game_hud} /// Overlay on the [PinballGame]. /// -/// Displays the current [GameState.score], [GameState.balls] and animates when +/// Displays the current [GameState.score], [GameState.rounds] and animates when /// the player gets a [GameBonus]. /// {@endtemplate} class GameHud extends StatefulWidget { diff --git a/test/game/components/controlled_ball_test.dart b/test/game/components/controlled_ball_test.dart index b0d269e7..c84ddaa7 100644 --- a/test/game/components/controlled_ball_test.dart +++ b/test/game/components/controlled_ball_test.dart @@ -53,30 +53,39 @@ void main() { }); flameBlocTester.testGameWidget( - 'when loaded adds BallAdded to GameBloc', + "lost doesn't adds RoundLost to GameBloc " + 'when there are balls left', setUp: (game, tester) async { final controller = BallController(ball); await ball.add(controller); await game.ensureAdd(ball); + final otherBall = Ball(baseColor: const Color(0xFF00FFFF)); + final otherController = BallController(otherBall); + await otherBall.add(otherController); + await game.ensureAdd(otherBall); + controller.lost(); + await game.ready(); }, verify: (game, tester) async { - verify(() => gameBloc.add(const BallAdded())).called(1); + verifyNever(() => gameBloc.add(const RoundLost())); }, ); flameBlocTester.testGameWidget( - 'lost adds BallLost to GameBloc', + 'lost adds RoundLost to GameBloc ' + 'when there are no balls left', setUp: (game, tester) async { final controller = BallController(ball); await ball.add(controller); await game.ensureAdd(ball); controller.lost(); + await game.ready(); }, verify: (game, tester) async { - verify(() => gameBloc.add(const BallLost())).called(1); + verify(() => gameBloc.add(const RoundLost())).called(1); }, ); diff --git a/test/game/components/controlled_flipper_test.dart b/test/game/components/controlled_flipper_test.dart index e754c395..7cc35b37 100644 --- a/test/game/components/controlled_flipper_test.dart +++ b/test/game/components/controlled_flipper_test.dart @@ -24,7 +24,6 @@ void main() { const state = GameState( score: 0, multiplier: 1, - balls: 0, rounds: 0, bonusHistory: [], ); diff --git a/test/game/components/controlled_plunger_test.dart b/test/game/components/controlled_plunger_test.dart index bacbdc54..a39bdef6 100644 --- a/test/game/components/controlled_plunger_test.dart +++ b/test/game/components/controlled_plunger_test.dart @@ -21,7 +21,6 @@ void main() { const state = GameState( score: 0, multiplier: 1, - balls: 0, rounds: 0, bonusHistory: [], ); diff --git a/test/game/components/game_flow_controller_test.dart b/test/game/components/game_flow_controller_test.dart index 862694af..ef93892c 100644 --- a/test/game/components/game_flow_controller_test.dart +++ b/test/game/components/game_flow_controller_test.dart @@ -16,7 +16,6 @@ void main() { final state = GameState( score: 10, multiplier: 1, - balls: 0, rounds: 0, bonusHistory: const [], ); @@ -69,7 +68,6 @@ void main() { GameState( score: 10, multiplier: 1, - balls: 0, rounds: 0, bonusHistory: const [], ), diff --git a/test/game/pinball_game_test.dart b/test/game/pinball_game_test.dart index 32acf0c5..f85482d7 100644 --- a/test/game/pinball_game_test.dart +++ b/test/game/pinball_game_test.dart @@ -86,17 +86,6 @@ void main() { final flameTester = FlameTester(() => PinballTestGame(assets)); final debugModeFlameTester = FlameTester(() => DebugPinballTestGame(assets)); - late GameBloc gameBloc; - - setUp(() { - gameBloc = GameBloc(); - }); - - final flameBlocTester = FlameBlocTester( - gameBuilder: EmptyPinballTestGame.new, - blocBuilder: () => gameBloc, - // assets: assets, - ); group('PinballGame', () { // TODO(alestiago): test if [PinballGame] registers diff --git a/test/game/view/widgets/game_hud_test.dart b/test/game/view/widgets/game_hud_test.dart index 36d49160..cfc4776c 100644 --- a/test/game/view/widgets/game_hud_test.dart +++ b/test/game/view/widgets/game_hud_test.dart @@ -19,7 +19,6 @@ void main() { const initialState = GameState( score: 1000, multiplier: 1, - balls: 2, rounds: 1, bonusHistory: [], ); diff --git a/test/game/view/widgets/round_count_display_test.dart b/test/game/view/widgets/round_count_display_test.dart index 5b9b4d0a..dfa28869 100644 --- a/test/game/view/widgets/round_count_display_test.dart +++ b/test/game/view/widgets/round_count_display_test.dart @@ -12,7 +12,6 @@ void main() { const initialState = GameState( score: 0, multiplier: 1, - balls: 1, rounds: 3, bonusHistory: [], ); diff --git a/test/game/view/widgets/score_view_test.dart b/test/game/view/widgets/score_view_test.dart index a8660331..63f7d1c5 100644 --- a/test/game/view/widgets/score_view_test.dart +++ b/test/game/view/widgets/score_view_test.dart @@ -16,7 +16,6 @@ void main() { const initialState = GameState( score: score, multiplier: 1, - balls: 1, rounds: 1, bonusHistory: [], );