flutter: 实现棋子点击后移动的效果
This commit is contained in:
parent
20fea630ab
commit
0114ee290c
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue