예제 #1
0
파일: Board.cs 프로젝트: georgimanov/Chess
        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
파일: Board.cs 프로젝트: georgimanov/Chess
        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
파일: Board.cs 프로젝트: georgimanov/Chess
        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
파일: Board.cs 프로젝트: georgimanov/Chess
        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);
 }