当前位置: 首页>>代码示例>>C#>>正文


C# IBoard.GetFigureAtPosition方法代码示例

本文整理汇总了C#中IBoard.GetFigureAtPosition方法的典型用法代码示例。如果您正苦于以下问题:C# IBoard.GetFigureAtPosition方法的具体用法?C# IBoard.GetFigureAtPosition怎么用?C# IBoard.GetFigureAtPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IBoard的用法示例。


在下文中一共展示了IBoard.GetFigureAtPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckIfFigureOnTheWay

 public static void CheckIfFigureOnTheWay(IPosition position, IBoard board, string message)
 {
     if (board.GetFigureAtPosition(position) != null)
     {
         throw new ArgumentException(message);
     }
 }
开发者ID:Fatme,项目名称:King-Survival-4,代码行数:7,代码来源:Validator.cs

示例2: KingWon

        /// <summary>
        /// Method that checks whether the king won or not
        /// </summary>
        /// <param name="players">The game players</param>
        /// <param name="board">The game board</param>
        /// <returns>Returns true if the king meets curtain conditions</returns>
        public bool KingWon(IList<IPlayer> players, IBoard board)
        {
            var kingPlayer = players[0];
            var pawnPlayer = players[1];

            ////check if king is on the first row
            foreach (var figure in kingPlayer.Figures)
            {
                    if (board.GetFigurePosition((IFigure)figure.Value).Row == 0)
                    {
                        return true;
                    }
            }

            //// check if all powns are on the last row
            for (int i = 1; i < board.NumberOfRows; i += 2)
            {
                if (board.GetFigureAtPosition(new Position(board.NumberOfColumns - 1, i)) == null)
                {
                    return false;
                }
            }

            return true;
        }
开发者ID:kskondov,项目名称:King-Survival-4,代码行数:31,代码来源:WinningConditions.cs

示例3: RenderBoard

        public void RenderBoard(IBoard board)
        {
            this.PrintHorizontalNumbers();
            for (int row = 0; row < board.NumberOfRows; row++)
            {
                Console.Write(row + "| ");
                for (int column = 0; column < board.NumberOfColumns; column++)
                {
                    Position position = new Position(row, column);
                    var figure = board.GetFigureAtPosition(position);

                    if (figure != null)
                    {
                        Console.Write(figure.DisplayName + " ");
                    }
                    else
                    {
                        this.PrintCell(position);
                    }
                }

                Console.Write("|");
                Console.WriteLine();
            }

            this.PrintHorizontalLines();
        }
开发者ID:Fatme,项目名称:King-Survival-4,代码行数:27,代码来源:ConsoleRenderer.cs

示例4: CheckIfFigureOnTheWay

 /// <summary>
 /// Checks if the figure is on the way that the figures want to move
 /// </summary>
 /// <param name="position">Position on which the figure moves</param>
 /// <param name="board">The game board</param>
 /// <exception cref="InvalidPositionException"></exception>
 public static void CheckIfFigureOnTheWay(IPosition position, IBoard board)
 {
     if (board.GetFigureAtPosition(position) != null)
     {
         throw new InvalidPositionException(GlobalErrorMessages.FigureOnTheWayErrorMessage);
     }
 }
开发者ID:kskondov,项目名称:King-Survival-4,代码行数:13,代码来源:Validator.cs

示例5: CheckOtherFigureIfValid

        private bool CheckOtherFigureIfValid(IBoard board, Position to, ChessColor color)
        {
            var otherFigure = board.GetFigureAtPosition(to);
            if (otherFigure != null && otherFigure.Color == color)
            {
                return false;
            }

            return true;
        }
开发者ID:georgimanov,项目名称:Chess,代码行数:10,代码来源:NormalKingMovement.cs

示例6: ValidateMove

        public void ValidateMove(IFigure figure, IBoard board, Move move)
        {
            var rowDistance = Math.Abs(move.From.Row - move.To.Row);
            var colDistance = Math.Abs(move.From.Col - move.To.Col);

            if (rowDistance != colDistance)
            {
                throw new InvalidOperationException(BishopInvalidMove);
            }

            var from = move.From;
            var to = move.To;

            int rowIndex = from.Row;
            char colIndex = from.Col;
            var other = figure.Color == ChessColor.White ? ChessColor.Black : ChessColor.White;

            // top-right
            while (true)
            {
                rowIndex++;
                colIndex++;
                if (to.Row == rowIndex && to.Col == colIndex)
                {
                    var figureAtPosition = board.GetFigureAtPosition(to);
                    if (figureAtPosition != null && figureAtPosition.Color == figure.Color)
                    {
                        throw new InvalidOperationException("There is a figure on the way!");
                    }
                    else
                    {
                        return;
                    }
                }

                var position = Position.FromChessCoordinates(rowIndex, colIndex);
                var figAtPosition = board.GetFigureAtPosition(position);
                if (figAtPosition != null)
                {
                    throw new InvalidOperationException("There is a figure on the way!");
                }
            }
        }
开发者ID:King-Survival-3,项目名称:HQC-Teamwork-2015,代码行数:43,代码来源:NormalBishopMovement.cs

示例7: DownChecker

 private void DownChecker(IBoard board, Position from, Position to)
 {
     for (int i = from.Row; i > to.Row + 1; i--)
     {
         Position curentPosition = new Position(i - 1, from.Col);
         var figureAtPosition = board.GetFigureAtPosition(curentPosition);
         if (figureAtPosition != null)
         {
             throw new InvalidOperationException("Rook cannot move this way!");
         }
     }
 }
开发者ID:totkov,项目名称:ChessGameEngine,代码行数:12,代码来源:NormalRookMovement.cs

示例8: CheckIfPositionIsEmpty

        private bool CheckIfPositionIsEmpty(Position position, IBoard board)
        {
            if (this.CheckIfInsideTheBoard(position))
            {
                if (board.GetFigureAtPosition(position) == null)
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:Fatme,项目名称:King-Survival-4,代码行数:12,代码来源:WinningConditions.cs

示例9: RightChecker

 private void RightChecker(IBoard board, Position from, Position to)
 {
     var currentCol = from.Col + 1;
     for (int i = from.Col; i < to.Col - 1; i++)
     {
         Position curentPosition = new Position(from.Row, (char)currentCol);
         var figureAtPosition = board.GetFigureAtPosition(curentPosition);
         if (figureAtPosition != null)
         {
             throw new InvalidOperationException("Rook cannot move this way!");
         }
         currentCol++;
     }
 }
开发者ID:totkov,项目名称:ChessGameEngine,代码行数:14,代码来源:NormalRookMovement.cs

示例10: BoardToFen

        public static string BoardToFen(IBoard board)
        {
            var fen = new StringBuilder();
            var reversedRow = board.TotalRows;
            for (int row = 1; row <= board.TotalRows; row++)
            {
                var empySpace = 0;
                for (int col = 0; col < board.TotalCols; col++)
                {
                    var figure = board.GetFigureAtPosition(new Position(reversedRow, (char)('a' + col)));

                    if (figure == null)
                    {
                        empySpace++;
                    }
                    else
                    {
                        if (empySpace != 0)
                        {
                            fen.Append(empySpace);
                            empySpace = 0;
                        }

                        if (figure is King)
                        {
                            fen.Append('K');
                        }
                        else
                        {
                            fen.Append('p');
                        }
                    }

                    if (col == (board.TotalCols - 1) && empySpace != 0)
                    {
                        fen.Append(empySpace);
                    }
                }

                if (row != board.TotalRows)
                {
                    fen.Append('/');
                }

                reversedRow--;
            }

            return fen.ToString();
        }
开发者ID:King-Survival-3,项目名称:HQC-Teamwork-2015,代码行数:49,代码来源:BoardHelper.cs

示例11: RenderBoard

        public void RenderBoard(IBoard board)
        {
            for (int row = 0; row < board.NumberOfRows; row++)
            {
                for (int column = 0; column < board.NumberOfColumns; column++)
                {

                   // int cell = board[row, colum];
                    Position position=new Position(row,column);
                    var figure = board.GetFigureAtPosition(position);

                    ConsoleHelpers.PrintFigure(figure,position);
               }
                Console.WriteLine();
            }
        }
开发者ID:havaliova,项目名称:King-Survival-4,代码行数:16,代码来源:ConsoleRenderer.cs

示例12: RenderBoard

        public void RenderBoard(IBoard board)
        {
            // TODO: Validate Console Dimension
            var startRowPrint = (Console.WindowWidth / 2) - ((board.TotalRows / 2) * ConsoleConstants.CharactersPerRowPerBoardSquare);
            var startColPrint = (Console.WindowHeight / 2) - ((board.TotalCols / 2) * ConsoleConstants.CharactersPerColPerBoardSquare);

            int currentRowPrint = startRowPrint;
            int currentColPrint = startColPrint;

            this.RenderBoarderForBord(startRowPrint, startColPrint, board.TotalRows, board.TotalCols);

            int counter = 1;
            for (int top = 0; top < board.TotalCols; top++)
            {
                for (int left = 0; left < board.TotalRows; left++)
                {
                    currentColPrint = startRowPrint + (left * ConsoleConstants.CharactersPerColPerBoardSquare);
                    currentRowPrint = startColPrint + (top * ConsoleConstants.CharactersPerRowPerBoardSquare);

                    ConsoleColor backgroundColor;

                    if (counter % 2 == 0)
                    {
                        backgroundColor = DarskSquareConsoleColor;
                        Console.BackgroundColor = DarskSquareConsoleColor;
                    }
                    else
                    {
                        backgroundColor = LightSquareConsoleColor;
                        Console.BackgroundColor = LightSquareConsoleColor;
                    }

                    var position = Position.FromArrayCoordinates(top, left, board.TotalRows);

                    var figure = board.GetFigureAtPosition(position);
                    ConsoleHelpers.PrintFigure(figure, backgroundColor, currentRowPrint, currentColPrint);

                    counter++;
                }

                counter++;
            }
        }
开发者ID:King-Survival-3,项目名称:HQC-Teamwork-2015,代码行数:43,代码来源:ConsoleRenderer.cs

示例13: ValidateMove

        public override void ValidateMove(IFigure figure, IBoard board, Move move)
        {
            var from = move.From;
            var to = move.To;

            if ((from.Row - 1 == to.Row && from.Col + 1 == to.Col) ||
                (from.Row - 1 == to.Row && from.Col - 1 == to.Col))
            {
                var otherFigure = board.GetFigureAtPosition(to);

                if (otherFigure != null)
                {
                    throw new InvalidOperationException(InvalidMove);
                }

                return;
            }

            throw new InvalidOperationException(InvalidMove);
        }
开发者ID:King-Survival-3,项目名称:HQC-Teamwork-2015,代码行数:20,代码来源:KingSurvivalPawnMovement.cs

示例14: DownLeftChecker

 private void DownLeftChecker(IBoard board, Position from, Position to)
 {
     var fromRow = from.Row;
     var fromCol = from.Col;
     var currentRow = fromRow;
     var currentCol = fromCol;
     while (true)
     {
         currentRow--;
         currentCol--;
         if (currentRow == to.Row && currentCol == to.Col)
         {
             return;
         }
         Position curentPosition = new Position(currentRow, currentCol);
         var figureAtPosition = board.GetFigureAtPosition(curentPosition);
         if (figureAtPosition != null)
         {
             throw new InvalidOperationException("Bishop cannot move this way!");
         }
     }
 }
开发者ID:totkov,项目名称:ChessGameEngine,代码行数:22,代码来源:NormalBishopMovement.cs

示例15: RenderBoard

        public void RenderBoard(IBoard board)
        {
            Console.Clear();

            var startRowPrint = Console.BufferWidth / 2 - (board.TotalRows / 2) * ConsoleConstants.CharactersPerRowPerBoardSquare;
            var startColPrint = Console.BufferHeight / 2 - (board.TotalCols / 2) * ConsoleConstants.CharactersPerColPerBoardSquare;

            var currentRowPrint = startRowPrint;
            var currentColPrint = startColPrint;

            this.PrintBorder(startRowPrint, startColPrint, board.TotalRows, board.TotalCols);

            int counter = 1;
            for (int top = 0; top < board.TotalRows; top++)
            {
                for (int left = 0; left < board.TotalCols; left++)
                {
                    currentColPrint = startRowPrint + left * ConsoleConstants.CharactersPerColPerBoardSquare;
                    currentRowPrint = startColPrint + top * ConsoleConstants.CharactersPerRowPerBoardSquare;

                    ConsoleColor background;
                    if (counter % 2 == 0)
                    {
                        background = DarkSquareConsoleColor;
                        Console.BackgroundColor = DarkSquareConsoleColor;
                    }
                    else
                    {
                        background = LightSquareConsoleColor;
                        Console.BackgroundColor = LightSquareConsoleColor;
                    }

                    var position = new Position(board.TotalRows - top, (char)(left + 'a'));

                    var figure = board.GetFigureAtPosition(position);

                    ConsolePrintFigure.Print(figure, background, currentRowPrint, currentColPrint);

                    counter++;
                }
                counter++;
            }

            Console.SetCursorPosition(Console.WindowWidth / 2, 1);
        }
开发者ID:totkov,项目名称:ChessGameEngine,代码行数:45,代码来源:ConsoleRenderer.cs


注:本文中的IBoard.GetFigureAtPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。