GameField.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Media;
using System.IO;
namespace Tetris
{
class GameField
{
public const int width = 20; //场景的宽,以方块个数为单位
public const int height = 30;
public const int SquareSize = 15; //每个四分之一小方块的边长
public static Color BackColor; //场景的背景色
public static System.IntPtr winHandle; //场景的handle
public static Color[] BlockForeColor = { Color.Blue, Color.Beige, Color.DarkKhaki, Color.DarkMagenta, Color.DarkOliveGreen, Color.DarkOrange, Color.DarkRed };
public static Color[] BlockBackColor = { Color.LightCyan, Color.DarkSeaGreen, Color.Beige, Color.Beige, Color.Beige, Color.Beige, Color.Beige };
public static bool isChanged = false; //设置是否被更改的标志位
public static SoundPlayer sound = new SoundPlayer();
public static Square[,] arriveBlock = new Square[width, height]; //保存已经不能再下落了的方块
public static int[] arrBitBlock = new int[height]; //位数组:当某个位置有方块时,该行的该位为1
private const int bitEmpty = 0x0; //0000 0000 0000 0000 0000
private const int bitFull = 0xFFFFF; //1111 1111 1111 1111 1111
/*检测是否为空*/
public static bool isEmpty(int x, int y)
{
//先检测是否越界
if (y < 0 || y >= height)
return false;
if (x < 0 || x >= width)
return false;
//然后检测是否为空
if ((arrBitBlock[y] & (1 << x)) != 0)
return false;
else
return true;
}
/*将方块停住*/
public static void stopSquare(Square sq, int x, int y)
{
arriveBlock[x, y] = sq;
arrBitBlock[y] = arrBitBlock[y] | (1 << x);
}
/*检测行是否满
* 返回:成功消除的行数和 (方便统计分数)
*/
public static int CheckLines()
{
//从最下面一行往上检测,当某行为空或到顶时结束
int lineFullCount = 0;
int y = height - 1;
while (y >= 0 && arrBitBlock[y] != bitEmpty)
{
if (arrBitBlock[y] == bitFull)
{
lineFullCount++; //消除一行记分
arrBitBlock[y] = bitEmpty;//消除该行的block
后面还有 50 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。