本文整理汇总了C#中Piece.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Piece.GetLength方法的具体用法?C# Piece.GetLength怎么用?C# Piece.GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piece
的用法示例。
在下文中一共展示了Piece.GetLength方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Board
public Board()
{
moveCounter = 0;
grid = new Piece[3, 3];
for (int row = 0; row < grid.GetLength(0); row++)
{
for (int column = 0; column < grid.GetLength(0); column++)
{
grid[row, column] = Piece.None;
}
}
}
示例2: Print2DArray
public static void Print2DArray(Piece[,] arr)
{
int rowLength = arr.GetLength(0);
int colLength = arr.GetLength(1);
for (int i = 0; i < rowLength; i++)
{
string line = "";
for (int j = 0; j < colLength; j++)
{
line += string.Format("{0} ", arr[i, j]);
}
Debug.Log(line);
}
}
示例3: getWinner
static Piece getWinner(Piece[,] board, int fixedIndex, Check check)
{
Piece color = getIthColor(board, fixedIndex, 0, check);
if (color == Piece.Empty)
return color;
for (int var = 1; var < board.GetLength(0); var++)
if (color != getIthColor(board, fixedIndex, var, check))
return Piece.Empty;
return color;
}
示例4: getIthColor
static Piece getIthColor(Piece[,] board, int index, int var, Check check)
{
if (check == Check.Row)
return board[index, var];
else if (check == Check.Col)
return board[var, index];
else if (check == Check.Diag)
return board[var, var];
else if (check == Check.RevDiag)
return board[board.GetLength(0) - 1 - var, var];
else
return Piece.Empty;
}
示例5: hasWon
static Piece hasWon(Piece[,] board)
{
int N = board.GetLength(0);
Piece winner;
for (int i = 0; i < N; i++)
{
if ((winner = getWinner(board, i, Check.Row)) != Piece.Empty)
return winner;
if ((winner = getWinner(board, i, Check.Col)) != Piece.Empty)
return winner;
}
if ((winner = getWinner(board, -1, Check.Diag)) != Piece.Empty)
return winner;
if ((winner = getWinner(board, -1, Check.RevDiag)) != Piece.Empty)
return winner;
return Piece.Empty;
}
示例6: RotateLayer
public void RotateLayer(Face face, int layerIndex, bool forward)
{
int faceIndex = (int)face;
Piece[,] oldMatrix = new Piece[CUBE_SIZE, CUBE_SIZE];
Piece[,] newMatrix = new Piece[CUBE_SIZE, CUBE_SIZE];
//Get Layer
switch (face)
{
case Face.X:
for(int y = 0; y < CUBE_SIZE; y++)
{
for(int z = 0; z < CUBE_SIZE; z++)
{
oldMatrix[y,z] = m_cube[layerIndex,y,z];
}
}
//[layer, XXX, XXX]
break;
case Face.Y:
for(int x = 0; x < CUBE_SIZE; x++)
{
for(int z = 0; z < CUBE_SIZE; z++)
{
oldMatrix[x,z] = m_cube[x,layerIndex,z];
}
}
//[XXX, layer, XXX]
break;
case Face.Z:
for(int x = 0; x < CUBE_SIZE; x++)
{
for(int y = 0; y < CUBE_SIZE; y++)
{
oldMatrix[x,y] = m_cube[x,y,layerIndex];
}
}
//[XXX, XXX, layer]
break;
}
//Rotate layer
if(forward)
{
int newColumn, newRow = 0;
for (int oldColumn = oldMatrix.GetLength(1) - 1; oldColumn >= 0; oldColumn--)
{
newColumn = 0;
for (int oldRow = 0; oldRow < oldMatrix.GetLength(0); oldRow++)
{
newMatrix[newRow, newColumn] = oldMatrix[oldRow, oldColumn];
newColumn++;
}
newRow++;
}
} else {
int newColumn, newRow = 0;
for (int oldColumn = 0; oldColumn < oldMatrix.GetLength(1); oldColumn++)
{
newColumn = 0;
for (int oldRow = oldMatrix.GetLength(0) - 1; oldRow >= 0; oldRow--)
{
newMatrix[newRow, newColumn] = oldMatrix[oldRow, oldColumn];
newColumn++;
}
newRow++;
}
}
// Print2DArray(oldMatrix);
// Print2DArray(newMatrix);
//Update layer
switch (face)
{
case Face.X:
for(int y = 0; y < CUBE_SIZE; y++)
{
for(int z = 0; z < CUBE_SIZE; z++)
{
Piece piece = newMatrix[y,z];
piece.UpdatePosition(layerIndex + CUBE_OFFSET, y + CUBE_OFFSET, z + CUBE_OFFSET);
m_cube[layerIndex,y,z] = piece;
}
}
//[layer, XXX, XXX]
break;
case Face.Y:
for(int x = 0; x < CUBE_SIZE; x++)
{
for(int z = 0; z < CUBE_SIZE; z++)
{
Piece piece = newMatrix[x,z];
piece.UpdatePosition(x + CUBE_OFFSET, layerIndex + CUBE_OFFSET, z + CUBE_OFFSET);
m_cube[x,layerIndex,z] = piece;
}
}
//[XXX, layer, XXX]
//.........这里部分代码省略.........