flutter: 实现棋子点击后移动的效果

This commit is contained in:
Calcitem 2020-11-08 11:36:30 +08:00
parent 20fea630ab
commit 0114ee290c
3 changed files with 6 additions and 5 deletions

View File

@ -61,9 +61,9 @@ class BoardWidget extends StatelessWidget {
final row = (dy - padding - digitsHeight) ~/ squareWidth;
final column = (dx - padding) ~/ squareWidth;
final index = row * 6 + column;
final index = row * 7 + column;
print("Tap on ($row, $column) => $index\n");
print("Tap on ($row, $column) <$index>");
if (row < 0 || row > 6) return;

View File

@ -53,7 +53,7 @@ class Position {
}
// Debugging
_board[sqToLoc[8]] = Piece.whiteStone;
_board[sqToLoc[8]] = Piece.blackStone;
//_board[7] = Piece.ban;
//_board[8] = Piece.whiteStone;

View File

@ -46,13 +46,14 @@ class _BattlePageState extends State<BattlePage> {
final position = Battle.shared.position;
// Position side
if (position.side != Side.white) return;
if (position.side != Side.black) return;
final tapedPiece = position.pieceAt(index);
print("Tap piece $tapedPiece at <$index>");
//
if (Battle.shared.focusIndex != Move.invalidIndex &&
Side.of(position.pieceAt(Battle.shared.focusIndex)) == Side.white) {
Side.of(position.pieceAt(Battle.shared.focusIndex)) == Side.black) {
//
//
if (Battle.shared.focusIndex == index) return;