Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 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;
         }
     }
 }
Ejemplo n.º 3
0
 protected bool ContainSize(ChessPoint chessPoint)
 {
     if (XIsBeyond(chessPoint.X) || YIsBeyond(chessPoint.Y))
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 4
0
 public ChessmanBase(ChessPoint point, Chessboard board, bool isRed)
 {
     IsRed = isRed;
     Board = board;
     this.Board.SetDefalutChessman(point, this);
     _location    = point;
     defalutPoint = point;
 }
Ejemplo n.º 5
0
        bool MoveFrontOnly(ChessPoint chessPoint)
        {
            if (chessPoint.Y == Location.Y)
            {
                return(true);
            }

            return(defalutPoint.Y > 4 ? chessPoint.Y <Location.Y : chessPoint.Y> Location.Y);
        }
Ejemplo n.º 6
0
        bool CanHorizontalMove(ChessPoint chessPoint)
        {
            if (chessPoint.X == Location.X)
            {
                return(true);
            }

            return(defalutPoint.Y > 4 ? Location.Y < 5 : Location.Y > 4);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        protected sealed override bool CheckPoint(ChessPoint chessPoint)
        {
            foreach (var item in canMoveFunc)
            {
                if (!item(chessPoint))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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));
        }
Ejemplo n.º 13
0
        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));
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        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));
        }
Ejemplo n.º 20
0
        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));
        }
Ejemplo n.º 21
0
        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));
        }
Ejemplo n.º 22
0
        protected bool AnyOneInRoad(ChessPoint chessPoint)
        {
            if (chessPoint.X != Location.X)
            {
                if (!canXMove(chessPoint))
                {
                    return(true);
                }
            }
            else
            {
                if (!canYMove(chessPoint))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
        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);
        }
Ejemplo n.º 25
0
 protected virtual bool CheckPoint(ChessPoint chessPoint)
 {
     return(true);
 }
Ejemplo n.º 26
0
 public Soldier(ChessPoint point, Chessboard board, bool isRed)
     : base(point, board, isRed)
 {
 }
Ejemplo n.º 27
0
 public Elephant(ChessPoint point, Chessboard board, bool isRed)
     : base(point, board, isRed)
 {
 }
Ejemplo n.º 28
0
 public Guard(ChessPoint point, Chessboard board, bool isRed)
     : base(point, board, isRed)
 {
 }
Ejemplo n.º 29
0
 private bool MoveInStraight(ChessPoint chessPoint)
 {
     return(!(chessPoint.X != Location.X && chessPoint.Y != Location.Y));
 }
Ejemplo n.º 30
0
 bool MoveStep(ChessPoint chessPoint)
 {
     return(Math.Abs(chessPoint.X - Location.X) < 2 && Math.Abs(chessPoint.Y - Location.Y) < 2);
 }