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


C# Board.PieceAt方法代码示例

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


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

示例1: Print

        public void Print(Board board)
        {
            // Note that the outer loop iterates over the rows rather than the columns
            // because it is easier to build the lines this way. Also, we regard (0,0)
            // to be in the bottom left corner. Hence, we print the highest numbered
            // row first so that the last row printed will be row 0.

            var rowDivider = GetRowDivider(board);

            for (var y = board.BoardSize - 1; y >= 0; y--) {

                _printTarget.PrintLine(rowDivider);

                string line = string.Empty;

                // The inner loop iterates over the columns.
                for (var x = 0; x < board.BoardSize; x++) {
                    line += "|";

                    var piece = board.PieceAt(x, y);
                    if (piece != null) {
                        var square = board.SquareAt(x, y);
                        line += string.Format(
                            " {0}{1} ",
                            piece.Name,
                            square.Colour == Colour.Black ? "b" : "w");
                    }
                    else {
                        line += new string(' ', 4);
                    }
                }
                line += "|";

                _printTarget.PrintLine(line);
            }

            _printTarget.PrintLine(rowDivider);
        }
开发者ID:taylorjg,项目名称:DraughtBoardPuzzle,代码行数:38,代码来源:BoardPrinter.cs

示例2: Reset_GivenThatTheBoardContainsAtLeastOnePiece_ClearsAllSqaures

        public void Reset_GivenThatTheBoardContainsAtLeastOnePiece_ClearsAllSqaures()
        {
            // Arrange
            var board = new Board(TestBoardSize);
            var squares =
                new[]
                    {
                        // WBW
                        new Square(0, 0, Colour.White),
                        new Square(1, 0, Colour.Black),
                        new Square(2, 0, Colour.White)
                    };
            var piece = new Piece(squares);
            board.PlacePieceAt(piece, 0, 0);

            // Act
            board.Reset();

            // Assert
            for (int x = 0; x < board.BoardSize; x++) {
                for (int y = 0; y < board.BoardSize; y++) {
                    Assert.That(board.PieceAt(x, y), Is.Null);
                }
            }
        }
开发者ID:taylorjg,项目名称:DraughtBoardPuzzle,代码行数:25,代码来源:BoardTests.cs

示例3: PlacePiece_GivenALocationAndPieceShapeThatCausesAnOverlapWithAnExistingPiece_ReturnsFalse

        public void PlacePiece_GivenALocationAndPieceShapeThatCausesAnOverlapWithAnExistingPiece_ReturnsFalse()
        {
            // Arrange
            var squares1 =
                new[]
                    {
                        // WBW
                        new Square(0, 0, Colour.White),
                        new Square(1, 0, Colour.Black),
                        new Square(2, 0, Colour.White)
                    };
            var piece1 = new Piece(squares1);

            var squares2 =
                new[]
                    {
                        // BWB
                        new Square(0, 0, Colour.Black),
                        new Square(1, 0, Colour.White),
                        new Square(2, 0, Colour.Black)
                    };
            var piece2 = new Piece(squares2);

            var board = new Board(TestBoardSize);

            // Act
            var actual1 = board.PlacePieceAt(piece1, 1, 0);
            var actual2 = board.PlacePieceAt(piece2, 0, 0);

            // Assert
            Assert.That(actual1, Is.True);
            Assert.That(actual2, Is.False);
            Assert.That(board.PieceAt(0, 0), Is.Null);
            Assert.That(board.PieceAt(1, 0), Is.SameAs(piece1));
            Assert.That(board.PieceAt(2, 0), Is.SameAs(piece1));
            Assert.That(board.PieceAt(3, 0), Is.SameAs(piece1));
        }
开发者ID:taylorjg,项目名称:DraughtBoardPuzzle,代码行数:37,代码来源:BoardTests.cs

示例4: PieceAt_GivenUnoccupiedLocation_ReturnsNull

        public void PieceAt_GivenUnoccupiedLocation_ReturnsNull()
        {
            // Arrange
            var squares =
                new[]
                    {
                        // WBW
                        new Square(0, 0, Colour.White),
                        new Square(1, 0, Colour.Black),
                        new Square(2, 0, Colour.White)
                    };
            var piece = new Piece(squares);
            var board = new Board(TestBoardSize);

            // Act
            var actual = board.PlacePieceAt(piece, 1, 0);

            // Assert
            Assert.That(actual, Is.True);
            Assert.That(board.PieceAt(0, 0), Is.Null);
            Assert.That(board.PieceAt(0, 1), Is.Null);
        }
开发者ID:taylorjg,项目名称:DraughtBoardPuzzle,代码行数:22,代码来源:BoardTests.cs

示例5: PieceAt_GivenInvalidCoordinates_ThrowsException

        public void PieceAt_GivenInvalidCoordinates_ThrowsException(int x, int y)
        {
            // Arrange
            var board = new Board(TestBoardSize);

            // Act, Assert
            Assert.Throws<ArgumentOutOfRangeException>(() => board.PieceAt(x, y));
        }
开发者ID:taylorjg,项目名称:DraughtBoardPuzzle,代码行数:8,代码来源:BoardTests.cs


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