From a6277005adc333f37797d79aabb8d2668fe88e0e Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sun, 29 Nov 2020 23:22:12 +0800 Subject: [PATCH] =?UTF-8?q?flutter:=20=E6=96=B0=E5=A2=9E=20showGameResult(?= =?UTF-8?q?)=20=E5=8F=96=E4=BB=A3=20gotWin/gotLose/gotDraw()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/flutter/lib/widgets/game_page.dart | 95 ++++++++--------------- 1 file changed, 34 insertions(+), 61 deletions(-) diff --git a/src/ui/flutter/lib/widgets/game_page.dart b/src/ui/flutter/lib/widgets/game_page.dart index 86911491..3ec97603 100644 --- a/src/ui/flutter/lib/widgets/game_page.dart +++ b/src/ui/flutter/lib/widgets/game_page.dart @@ -73,15 +73,15 @@ class _GamePageState extends State { break; case Color.black: changeStatus(S.of(context).blackWin); - gotWin(); + showGameResult(GameResult.win); break; case Color.white: changeStatus(S.of(context).whiteWin); - gotLose(); + showGameResult(GameResult.lose); break; case Color.draw: changeStatus(S.of(context).draw); - gotDraw(); + showGameResult(GameResult.draw); break; } } @@ -329,18 +329,38 @@ class _GamePageState extends State { return loseReasonStr; } - void gotWin() { + void showGameResult(GameResult result) { // - Game.shared.position.result = GameResult.win; - //Audios.playTone('win.mp3'); + Game.shared.position.result = result; + + switch (result) { + case GameResult.win: + //Audios.playTone('win.mp3'); + break; + case GameResult.lose: + //Audios.playTone('lose.mp3'); + break; + case GameResult.draw: + break; + default: + break; + } + + Map retMap = { + GameResult.win: S.of(context).youWin, + GameResult.lose: S.of(context).youLose, + GameResult.draw: S.of(context).draw + }; + + var dialogTitle = retMap[result]; showDialog( context: context, barrierDismissible: false, builder: (BuildContext context) { return AlertDialog( - title: Text(S.of(context).youWin, - style: TextStyle(color: UIColors.primaryColor)), + title: + Text(dialogTitle, style: TextStyle(color: UIColors.primaryColor)), content: Text(getGameOverReasonString( Game.shared.position.gameOverReason, Game.shared.position.winner)), @@ -353,59 +373,12 @@ class _GamePageState extends State { }, ); - if (widget.engineType == EngineType.humanVsCloud) - Player.shared.increaseWinCloudEngine(); - else - Player.shared.increaseWinAi(); - } - - void gotLose() { - // - Game.shared.position.result = GameResult.lose; - //Audios.playTone('lose.mp3'); - - showDialog( - context: context, - barrierDismissible: false, - builder: (BuildContext context) { - return AlertDialog( - title: Text(S.of(context).youLose, - style: TextStyle(color: UIColors.primaryColor)), - content: Text(getGameOverReasonString( - Game.shared.position.gameOverReason, - Game.shared.position.winner)), - actions: [ - FlatButton( - child: Text(S.of(context).ok), - onPressed: () => Navigator.of(context).pop()), - ], - ); - }, - ); - } - - void gotDraw() { - // - Game.shared.position.result = GameResult.draw; - - showDialog( - context: context, - barrierDismissible: false, - builder: (BuildContext context) { - return AlertDialog( - title: Text(S.of(context).draw, - style: TextStyle(color: UIColors.primaryColor)), - content: Text(getGameOverReasonString( - Game.shared.position.gameOverReason, - Game.shared.position.winner)), - actions: [ - FlatButton( - child: Text(S.of(context).ok), - onPressed: () => Navigator.of(context).pop()), - ], - ); - }, - ); + if (result == GameResult.win) { + if (widget.engineType == EngineType.humanVsCloud) + Player.shared.increaseWinCloudEngine(); + else + Player.shared.increaseWinAi(); + } } void calcScreenPaddingH() {