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


C# IBoard.SeeFigureOnPosition方法代码示例

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


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

示例1: RenderBoard

        public void RenderBoard(IBoard board)
        {
            int counter = 0;
            int startRow = (Console.BufferHeight / 2) - ((board.Size / 2) * BoardCellSymbolsCount);
            int startCol = (Console.BufferWidth / 2) - ((board.Size / 2) * BoardCellSymbolsCount);

            this.PrintBoardBorder(startRow - Renderer.BorderSize, startCol - Renderer.BorderSize, board);

            for (int row = 0; row < board.Size; row++)
            {
                for (int col = 0; col < board.Size; col++)
                {
                    int printRow = startRow + (row * BoardCellSymbolsCount);
                    int printCol = startCol + (col * BoardCellSymbolsCount);
                    ConsoleColor color = counter % 2 == 0 ? Renderer.DarkBoardCells : Renderer.LigthBoardCells;
                    var figure = board.SeeFigureOnPosition(row, col);
                    this.PrintCell(printRow, printCol, color, figure);
                    counter++;
                }

                counter++;
            }

            Console.BackgroundColor = ConsoleColor.Black;
            Console.WriteLine();
        }
开发者ID:zhenyaracheva,项目名称:Chess,代码行数:26,代码来源:Renderer.cs

示例2: 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(string.Format(GlobalConstants.ExceptionMessege, figure.Type));
            }

            int rowDirection = move.From.Row > move.To.Row ? -1 : 1;
            int colDirection = move.From.Col > move.To.Col ? -1 : 1;

            var row = move.From.Row;
            var col = move.From.Col;

            var endRow = move.To.Row + (rowDirection * (-1));
            var endCol = move.To.Col + (colDirection * (-1));

            while (row != endRow && col != endCol)
            {
                row += rowDirection;
                col += colDirection;

                if (board.SeeFigureOnPosition(row, col) != null)
                {
                    throw new InvalidOperationException(string.Format(GlobalConstants.ExceptionMessege, figure.Type));
                }
            }

            base.ValidateMove(figure, board, move);
        }
开发者ID:zhenyaracheva,项目名称:Chess,代码行数:32,代码来源:BishopMovement.cs

示例3: CheckCaslte

        private bool CheckCaslte(IFigure figure, IBoard board, Move move, FigureColor color, int row, int col, int startCheck, int endCheck)
        {
            if (figure.Color == color && move.To.Row == row && move.To.Col == col)
            {
                var rook = board.SeeFigureOnPosition(row, 0);

                if (rook.Color == color && rook.IsFirstMove && figure.IsFirstMove)
                {
                    for (int i = startCheck; i < endCheck; i++)
                    {
                        if (board.SeeFigureOnPosition(row, i) != null)
                        {
                            return false;
                        }

                    }

                    return true;
                }
            }

            return false;
        }
开发者ID:zhenyaracheva,项目名称:Chess,代码行数:23,代码来源:KingMovement.cs

示例4: ValidPLayerMoves

        private bool ValidPLayerMoves(Move move, IBoard board)
        {
            var figureToPosition = board.SeeFigureOnPosition(move.To.Row, move.To.Col);

            if (figureToPosition == null)
            {
                return this.ValidEmptyCellMoves(move, figureToPosition, board);
            }
            else if (figureToPosition.Color == this.oppositeColor)
            {
                if (move.From.Row + this.direction == move.To.Row && (move.From.Col - 1 == move.To.Col || move.From.Col + 1 == move.To.Col))
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:zhenyaracheva,项目名称:Chess,代码行数:18,代码来源:PawnMovement.cs

示例5: ValidateMove

        public override 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 > 0 && colDistance > 0)
            {
                throw new InvalidOperationException(string.Format(GlobalConstants.ExceptionMessege, figure.Type));
            }

            var rowDirection = move.From.Row < move.To.Row ? 1 : -1;
            var colDirection = move.From.Col < move.To.Col ? 1 : -1;

            rowDirection = rowDistance > 0 ? rowDirection : 0;
            colDirection = colDistance > 0 ? colDirection : 0;

            var row = move.From.Row;
            var col = move.From.Col;

            var finalRow = move.To.Row;// + (rowDirection * (-1));
            var finalCol = move.To.Col;// + (colDirection * (-1));

            while (true)
            {
                row += rowDirection;
                col += colDirection;

                if (board.SeeFigureOnPosition(row, col) != null)
                {
                    throw new InvalidOperationException(string.Format(GlobalConstants.ExceptionMessege, figure.Type));
                }

                if (row == finalRow && col == finalCol)
                {
                    break;
                }
            }

            base.ValidateMove(figure, board, move);
        }
开发者ID:zhenyaracheva,项目名称:Chess,代码行数:40,代码来源:RookMovement.cs

示例6: ValidEmptyCellMoves

        private bool ValidEmptyCellMoves(Move move, IFigure figure, IBoard board)
        {
            if (this.startRow == move.From.Row &&
                  move.From.Col == move.To.Col &&
                  move.From.Row + (2 * this.direction) == move.To.Row &&
                  board.SeeFigureOnPosition(move.From.Row + this.direction, move.From.Col) == null)
            {
                return true;
            }

            if (this.startRow == move.From.Row &&
                    move.From.Col == move.To.Col &&
                    move.From.Row + this.direction == move.To.Row)
            {
                return true;
            }

            if (move.From.Row + this.direction == move.To.Row && move.From.Col == move.To.Col && figure == null)
            {
                return true;
            }

            return false;
        }
开发者ID:zhenyaracheva,项目名称:Chess,代码行数:24,代码来源:PawnMovement.cs

示例7: CheckIfToPositionSafeKing

        private void CheckIfToPositionSafeKing(IPlayer attacker, IFigure playFigure, Move move, IBoard gameBoard, Position kingPosition, IDictionary<Position, IFigure> defenderFigures)
        {
            var toFigure = gameBoard.SeeFigureOnPosition(move.To.Row, move.To.Col);
            gameBoard.SetFigure(move.To.Row, move.To.Col, playFigure);
            gameBoard.SetFigure(move.From.Row, move.From.Col, null);
            kingPosition = this.FindKingPosition(attacker);

            if (this.CheckIfCheck(gameBoard, kingPosition, defenderFigures))
            {
                gameBoard.SetFigure(move.To.Row, move.To.Col, toFigure);
                gameBoard.SetFigure(move.From.Row, move.From.Col, playFigure);

                throw new InvalidOperationException("Under Chess Save Your King!");
            }

            gameBoard.SetFigure(move.To.Row, move.To.Col, toFigure);
            gameBoard.SetFigure(move.From.Row, move.From.Col, playFigure);
        }
开发者ID:zhenyaracheva,项目名称:Chess,代码行数:18,代码来源:ChessStandardGame.cs

示例8: TakeDefenderFigure

 private void TakeDefenderFigure(IPlayer attacker, IPlayer defender, Move move, IBoard gameBoard)
 {
     var figure = gameBoard.SeeFigureOnPosition(move.To.Row, move.To.Col);
     if (figure != null)
     {
         attacker.TakeFigure(move.To, figure, defender);
     }
 }
开发者ID:zhenyaracheva,项目名称:Chess,代码行数:8,代码来源:ChessStandardGame.cs


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