flutter: Support Auto replay moves (WIP)

This commit is contained in:
Calcitem 2021-05-23 00:00:15 +08:00
parent 189ed16ab8
commit 0d86b504b4
4 changed files with 58 additions and 29 deletions

View File

@ -899,5 +899,9 @@
"aiIsNotThinking": "AI is not thinking.",
"@aiIsNotThinking": {
"description": "AI is not thinking."
},
"autoReplay": "Auto replay moves",
"@autoReplay": {
"description": "Auto replay moves"
}
}

View File

@ -224,5 +224,6 @@
"onBoard": "棋盘上",
"boardTop": "棋盘和上边缘的间距",
"notAIsTurn": "现在不是轮到电脑行棋",
"aiIsNotThinking": "电脑并非正在思考中"
"aiIsNotThinking": "电脑并非正在思考中",
"autoReplay": "自动回放"
}

View File

@ -1059,6 +1059,8 @@ class Position {
for (var i = 0; i <= moveIndex; i++) {
Game.instance.doMove(history[i].move);
//await Future.delayed(Duration(seconds: 1));
//setState(() {});
}
// Restore context

View File

@ -460,20 +460,27 @@ class _GamePageState extends State<GamePage> with RouteAware {
}
}
onGameButtonPressed() {
confirm() {
Navigator.of(context).pop();
Game.instance.newGame();
if (mounted) {
showTip(S.of(context).gameStarted);
}
if (Game.instance.isAiToMove()) {
print("$tag New game, AI to move.");
engineToGo(false);
}
onStartNewGameButtonPressed() async {
Navigator.of(context).pop();
Game.instance.newGame();
if (mounted) {
showTip(S.of(context).gameStarted);
}
if (Game.instance.isAiToMove()) {
print("$tag New game, AI to move.");
engineToGo(false);
}
}
onAutoReplayButtonPressed() async {
Navigator.of(context).pop();
await onTakeBackAllButtonPressed(pop: false);
await onStepForwardAllButtonPressed(pop: false);
}
onGameButtonPressed() {
showDialog(
context: context,
builder: (BuildContext context) {
@ -481,12 +488,24 @@ class _GamePageState extends State<GamePage> with RouteAware {
backgroundColor: Colors.transparent,
children: <Widget>[
SimpleDialogOption(
child: Text(
S.of(context).startNewGame,
style: AppTheme.simpleDialogOptionTextStyle,
textAlign: TextAlign.center,
),
onPressed: confirm),
child: Text(
S.of(context).startNewGame,
style: AppTheme.simpleDialogOptionTextStyle,
textAlign: TextAlign.center,
),
onPressed: onStartNewGameButtonPressed,
),
/*
SizedBox(height: AppTheme.sizedBoxHeight),
SimpleDialogOption(
child: Text(
S.of(context).autoReplay,
style: AppTheme.simpleDialogOptionTextStyle,
textAlign: TextAlign.center,
),
onPressed: onAutoReplayButtonPressed,
),
*/
],
);
},
@ -567,8 +586,10 @@ class _GamePageState extends State<GamePage> with RouteAware {
);
}
onGotoHistoryButtonsPressed(var func) async {
Navigator.of(context).pop();
onGotoHistoryButtonsPressed(var func, {bool pop = true}) async {
if (pop == true) {
Navigator.of(context).pop();
}
if (mounted) {
showTip(S.of(context).waiting);
@ -588,20 +609,21 @@ class _GamePageState extends State<GamePage> with RouteAware {
}
}
onTakeBackButtonPressed() async {
onGotoHistoryButtonsPressed(Game.instance.position.takeBack());
onTakeBackButtonPressed({bool pop = true}) async {
onGotoHistoryButtonsPressed(Game.instance.position.takeBack(), pop: pop);
}
onStepForwardButtonPressed() async {
onGotoHistoryButtonsPressed(Game.instance.position.stepForward());
onStepForwardButtonPressed({bool pop = true}) async {
onGotoHistoryButtonsPressed(Game.instance.position.stepForward(), pop: pop);
}
onTakeBackAllButtonPressed() async {
onGotoHistoryButtonsPressed(Game.instance.position.takeBackAll());
onTakeBackAllButtonPressed({bool pop = true}) async {
onGotoHistoryButtonsPressed(Game.instance.position.takeBackAll(), pop: pop);
}
onStepForwardAllButtonPressed() async {
onGotoHistoryButtonsPressed(Game.instance.position.stepForwardAll());
onStepForwardAllButtonPressed({bool pop = true}) async {
onGotoHistoryButtonsPressed(Game.instance.position.stepForwardAll(),
pop: pop);
}
onMoveListButtonPressed() {