Beispiel #1
0
        public static void AddDiagonalMoves(Position currentPosition, Figure fig)
        {
            for (int i = 1; i <= currentPosition.X; i++)
            {
                if (currentPosition.Y - i >= 0)
                    {
                        Position p = new Position(currentPosition.X - i, (currentPosition.Y - i));
                        fig.validMoves.Add(p);
                    }

                if (currentPosition.Y + i <= 7)
                    {
                        Position p = new Position(currentPosition.X - i, (currentPosition.Y + i));
                        fig.validMoves.Add(p);
                    }
            }

            for (int i = 1; i <= 7 - currentPosition.X; i++)
            {

                    if (currentPosition.Y - i >= 0)
                    {
                        Position p = new Position(currentPosition.X + i, (currentPosition.Y - i));
                        fig.validMoves.Add(p);
                    }

                    if (currentPosition.Y + i <= 7)
                    {
                        Position p = new Position(currentPosition.X + i, (currentPosition.Y + i));
                        fig.validMoves.Add(p);
                    }

            }
        }
Beispiel #2
0
        public override void CalculateValidMoves(Position currentPosition)
        {
            Position p = new Position(0,0);
            for (int i = -2; i <= 2; i++)
            {
                for (int j = -2; j <= 2; j++)
                {
                    if (i * j == 2 || i * j == -2)
                    {
                        if (IsPositionOnBoard(p))
                        {
                            try
                            {
                                p.X = currentPosition.X + i;
                                p.Y = currentPosition.Y + j;
                                this.validMoves.Add(p);
                            }
                            catch (ArgumentOutOfRangeException)
                            {

                                continue;
                            }

                        }

                    }

                }
            }
        }
Beispiel #3
0
 internal Figure(FigureColor color, FigureType type, Position position)
 {
     this.color = color;
     this.type = type;
     this.position = position;
     CalculateValidMoves(position);
 }
Beispiel #4
0
 protected bool IsPositionOnBoard(Position p)
 {
     if (p.X >= 0 && p.X <= 7 && p.Y >= 0 && p.Y <= 7)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Beispiel #5
0
 internal Bishop(FigureColor color, FigureType type, Position position)
     : base(color, type, position)
 {
     switch (color)
     {
         case FigureColor.Black:
             draw = "\u265D";
             break;
         case FigureColor.White:
             draw = "\u2657";
             break;
     }
 }
Beispiel #6
0
 internal Knight(FigureColor color, FigureType type, Position position)
     : base(color, type, position)
 {
     switch (color)
     {
         case FigureColor.Black:
             draw = "\u265E";
             break;
         case FigureColor.White:
             draw = "\u2658";
             break;
     }
 }
Beispiel #7
0
 public override void CalculateValidMoves(Position currentPosition)
 {
     Figure.AddDiagonalMoves(currentPosition, this);
 }
Beispiel #8
0
        public static void AddHorizontalMoves(Position currentPosition, Figure fig)
        {
            for (int i = 0; i < currentPosition.X; i++)
            {
                Position p = new Position(i, currentPosition.Y);
                fig.validMoves.Add(p);
            }

            for (int i = currentPosition.X + 1; i <= 7; i++)
            {
                Position p = new Position(i, currentPosition.Y);
                fig.validMoves.Add(p);
            }
        }
Beispiel #9
0
 public virtual void Move(Position newPosition)
 {
     if (validMoves.Contains(newPosition))
     {
         this.position = newPosition;
         this.validMoves.Clear();
         CalculateValidMoves(this.position);
     }
 }
Beispiel #10
0
 public abstract void CalculateValidMoves(Position currentPosition);
Beispiel #11
0
 public static void VerticalPositions(Position currentPosition)
 {
     List<Position> positions = new List<Position>();
 }
Beispiel #12
0
        public static void AddVerticalMoves(Position currentPosition, Figure fig)
        {
            for (int i = 0; i < currentPosition.Y; i++)
            {
                Position p = new Position(currentPosition.X, i);
                fig.validMoves.Add(p);
            }

            for (int i = currentPosition.Y + 1; i <= 7; i++)
            {
                Position p = new Position(currentPosition.X, i);
                fig.validMoves.Add(p);
            }
        }
Beispiel #13
0
 internal Knight(FigureColor color, FigureType type, Position position)
     : base(color, type, position)
 {
 }
Beispiel #14
0
 internal Queen(FigureColor color, FigureType type, Position position)
     : base(color, type, position)
 {
 }