📄 curshow.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace 俄罗斯方块
{
class CurShow : Show
{
public CurShow(int height, int width)
{
this.height = height;
this.width = width;
this.showArray = new bool[height, width];
}
public void DrawBack(Graphics g, SolidBrush sb, Pen p)
{
//Erase back
g.FillRectangle(sb, new Rectangle(100, 50, 20 * width, 20 * height));
//Hor Line
for (int i = 0; i <= height; i++)
{
g.DrawLine(p, new Point(100, 50 + i * 20), new Point(100 + 20 * width, 50 + i * 20));
}
//Ver Line
for (int i = 0; i <= width; i++)
{
g.DrawLine(p, new Point(100 + i * 20, 50), new Point(100 + i * 20, 50 + 20 * height));
}
}
public void saveArray(Shape s)//储存已下落好的图
{
for (int i = 0; i < s.height; i++)
for (int j = 0; j < s.width; j++)
{
if (s.type[i, j] == true)
showArray[s.y + i, s.x + j] = s.type[i, j];
}
}
public void DrawShowShape(Graphics g, SolidBrush sb)//当每次重画时,画出原先的已下落好的图
{
for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++)
{
if (showArray[i, j] == true)
g.FillRectangle(sb, new Rectangle(100 + j * 20, 50 + i * 20, 20, 20));
}
}
#region EraseFullRow
public int EraseFullRow()//删满行
{
int n = 0;//记录删多少行
for (int i = height-1; i >0; i--)
{
if (IsFull(i))
{
MoveRow(i);
n++;
i++;//若删了该行,上一行就下来了,所以i还是要从这行开始
}
}
return n;
}
private bool IsFull(int i)
{
int n=0;//记录占格子的数目
for (int j = 0; j < width; j++)
if (showArray[i, j] == true)
n++;
if (n == width)
return true;
else
return false;
}
private void MoveRow(int i)
{
for (int j = i; j > 0; j--)
for (int k = 0; k < width; k++)
showArray[j, k] = showArray[j - 1, k];//把上一行下移
for (int j = 0; j < width; j++)
showArray[0, j] = false;//插入一个新的第一行
}
#endregion
public bool IsLose()
{
for (int i = 0; i < width; i++)
{
if (showArray[0, i] == true)
return true;
}
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -