flutter: 没点击到棋盘点位上则不落子
顺带: * 人工落子时,黑白交替落子改为只落黑子; * 解决棋盘初始化位置函数找不到的问题。
This commit is contained in:
parent
179c1bad4c
commit
c0af6740c1
|
@ -38,7 +38,7 @@ class Battle {
|
|||
}
|
||||
|
||||
newGame() {
|
||||
Battle.shared.position.initDefaultPosition();
|
||||
Battle.shared.position.init();
|
||||
_focusIndex = _blurIndex = Move.invalidIndex;
|
||||
}
|
||||
|
||||
|
|
|
@ -94,6 +94,10 @@ class Position {
|
|||
_recorder = MillRecorder(lastCapturedPosition: fen());
|
||||
}
|
||||
|
||||
init() {
|
||||
Position.init();
|
||||
}
|
||||
|
||||
Position.boardToGrid() {
|
||||
_grid = List<String>();
|
||||
for (int sq = 0; sq < _board.length; sq++) {
|
||||
|
@ -164,9 +168,20 @@ class Position {
|
|||
return selectPieceSQ(makeSquare(file, rank));
|
||||
}
|
||||
|
||||
void putPiece(var pt, int index) {
|
||||
bool putPiece(var pt, int index) {
|
||||
var sq = indexToSquare[index];
|
||||
|
||||
if (sq == null) {
|
||||
print("putPiece skip index: $index");
|
||||
return false;
|
||||
}
|
||||
|
||||
_grid[index] = pt;
|
||||
_board[indexToSquare[index]] = pt;
|
||||
_board[sq] = pt;
|
||||
|
||||
print("putPiece: pt = $pt, index = $index, sq = $sq");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool putPieceFR(int file, int rank) {
|
||||
|
|
|
@ -51,7 +51,7 @@ class _BattlePageState extends State<BattlePage> {
|
|||
String _status = '';
|
||||
bool _analysising = false;
|
||||
|
||||
static int flag = 0;
|
||||
//static int flag = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -72,8 +72,11 @@ class _BattlePageState extends State<BattlePage> {
|
|||
final position = Battle.shared.position;
|
||||
|
||||
//position
|
||||
flag++;
|
||||
position.putPiece(flag % 2 == 0 ? '@' : 'O', index);
|
||||
//flag++;
|
||||
//position.putPiece(flag % 2 == 0 ? '@' : 'O', index);
|
||||
if (position.putPiece('@', index) == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 仅 Position 中的 side 指示一方能动棋
|
||||
if (position.side != Color.black) return;
|
||||
|
|
Loading…
Reference in New Issue