flutter: 解决点击 新局 按钮后不能清空棋盘的问题

This commit is contained in:
Calcitem 2020-11-19 23:40:59 +08:00
parent d851b2e525
commit b56e5c35c8
3 changed files with 6 additions and 9 deletions

View File

@ -88,7 +88,7 @@ class Battle {
}
init() {
_position = Position.init();
_position = Position();
_focusIndex = _blurIndex = Move.invalidValue;
}
@ -96,6 +96,7 @@ class Battle {
Battle.shared.position.init();
_focusIndex = _blurIndex = Move.invalidValue;
cmdlist = [""];
sideToMove = Color.black;
}
select(int pos) {

View File

@ -201,7 +201,7 @@ class Position {
return false;
}
Position.init() {
init() {
for (var i = 0; i < _grid.length; i++) {
_grid[i] = Piece.noPiece;
}
@ -218,16 +218,12 @@ class Position {
setPosition(rule); // TODO
// TODO
score[Color.black] = score[Color.white] = score[Color.draw] = nPlayed = 0;
_recorder = MillRecorder(lastCapturedPosition: fen());
}
init() {
Position.init();
}
Position() {
score[Color.black] = score[Color.white] = score[Color.draw] = nPlayed = 0;
init();
}

View File

@ -309,7 +309,8 @@ class _BattlePageState extends State<BattlePage> {
confirm() {
Navigator.of(context).pop();
Battle.shared.newGame();
setState(() {});
//setState(() {});
changeStatus('新游戏');
if (Battle.shared.isAIsTurn()) {
print("New Game: AI's turn.");
@ -317,7 +318,6 @@ class _BattlePageState extends State<BattlePage> {
}
//setState(() {});
changeStatus('新游戏');
}
cancel() => Navigator.of(context).pop();