本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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;
}