Пример #1
0
        public IFigure GetFigureAtPosition(Position position)
        {
            int arrRow = this.GetArrayRow(position.Row);
            int arrCol = this.GetArrayCol(position.Col);

            return this.board[arrRow, arrCol];
        }
Пример #2
0
        public static Position FromChessCoordinates(int chessRow, char chessCol)
        {
            var newPosition = new Position(chessRow, chessCol);
            ChechIfValid(newPosition);

            return newPosition;
        }
Пример #3
0
        public void RemoveFigure(Position position)
        {
            Position.ChechIfValid(position);

            int arrRow = this.GetArrayRow(position.Row);
            int arrCol = this.GetArrayCol(position.Col);
            this.board[arrRow, arrCol] = null;
        }
Пример #4
0
        public void MoveFigureAtPosition(IFigure figure, Position from, Position to)
        {
            int arrFromRow = this.GetArrayRow(from.Row);
            int arrFromCol = this.GetArrayCol(from.Col);
            this.board[arrFromRow, arrFromCol] = null;

            int arrToRow = this.GetArrayRow(to.Row);
            int arrToCol = this.GetArrayCol(to.Col);
            this.board[arrToRow, arrToCol] = figure;
        }
Пример #5
0
        public void AddFigure(IFigure figure, Position position)
        {
            ObjectValidator.CheckIfObjectIsNull(figure, GlobalErrorMessages.NullFigureErrorMessage);

            Position.ChechIfValid(position);

            int arrRow = this.GetArrayRow(position.Row);
            int arrCol = this.GetArrayCol(position.Col);
            this.board[arrRow, arrCol] = figure;
        }
Пример #6
0
        private bool CheckOtherFigureIfValid(IBoard board, Position to, ChessColor color)
        {
            var otherFigure = board.GetFigureAtPosition(to);
            if (otherFigure != null && otherFigure.Color == color)
            {
                return false;
            }

            return true;
        }
 private void AddPawnsToBoardRow(IPlayer player, IBoard board, int chessRow)
 {
     for (int i = 0; i < StandartGameTotalCols; i++)
     {
         var pawn = new Pawn(player.Color);
         player.AddFigure(pawn);
         var position = new Position(chessRow, (char)(i + 'a'));
         board.AddFigure(pawn, position);
     }
 }
 private void AddArmyToBoardRow(IPlayer player, IBoard board, int chessRow)
 {
     for (int i = 0; i < StandartGameTotalCols; i++)
     {
         var figureType = this.figureTypes[i];
         var figureInstance = (IFigure)Activator.CreateInstance(figureType, player.Color);
         player.AddFigure(figureInstance);
         var position = new Position(chessRow, (char)(i + 'a'));
         board.AddFigure(figureInstance, position);
     }
 }
Пример #9
0
        public static void ChechIfValid(Position position)
        {
            if (position.Row < GlobalConstants.MinimumRowValueOnBoard ||
                position.Row > GlobalConstants.MaximumRowValueOnBoard)
            {
                throw new IndexOutOfRangeException("Selected row position is not valid");
            }

            if (position.Col < GlobalConstants.MinimumColValueOnBoard ||
                position.Col > GlobalConstants.MaximumColValueOnBoard)
            {
                throw new IndexOutOfRangeException("Selected col position is not valid");
            }
        }
Пример #10
0
 private bool CheckDiagonalMove(Position from, Position to)
 {
     return (from.Col + 1 == to.Col || from.Col - 1 == to.Col);
 }