/// <summary> /// it's only move the chess piece, after select it /// </summary> /// <param name="newLocation"></param> private void chessMove(int gridX, int gridY) { if (_selectChess != null && _selectChess.Type == _currentActionType) { if (_selectChess.move(gridX, gridY)) { //_selectChess.IsChecked = false; chessArray[_selectChess.GridY, _selectChess.GridX] = (byte)_selectChess.PieceType; chessArray[_selectChess.PreviousGridY, _selectChess.PreviousGridX] = (byte)0; string move = ChessUtils.getMoveString(_selectChess.GridX, _selectChess.GridY, _selectChess.PreviousGridX, _selectChess.PreviousGridY); _updateMovesStep(move); doSomeAfterMove(); } } }
/// <summary> /// it's common from select chess piece, or attack another chess piece /// </summary> /// <param name="theChessPiece"></param> private void chessItemSelected(BaseChess theChessPiece) { if (_selectChess == null) { //第一次选择棋子 if (theChessPiece.Type == _currentActionType) { _selectChess = theChessPiece; //_previousChess = _selectChess; } else { //选择错了棋子 theChessPiece.IsChecked = false; } } else { //已经选择了一个棋子,再次选择时是对方棋子 if (theChessPiece.Type != _currentActionType) { BaseChess beAttackChess = theChessPiece; if (_selectChess.move(beAttackChess.Location)) { chessArray[_selectChess.GridY, _selectChess.GridX] = (byte)_selectChess.PieceType; chessArray[beAttackChess.GridY, beAttackChess.GridX] = 0; _previousOppositeChess = beAttackChess.Clone(); beAttackChess.remove(); string move = ChessUtils.getMoveString(_selectChess.GridX, _selectChess.GridY, _selectChess.PreviousGridX, _selectChess.PreviousGridY); _updateMovesStep(move, true); _updateFenStr(); doSomeAfterMove(); } else { //不遵循着法 beAttackChess.IsChecked = false; } } else { //如果再次选择时还是己方棋子,更改check状态 _selectChess.IsChecked = false; //更换当前引用 _selectChess = theChessPiece; } } }