protected sealed override bool CheckPoint(ChessPoint chessPoint) { if (!IsEnemyKing(chessPoint)) { if (!MoveInStraight(chessPoint)) { return(false); } if (!ContainSize(chessPoint)) { return(false); } if (!MoveStep(chessPoint)) { return(false); } } else { if (AnyOneInRoad(chessPoint)) { return(false); } } return(true); }
static Board() { for (int i = 0; i < 10; i++) { for (int j = 0; j < 9; j++) { Position[i, j] = new ChessPoint(); Position[i, j].Row = i; Position[i, j].Col = j; Position[i, j].IsEmpty = true; Position[i, j].Name = ""; Position[i, j].Index = -1; Position[i, j].Side = -1; Position[i, j].ValidMove = new PictureBox(); Position[i, j].ValidMove.Image = Resources.ValidMove; Position[i, j].ValidMove.Width = 20; Position[i, j].ValidMove.Height = 20; Position[i, j].ValidMove.BackColor = Color.Transparent; Position[i, j].ValidMove.Top = i * 48 + 47; Position[i, j].ValidMove.Left = j * 48 + 23; Position[i, j].ValidMove.Cursor = Cursors.Hand; Position[i, j].ValidMove.Visible = false; } } }
protected bool ContainSize(ChessPoint chessPoint) { if (XIsBeyond(chessPoint.X) || YIsBeyond(chessPoint.Y)) { return(false); } return(true); }
public ChessmanBase(ChessPoint point, Chessboard board, bool isRed) { IsRed = isRed; Board = board; this.Board.SetDefalutChessman(point, this); _location = point; defalutPoint = point; }
bool MoveFrontOnly(ChessPoint chessPoint) { if (chessPoint.Y == Location.Y) { return(true); } return(defalutPoint.Y > 4 ? chessPoint.Y <Location.Y : chessPoint.Y> Location.Y); }
bool CanHorizontalMove(ChessPoint chessPoint) { if (chessPoint.X == Location.X) { return(true); } return(defalutPoint.Y > 4 ? Location.Y < 5 : Location.Y > 4); }
public Pawn(ChessPoint point, Chessboard board, bool isRed) : base(point, board, isRed) { canMoveFunc = new List <Func <ChessPoint, bool> >(5); canMoveFunc.Add(MoveInStraight); canMoveFunc.Add(ContainSize); canMoveFunc.Add(MoveStep); canMoveFunc.Add(MoveFrontOnly); canMoveFunc.Add(CanHorizontalMove); }
public Minister(ChessPoint point, Chessboard board, bool isRed) : base(point, board, isRed) { canMovePoint = new List <Func <ChessPoint> >(8); canMovePoint.Add(Northwest); canMovePoint.Add(Northeast); canMovePoint.Add(Southeast); canMovePoint.Add(Southwest); }
protected sealed override bool CheckPoint(ChessPoint chessPoint) { foreach (var item in canMoveFunc) { if (!item(chessPoint)) { return(false); } } return(true); }
internal void MoveChessman(ChessPoint point, ChessmanBase chessman) { ChessmanBase oldChessman = _chessmanMap[point.X, point.Y]; _chessmanMap[chessman.Location.X, chessman.Location.Y] = null; _chessmanMap[point.X, point.Y] = chessman; if (ChessMoved != null) { ChessMoved(point, chessman.Location, chessman, oldChessman); } }
protected sealed override bool CheckPoint(ChessPoint chessPoint) { foreach (var item in canMovePoint) { ChessPoint result = item(); if (result != null && result.Equals(chessPoint)) { return(true); } } return(false); }
ChessPoint Northeast() { ChessPoint currentPoint = this.Location; int x = currentPoint.X + 1; int y = currentPoint.Y - 1; if (XIsBeyond(x) || YIsBeyond(y)) { return(null); } return(new ChessPoint(x, y)); }
ChessPoint Southwest() { ChessPoint currentPoint = this.Location; int x = currentPoint.X - 1; int y = currentPoint.Y + 1; if (XIsBeyond(x) || YIsBeyond(y)) { return(null); } return(new ChessPoint(x, y)); }
protected bool canXMove(ChessPoint chessPoint) { int maxX = Math.Max(chessPoint.X, Location.X); int minX = Math.Min(chessPoint.X, Location.X); for (minX++; minX < maxX; minX++) { if (this.Board.GetChessman(new ChessPoint(minX, chessPoint.Y)) != null) { return(false); } } return(true); }
protected bool canYMove(ChessPoint chessPoint) { int maxY = Math.Max(chessPoint.Y, Location.Y); int minY = Math.Min(chessPoint.Y, Location.Y); for (minY++; minY < maxY; minY++) { if (this.Board.GetChessman(new ChessPoint(chessPoint.X, minY)) != null) { return(false); } } return(true); }
bool canYEat(ChessPoint chessPoint) { int maxY = Math.Max(chessPoint.Y, Location.Y); int minY = Math.Min(chessPoint.Y, Location.Y); int i = 0; for (minY++; minY < maxY && i < 2; minY++) { if (this.Board.GetChessman(new ChessPoint(chessPoint.X, minY)) != null) { i++; } } return(i == 1); }
bool canXEat(ChessPoint chessPoint) { int maxX = Math.Max(chessPoint.X, Location.X); int minX = Math.Min(chessPoint.X, Location.X); int i = 0; for (minX++; minX < maxX && i < 2; minX++) { if (this.Board.GetChessman(new ChessPoint(minX, chessPoint.Y)) != null) { i++; } } return(i == 1); }
public Knight(ChessPoint point, Chessboard board, bool isRed) : base(point, board, isRed) { canMovePoint = new List <Func <ChessPoint> >(8); canMovePoint.Add(Left_Buttom); canMovePoint.Add(Left_Up); canMovePoint.Add(Up_Left); canMovePoint.Add(Up_Right); canMovePoint.Add(Right_Up); canMovePoint.Add(Right_Bottom); canMovePoint.Add(Bottom_Right); canMovePoint.Add(Bottom_Left); }
ChessPoint Southwest() { ChessPoint currentPoint = this.Location; int x = currentPoint.X - 2; int y = currentPoint.Y + 2; if (XIsBeyond(x) || YIsBeyond(y)) { return(null); } if (Board.GetChessman(new ChessPoint(currentPoint.X - 1, currentPoint.Y + 1)) != null) { return(null); } return(new ChessPoint(x, y)); }
ChessPoint Up_Left() { ChessPoint currentPoint = this.Location; int x = currentPoint.X + 1; int y = currentPoint.Y - 2; if (XIsBeyond(x) || YIsBeyond(y)) { return(null); } if (Board.GetChessman(new ChessPoint(currentPoint.X, currentPoint.Y - 1)) != null) { return(null); } return(new ChessPoint(x, y)); }
ChessPoint Right_Bottom() { ChessPoint currentPoint = this.Location; int x = currentPoint.X + 2; int y = currentPoint.Y + 1; if (XIsBeyond(x) || YIsBeyond(y)) { return(null); } if (Board.GetChessman(new ChessPoint(currentPoint.X + 1, currentPoint.Y)) != null) { return(null); } return(new ChessPoint(x, y)); }
protected bool AnyOneInRoad(ChessPoint chessPoint) { if (chessPoint.X != Location.X) { if (!canXMove(chessPoint)) { return(true); } } else { if (!canYMove(chessPoint)) { return(true); } } return(false); }
void chessboard_ChessMoved(ChessPoint newPoint, ChessPoint oldPoint, ChessmanBase newChessman, ChessmanBase oldChessman) { _lastMoveChessman = _chessmanBaseDic[newChessman]; soundPlayer.Play(); //置换 IsRedTurn = !IsRedTurn; //移动动画 _chessmanBaseDic[newChessman].RenderTransform = _moveTransform; DoubleAnimation xAnimation = new DoubleAnimation((newPoint.X - oldPoint.X) * CellWidth, _moveDuration, FillBehavior.Stop); _moveTransform.BeginAnimation(TranslateTransform.XProperty, xAnimation); DoubleAnimation yAnimation = new DoubleAnimation((newPoint.Y - oldPoint.Y) * CellWidth, _moveDuration, FillBehavior.Stop); EventHandler tempAction = default(EventHandler); tempAction = delegate { _chessmanBaseDic[newChessman].ClearValue(UIElement.RenderTransformProperty); _chessmanBaseDic[newChessman].isSelected = false; _currentChessmanControl = null; if (oldChessman != null) { ChessmanCollection.Remove(_chessmanBaseDic[oldChessman]); } //更新 this.InvalidateArrange(); //移除本身 yAnimation.Completed -= tempAction; }; yAnimation.Completed += tempAction; _moveTransform.BeginAnimation(TranslateTransform.YProperty, yAnimation); }
protected sealed override bool CheckPoint(ChessPoint chessPoint) { if (!MoveInStraight(chessPoint)) { return(false); } if (!ContainSize(chessPoint)) { return(false); } if (this.Board.GetChessman(chessPoint) != null) { if (chessPoint.X != Location.X) { if (!canXEat(chessPoint)) { return(false); } } else { if (!canYEat(chessPoint)) { return(false); } } } else { if (AnyOneInRoad(chessPoint)) { return(false); } } return(true); }
protected virtual bool CheckPoint(ChessPoint chessPoint) { return(true); }
public Soldier(ChessPoint point, Chessboard board, bool isRed) : base(point, board, isRed) { }
public Elephant(ChessPoint point, Chessboard board, bool isRed) : base(point, board, isRed) { }
public Guard(ChessPoint point, Chessboard board, bool isRed) : base(point, board, isRed) { }
private bool MoveInStraight(ChessPoint chessPoint) { return(!(chessPoint.X != Location.X && chessPoint.Y != Location.Y)); }
bool MoveStep(ChessPoint chessPoint) { return(Math.Abs(chessPoint.X - Location.X) < 2 && Math.Abs(chessPoint.Y - Location.Y) < 2); }