---------------------- Windows Phone 7手机开发 Net培训、期待与您交流! ----------------------
一.创建了各种各样的方块样式的源代码
/// <summary>
/// 创建了piece (砖块)各种各样的款式
/// 这个的样式有各种各样的类型 如'田'字型,'N'类型,'T'类型等等
/// 而且我们使他起始位置是(0,3)坐标的位置
/// </summary>
private void CreatePiece()
{
for (int x = 0; x < _columns; x++)
{
if (Container[0,x].Color!=null)
{
OnGameOver(null);
break;
}
}
Random random = new Random();
_currentPiece = _nextPiece == null ? _pieces[random.Next(0, 7)] : _nextPiece;
_nextPiece = _pieces[random.Next(0, 7)];
_positionX = 3;
_positionY = 0;
SetNextContainerUI();
}
一个是消去 方块的方法
public void Clear() { for (int x = 0; x < _columns; x++) { for (int y = 0; y < _rows; y++) { Container[y, x].Color = null; }
一个判断砖块是否是出界的方法
private bool IsBoundary(int[,] matrix, int offsetX, int offsetY) { RemovePiece(); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (matrix[i, j] == 1) { if (j + _positionX + offsetX > _columns - 1 || i + _positionY + offsetY > _rows - 1 || j + _positionX + offsetX < 0 || Container[i + _positionY + offsetY, j + _positionX + offsetX].Color != null) { AddPiece(0, 0); return true; } } } } AddPiece(0, 0); return false; }
---------------------- Windows Phone 7手机开发、.Net培训、期待与您交流! ----------------------
详细请查看:http://net.itheima.com/