예제 #1
0
 public void TestKing_Position()
 {
     for (int i = 0; i < 100; i++)
     {
         Random random = new Random();
         int row = random.Next(0, 7);
         int col = random.Next(0, 7);
         Position position = new Position(row, col);
         King king = new King(position);
         Assert.AreEqual<Position>(king.Position, position, "King`s position is not working correctly");
     }
 }
예제 #2
0
        public Figure(Position position, char symbol)
        {
            this.Position = position;

            //if (((int)symbol >= (int)'a') && ((int)'z' <= (int)symbol))) ||
            //    ((int)symbol >= (int)'A' &&  (int)'Z' <= (int)symbol))
            if ((symbol >= 'A' && symbol <= 'Z') || (symbol >= 'a' && symbol <= 'z'))
            {
                this.symbolRepresentation = symbol;
            }
            else
            {
                throw new ArgumentOutOfRangeException("Not valid figure symbol");
            }
        }
예제 #3
0
 private bool IsValidGameBoardCell(Position position)
 {
     bool valid = this.gameBoard.IsInGameField(position) && this.gameBoard[position.Row, position.Column] == ' ';
     return valid;
 }
예제 #4
0
        /// <summary>
        /// Gets the displacement for figure movement
        /// </summary>
        private Position GetDisplacement(Direction direction)
        {
            Position displacement = null;
            switch (direction)
            {
                case Direction.DL:
                    displacement = new Position(1, -2);
                    break;
                case Direction.DR:
                    displacement = new Position(1, 2);
                    break;
                case Direction.UL:
                    displacement = new Position(-1, -2);
                    break;
                case Direction.UR:
                    displacement = new Position(-1, 2);
                    break;
                default:
                    throw new ArgumentException("Invalid direction for displacement!");
            }

            return displacement;
        }
예제 #5
0
        public void DrawGameBoard()
        {
            Console.WriteLine();
            for (int row = 0; row < gameBoard.GetLength(0); row++)
            {
                for (int col = 0; col < gameBoard.GetLength(1); col++)
                {
                    Position positionCell = new Position(row, col);
                    bool isCellIn = IsInGameField(positionCell);
                    if (isCellIn)
                    {
                        if (row % 2 == 0)
                        {
                            if (col % 4 == 0)
                            {
                                Console.BackgroundColor = ConsoleColor.Green;
                                Console.ForegroundColor = ConsoleColor.Black;
                                Console.Write(gameBoard[row, col]);
                                Console.ResetColor();
                            }
                            else if (col % 2 == 0)
                            {
                                Console.BackgroundColor = ConsoleColor.Blue;
                                Console.ForegroundColor = ConsoleColor.Black;
                                Console.Write(gameBoard[row, col]);
                                Console.ResetColor();
                            }
                            else //if (col % 2 != 0)
                            {
                                Console.Write(gameBoard[row, col]);
                            }
                        }
                        else if (col % 4 == 0)
                        {
                            Console.BackgroundColor = ConsoleColor.Blue;
                            Console.ForegroundColor = ConsoleColor.Black;
                            Console.Write(gameBoard[row, col]);
                            Console.ResetColor();
                        }
                        else if (col % 2 == 0)
                        {
                            Console.BackgroundColor = ConsoleColor.Green;
                            Console.ForegroundColor = ConsoleColor.Black;
                            Console.Write(gameBoard[row, col]);
                            Console.ResetColor();
                        }
                        else //if (col % 2 != 0)
                        {
                            Console.Write(gameBoard[row, col]);
                        }
                    }
                    else
                    {
                        Console.Write(gameBoard[row, col]);
                    }

                }
                Console.WriteLine();
                Console.ResetColor();
            }
            Console.WriteLine();
        }
예제 #6
0
        public bool IsInGameField(Position position)
        {
            int positonRow = position.Row;
            bool isRowInBoard = (positonRow >= topLeft.Row) && (positonRow <= bottomLeft.Row);
            int positonCol = position.Column;
            bool isColInBoard = (positonCol >= topLeft.Column) && (positonCol <= topRight.Column);
            bool isValidPosition = isRowInBoard && isColInBoard;

            return isValidPosition;
        }
예제 #7
0
 public King(Position position)
     : base(position, kingSymbol)
 {
     this.ExistingMoves = new bool[] { true, true, true, true };
 }
예제 #8
0
 public Pawn(Position position, char pawnSymbol)
     : base(position, pawnSymbol)
 {
     this.ExistingMoves = new bool[] { true, true };
 }