BlockGroup.cs
(完整代码) 1KBusing System;
using System.Collections;
using System.Text;
using System.Drawing;
namespace Tetris
{
class BlockGroup
{
private InfoArr info; //存放所有方块样式信息
private Color disapperColor; //背景色
private int rectPix; //单元格像素
public BlockGroup() //构造函数
{
Config config = new Config();
config.LoadFromXmlFile();
info = new InfoArr();
info = config.Info;
disapperColor = config.BackColor;
rectPix = config.RectPix;
}
public Block GetABlock() //从方块组中随机抽取一个方块样式并返回
{
Random rd = new Random(); //实例化一个随机数类
int keyOrder = rd.Next(0, info.Length);//产生一个随机数
BitArray ba = info[keyOrder].ID;//把抽取的方块样式付给BitArray类对象ba
int struNum = 0; //确定主人个人方块样式中被填充的方块的个数
foreach (bool b in ba)//即需要确定Point数组的长度
{
if (b)
{
struNum++;
}
}
Point[] structArr = new Point[struNum];//新建一个Point数组,并确定其长度,以创建新的Block
int k = 0;
for (int j = 0; j < ba.Length; j++)
{ //用循环给Point数组赋坐标值
if (ba[j])
{
structArr[k].X = j / 5 - 2;
structArr[k].Y = 2 - j % 5;
k++;
}
}
return new Block(structArr, info[keyOrder].BColor, disapperColor, rectPix); //创建一个新方块并返回
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。