flutter: 决出胜负后显示的对话框改为黑方的视角显示输赢

This commit is contained in:
Calcitem 2020-11-23 00:55:07 +08:00
parent 62674246a8
commit ffa1d494cb
1 changed files with 29 additions and 24 deletions

View File

@ -59,6 +59,32 @@ class _GamePageState extends State<GamePage> {
changeStatus(String status) => setState(() => _status = status); changeStatus(String status) => setState(() => _status = status);
void showTips() {
final winner = Game.shared.position.winner;
switch (winner) {
case Color.nobody:
if (Game.shared.position.phase == Phase.placing) {
changeStatus('请摆子');
} else if (Game.shared.position.phase == Phase.moving) {
changeStatus('请走子');
}
break;
case Color.black:
changeStatus('黑方胜');
gotWin();
break;
case Color.white:
changeStatus('白方胜');
gotLose();
break;
case Color.draw:
changeStatus('和棋');
gotDraw();
break;
}
}
onBoardTap(BuildContext context, int index) { onBoardTap(BuildContext context, int index) {
final position = Game.shared.position; final position = Game.shared.position;
@ -165,6 +191,8 @@ class _GamePageState extends State<GamePage> {
// //
if (position.winner == Color.nobody) { if (position.winner == Color.nobody) {
engineToGo(); engineToGo();
} else {
showTips();
} }
} }
@ -188,30 +216,7 @@ class _GamePageState extends State<GamePage> {
//Battle.shared.move = move; //Battle.shared.move = move;
Game.shared.doMove(move.move); Game.shared.doMove(move.move);
showTips();
final winner = Game.shared.position.winner;
switch (winner) {
case Color.nobody:
if (Game.shared.position.phase == Phase.placing) {
changeStatus('请摆子');
} else if (Game.shared.position.phase == Phase.moving) {
changeStatus('请走子');
}
break;
case Color.black:
changeStatus('黑方胜');
gotLose();
break;
case Color.white: // TODO
changeStatus('白方胜');
gotWin();
break;
case Color.draw:
changeStatus('平局');
gotDraw();
break;
}
} else { } else {
changeStatus('Error: ${response.type}'); changeStatus('Error: ${response.type}');
} }