flutter: invalidIndex 等部分变量改名
This commit is contained in:
parent
a78f1cd9f5
commit
f6710e800e
|
@ -55,7 +55,7 @@ class BoardWidget extends StatelessWidget {
|
|||
onTapUp: (d) {
|
||||
//
|
||||
final gridWidth = (width - padding * 2);
|
||||
final squareWidth = gridWidth / 6;
|
||||
final squareWidth = gridWidth / 7;
|
||||
|
||||
final dx = d.localPosition.dx, dy = d.localPosition.dy;
|
||||
final row = (dy - padding - digitsHeight) ~/ squareWidth;
|
||||
|
|
|
@ -22,8 +22,8 @@ class PiecesPainter extends PainterBase {
|
|||
PiecesPainter({
|
||||
@required double width,
|
||||
@required this.position,
|
||||
this.focusIndex = Move.InvalidIndex,
|
||||
this.blurIndex = Move.InvalidIndex,
|
||||
this.focusIndex = Move.invalidIndex,
|
||||
this.blurIndex = Move.invalidIndex,
|
||||
}) : super(width: width) {
|
||||
//
|
||||
pieceSide = squareWidth * 0.9; // 棋子大小
|
||||
|
@ -62,11 +62,12 @@ class PiecesPainter extends PainterBase {
|
|||
double pieceSide,
|
||||
double offsetX,
|
||||
double offsetY,
|
||||
int focusIndex = Move.InvalidIndex,
|
||||
int blurIndex = Move.InvalidIndex,
|
||||
int focusIndex = Move.invalidIndex,
|
||||
int blurIndex = Move.invalidIndex,
|
||||
}) {
|
||||
//
|
||||
final left = offsetX, top = offsetY;
|
||||
final left = offsetX;
|
||||
final top = offsetY;
|
||||
|
||||
final shadowPath = Path();
|
||||
final piecesToDraw = <PiecePaintStub>[];
|
||||
|
@ -76,10 +77,9 @@ class PiecesPainter extends PainterBase {
|
|||
//
|
||||
for (var column = 0; column < 7; column++) {
|
||||
//
|
||||
//final piece = position.pieceAt(row * 7 + column);
|
||||
final piece = position.pieceAt(row * 7 + column); // 改为9则全空
|
||||
|
||||
if (piece == Piece.Empty) continue;
|
||||
if (piece == Piece.noPiece) continue;
|
||||
|
||||
var pos = Offset(left + squareSide * column, top + squareSide * row);
|
||||
|
||||
|
@ -98,7 +98,7 @@ class PiecesPainter extends PainterBase {
|
|||
|
||||
/*
|
||||
final textStyle = TextStyle(
|
||||
color: ColorConsts.PieceTextColor,
|
||||
color: ColorConst.PieceTextColor,
|
||||
fontSize: pieceSide * 0.8,
|
||||
height: 1.0,
|
||||
);
|
||||
|
@ -116,7 +116,7 @@ class PiecesPainter extends PainterBase {
|
|||
paint.color = Piece.isWhite(pps.piece)
|
||||
? ColorConst.whitePieceColor
|
||||
: ColorConst.blackPieceColor;
|
||||
//paint.color = ColorConsts.WhitePieceColor;
|
||||
//paint.color = ColorConst.WhitePieceColor;
|
||||
|
||||
canvas.drawCircle(pps.pos, pieceSide * 0.8 / 2, paint); // 决定棋子外圈有宽
|
||||
/*
|
||||
|
@ -140,7 +140,7 @@ class PiecesPainter extends PainterBase {
|
|||
|
||||
// draw focus and blur position
|
||||
|
||||
if (focusIndex != Move.InvalidIndex) {
|
||||
if (focusIndex != Move.invalidIndex) {
|
||||
//
|
||||
final int row = focusIndex ~/ 7, column = focusIndex % 7;
|
||||
|
||||
|
@ -155,7 +155,7 @@ class PiecesPainter extends PainterBase {
|
|||
);
|
||||
}
|
||||
|
||||
if (blurIndex != Move.InvalidIndex) {
|
||||
if (blurIndex != Move.invalidIndex) {
|
||||
//
|
||||
final row = blurIndex ~/ 7, column = blurIndex % 7;
|
||||
|
||||
|
|
|
@ -15,17 +15,17 @@ class Battle {
|
|||
|
||||
init() {
|
||||
_position = Position.defaultPosition();
|
||||
_focusIndex = _blurIndex = Move.InvalidIndex;
|
||||
_focusIndex = _blurIndex = Move.invalidIndex;
|
||||
}
|
||||
|
||||
newGame() {
|
||||
Battle.shared.position.initDefaultPosition();
|
||||
_focusIndex = _blurIndex = Move.InvalidIndex;
|
||||
_focusIndex = _blurIndex = Move.invalidIndex;
|
||||
}
|
||||
|
||||
select(int pos) {
|
||||
_focusIndex = pos;
|
||||
_blurIndex = Move.InvalidIndex;
|
||||
_blurIndex = Move.invalidIndex;
|
||||
//Audios.playTone('click.mp3');
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ class Battle {
|
|||
//
|
||||
} else {
|
||||
//
|
||||
_blurIndex = _focusIndex = Move.InvalidIndex;
|
||||
_blurIndex = _focusIndex = Move.invalidIndex;
|
||||
}
|
||||
|
||||
regreted = true;
|
||||
|
@ -85,7 +85,7 @@ class Battle {
|
|||
}
|
||||
|
||||
clear() {
|
||||
_blurIndex = _focusIndex = Move.InvalidIndex;
|
||||
_blurIndex = _focusIndex = Move.invalidIndex;
|
||||
}
|
||||
|
||||
BattleResult scanBattleResult() {
|
||||
|
|
|
@ -28,18 +28,18 @@ class Side {
|
|||
|
||||
class Piece {
|
||||
//
|
||||
static const Empty = ' ';
|
||||
static const noPiece = ' ';
|
||||
//
|
||||
static const BlackStone = 'b';
|
||||
static const WhiteStone = 'w';
|
||||
static const Ban = 'x';
|
||||
static const blackStone = 'b';
|
||||
static const whiteStone = 'w';
|
||||
static const ban = 'x';
|
||||
|
||||
static const Names = {
|
||||
Empty: '',
|
||||
noPiece: '',
|
||||
//
|
||||
BlackStone: 'b',
|
||||
WhiteStone: 'w',
|
||||
Ban: 'x',
|
||||
blackStone: 'b',
|
||||
whiteStone: 'w',
|
||||
ban: 'x',
|
||||
};
|
||||
|
||||
static bool isBlack(String c) => 'b'.contains(c);
|
||||
|
@ -49,7 +49,7 @@ class Piece {
|
|||
|
||||
class Move {
|
||||
// TODO
|
||||
static const InvalidIndex = -1;
|
||||
static const invalidIndex = -1;
|
||||
|
||||
// List<String>(90) 中的索引
|
||||
int from, to;
|
||||
|
@ -67,7 +67,7 @@ class Move {
|
|||
String counterMarks;
|
||||
|
||||
Move(this.from, this.to,
|
||||
{this.captured = Piece.Empty, this.counterMarks = '0 0'}) {
|
||||
{this.captured = Piece.noPiece, this.counterMarks = '0 0'}) {
|
||||
//
|
||||
fx = from % 9;
|
||||
fy = from ~/ 9;
|
||||
|
@ -104,7 +104,7 @@ class Move {
|
|||
from = fx + fy * 9;
|
||||
to = tx + ty * 9;
|
||||
|
||||
captured = Piece.Empty;
|
||||
captured = Piece.noPiece;
|
||||
}
|
||||
|
||||
static bool validateEngineStep(String step) {
|
||||
|
|
|
@ -26,7 +26,7 @@ class MillRecorder {
|
|||
}
|
||||
void stepIn(Move move, Position position) {
|
||||
//
|
||||
if (move.captured != Piece.Empty) {
|
||||
if (move.captured != Piece.noPiece) {
|
||||
halfMove = 0;
|
||||
} else {
|
||||
halfMove++;
|
||||
|
@ -40,7 +40,7 @@ class MillRecorder {
|
|||
|
||||
_history.add(move);
|
||||
|
||||
if (move.captured != Piece.Empty) {
|
||||
if (move.captured != Piece.noPiece) {
|
||||
lastCapturedPosition = position.toFen();
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ class MillRecorder {
|
|||
List<Move> moves = [];
|
||||
|
||||
for (var i = _history.length - 1; i >= 0; i--) {
|
||||
if (_history[i].captured != Piece.Empty) break;
|
||||
if (_history[i].captured != Piece.noPiece) break;
|
||||
moves.add(_history[i]);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class Position {
|
|||
_board = List<String>(64); // 7 * 7
|
||||
|
||||
for (var i = 0; i < 64; i++) {
|
||||
_board[i] ??= Piece.Empty;
|
||||
_board[i] ??= Piece.noPiece;
|
||||
}
|
||||
|
||||
_recorder = MillRecorder(lastCapturedPosition: toFen());
|
||||
|
@ -48,7 +48,7 @@ class Position {
|
|||
|
||||
// 修改棋盘
|
||||
_board[to] = _board[from];
|
||||
_board[from] = Piece.Empty;
|
||||
_board[from] = Piece.noPiece;
|
||||
|
||||
// 交换走棋方
|
||||
_sideToMove = Side.opponent(_sideToMove);
|
||||
|
@ -70,7 +70,7 @@ class Position {
|
|||
//
|
||||
// 修改棋盘
|
||||
_board[move.to] = _board[move.from];
|
||||
_board[move.from] = Piece.Empty;
|
||||
_board[move.from] = Piece.noPiece;
|
||||
|
||||
// 交换走棋方
|
||||
if (turnSide) _sideToMove = Side.opponent(_sideToMove);
|
||||
|
@ -90,7 +90,7 @@ class Position {
|
|||
_recorder.halfMove = counterMarks.halfMove;
|
||||
_recorder.fullMove = counterMarks.fullMove;
|
||||
|
||||
if (lastMove.captured != Piece.Empty) {
|
||||
if (lastMove.captured != Piece.noPiece) {
|
||||
//
|
||||
// 查找上一个吃子局面(或开局),NativeEngine 需要
|
||||
final tempPosition = Position.clone(this);
|
||||
|
@ -124,7 +124,7 @@ class Position {
|
|||
//
|
||||
final piece = pieceAt((file - 1) * 8 + rank + 8);
|
||||
|
||||
if (piece == Piece.Empty) {
|
||||
if (piece == Piece.noPiece) {
|
||||
//
|
||||
emptyCounter++;
|
||||
//
|
||||
|
@ -157,7 +157,7 @@ class Position {
|
|||
var steps = '', posAfterLastCaptured = 0;
|
||||
|
||||
for (var i = _recorder.stepsCount - 1; i >= 0; i--) {
|
||||
if (_recorder.stepAt(i).captured != Piece.Empty) break;
|
||||
if (_recorder.stepAt(i).captured != Piece.noPiece) break;
|
||||
posAfterLastCaptured = i;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ class _BattlePageState extends State<BattlePage> {
|
|||
final tapedPiece = position.pieceAt(index);
|
||||
|
||||
// 之前已经有棋子被选中了
|
||||
if (Battle.shared.focusIndex != Move.InvalidIndex &&
|
||||
if (Battle.shared.focusIndex != Move.invalidIndex &&
|
||||
Side.of(position.pieceAt(Battle.shared.focusIndex)) == Side.white) {
|
||||
//
|
||||
// 当前点击的棋子和之前已经选择的是同一个位置
|
||||
|
@ -86,7 +86,7 @@ class _BattlePageState extends State<BattlePage> {
|
|||
//
|
||||
} else {
|
||||
// 之前未选择棋子,现在点击就是选择棋子
|
||||
if (tapedPiece != Piece.Empty) Battle.shared.select(index);
|
||||
if (tapedPiece != Piece.noPiece) Battle.shared.select(index);
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
|
|
Loading…
Reference in New Issue