Example #1
0
        public void DoCastling(Point startSquare, Point endSquare)
        {
            Figures figure = GetFigures(startSquare.X, startSquare.Y);

            if (endSquare.Y == 2)
            {
                MoveFigure(startSquare, endSquare);
                (figure as King).Moved = true;

                (GetFigures(endSquare.X, 0) as Rook).Moved = true;
                MoveFigure(new Point(endSquare.X, 0), new Point(endSquare.X, 3));

                RemoveEnPassant(figure);
            }
            if (endSquare.Y == 6)
            {
                MoveFigure(startSquare, endSquare);
                (figure as King).Moved = true;

                (GetFigures(endSquare.X, 7) as Rook).Moved = true;
                MoveFigure(new Point(endSquare.X, 7), new Point(endSquare.X, 5));

                RemoveEnPassant(figure);
            }
        }
Example #2
0
        public void MoveFigure(Point startP, Point endP)
        {
            Figures fig = GetFigures(startP.X, startP.Y);

            figures[startP.X, startP.Y] = null;
            figures[endP.X, endP.Y]     = fig;
            form.MoveFigure(startP, endP);
        }
Example #3
0
 public void RemoveEnPassant(Figures figures)
 {
     if (figures.IsWhite)
     {
         LPawnEnPassant = null;
     }
     else
     {
         DPawnEnPassant = null;
     }
 }
Example #4
0
 public void AddEnPassant(Figures figures)
 {
     if (figures.IsWhite)
     {
         LPawnEnPassant = figures;
     }
     else
     {
         DPawnEnPassant = figures;
     }
 }
Example #5
0
        public void DoEnPassant(Point startSquare, Point endSquare)
        {
            Figures figure = GetFigures(startSquare.X, startSquare.Y);

            if (figure.IsWhite)
            {
                MoveFigure(new Point(endSquare.X + 1, endSquare.Y), new Point(endSquare.X, endSquare.Y));
                MoveFigure(startSquare, endSquare);
                RemoveEnPassant(figure);
            }
            else
            {
                MoveFigure(new Point(endSquare.X - 1, endSquare.Y), new Point(endSquare.X, endSquare.Y));
                MoveFigure(startSquare, endSquare);
                RemoveEnPassant(figure);
            }
        }
Example #6
0
        public bool MakeMove(Point startSquare, Point endSquare)
        {
            Figures figure = figures[startSquare.X, startSquare.Y];

            if (figure.Moves.Contains(endSquare))
            {
                figure.Move(this, startSquare, endSquare);
                if (figure.Type == FigureTypes.Rook)
                {
                    (figure as Rook).Moved = true;
                }
                if (figure.Type == FigureTypes.King)
                {
                    (figure as King).Moved = true;
                }

                if (figure.Type == FigureTypes.Pawn && Math.Abs(startSquare.X - endSquare.X) == 2)
                {
                    AddEnPassant(figure);
                }
                else
                {
                    RemoveEnPassant(figure);
                }

                if (figure.Type == FigureTypes.Pawn && endSquare.X % 7 == 0)
                {
                    form.RemovePosibleMoves(figure.Moves);
                    Figures f = CreateFigure(form.ChooseReplacement(), figure.IsWhite);
                    figures[endSquare.X, endSquare.Y] = f;
                    form.SetImage(endSquare.X, endSquare.Y, f);
                }
                return(true);
            }
            return(false);
        }
Example #7
0
 public void SetFigure(Figures figure, Point position)
 {
     figures[position.X, position.Y] = figure;
     form.SetImage(position.X, position.Y, figure);
 }