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


C# Piece.Equals方法代码示例

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


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

示例1: Equals_WhenSideIsDifferent_ShouldReturnFalse

        public void Equals_WhenSideIsDifferent_ShouldReturnFalse()
        {
            // Arrange
            var position = fixture.Create<Position>();
            var piece1 = new Piece(position, Side.Black);
            var piece2 = new Piece(position, Side.White);

            // Act
            var result = piece1.Equals(piece2);

            // Assert
            Assert.That(result, Is.False);
        }
开发者ID:cncplyr,项目名称:reversal,代码行数:13,代码来源:PieceTestFixture.cs

示例2: Equals_WhenPositionAndSideAreEqual_ShouldReturnTrue

        public void Equals_WhenPositionAndSideAreEqual_ShouldReturnTrue()
        {
            // Arrange
            var position = fixture.Create<Position>();
            var side = fixture.Create<Side>();
            var piece1 = new Piece(position, side);
            var piece2 = new Piece(position, side);

            // Act
            var result = piece1.Equals(piece2);

            // Assert
            Assert.That(result, Is.True);
        }
开发者ID:cncplyr,项目名称:reversal,代码行数:14,代码来源:PieceTestFixture.cs

示例3: Equals_WhenPositionIsDifferent_ShouldReturnFalse

        public void Equals_WhenPositionIsDifferent_ShouldReturnFalse()
        {
            // Arrange
            var position1 = new Position(0, 1);
            var position2 = new Position(0, 2);
            var side = fixture.Create<Side>();
            var piece1 = new Piece(position1, side);
            var piece2 = new Piece(position2, side);

            // Act
            var result = piece1.Equals(piece2);

            // Assert
            Assert.That(result, Is.False);
        }
开发者ID:cncplyr,项目名称:reversal,代码行数:15,代码来源:PieceTestFixture.cs

示例4: ValidMove

        public bool ValidMove(string[] playerTryMove, Piece playerPiece)
        {
            bool validMove = false;
            string startLocation = playerTryMove[2];
            string endLocation = playerTryMove[3];
            //Take 1 from all because array's start at 0
            int startRow = Int32.Parse(playerTryMove[2][1].ToString()) - 1;
            int startCol = Int32.Parse(playerTryMove[2][2].ToString()) - 1;
            int endRow = Int32.Parse(playerTryMove[3][1].ToString()) - 1;
            int endCol = Int32.Parse(playerTryMove[3][2].ToString()) - 1;

            if (cells[startRow, startCol].getPiece().Equals(playerPiece) && cells[endRow, endCol].getPiece().Equals(Piece.EMPTY))
            {
                //Check if cell is movable to
                if (moveableCell(cells[startRow, startCol], cells[endRow, endCol]))
                {
                    cells[startRow, startCol].piece = Piece.EMPTY;
                    cells[endRow, endCol].piece = playerPiece;
                    validMove = true;
                }
                else if (Math.Abs(startRow - endRow) == 2 && Math.Abs(startCol - endCol) == 2)
                {
                    Piece opponent;
                    if (playerPiece.Equals(Piece.PLAYER1))
                    {
                        opponent = Piece.PLAYER2;
                    }
                    else
                    {
                        opponent = Piece.PLAYER1;
                    }
                    int enemyRow = 0; ;
                    if (startRow > endRow)
                    {
                        enemyRow = startRow - 1;
                    }
                    else if (endRow > startRow)
                    {
                        enemyRow = startRow + 1;
                    }

                    int enemyCol = 0; ;
                    if (startCol > endCol)
                    {
                        enemyCol = startCol - 1;
                    }
                    else if (endCol > startCol)
                    {
                        enemyCol = startCol + 1;
                    }
                    if (cells[enemyRow, enemyCol].getPiece().Equals(opponent))
                    {
                        cells[startRow, startCol].piece = Piece.EMPTY;
                        cells[enemyRow, enemyCol].piece = Piece.EMPTY;
                        cells[endRow, endCol].piece = playerPiece;
                        validMove = true;
                    }
                }
            }


            Debug.WriteLine("start location: " + startLocation);
            Debug.WriteLine("end location: " + endLocation);
            Debug.WriteLine("start row: " + startRow);
            Debug.WriteLine("start col: " + startCol);
            Debug.WriteLine("end row: " + endRow);
            Debug.WriteLine("end col: " + endCol);

            //Check if it the users
            return validMove;

        }
开发者ID:bdr27,项目名称:c-,代码行数:72,代码来源:Board.cs


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