Vb写的俄罗斯方块 基本功能全'声明一个整数常量Width,表示游戏界面横向的小正方形数目,初始化为16
Public Const Width As Integer = 16
'声明一个整数常量Height,表示游戏界面横向的小正方形数目,初始化为30
Public Const Height As Integer = 30
'游戏界面的背景色
Public Shared BackColor As Color
'小正方形的大小
Public Shared SquareSize As Size = New Size(10, 10)
Public Shared g As Graphics
'声明一个Graphics变量,用于绘制下一个方块
Public Shared gNext As Graphics
'声明一个数组,用于表示游戏界面上的所有小正方形
Private Shared ArrGameField(Width - 1, Height - 1) As CSquare
'函数功能:判断ArrGameField(x, y)是否有正方形,有则返回False,无则返回True
Public Shared Function IsEmpty(ByVal x As Integer, ByVal y As Integer) As Boolean
If x >= 0 And x = 0 And y =0
'在循环体中,先判断第y行是否是满的,是的话result增1,并把第y行上的所有小正方形下降一行.最后y递减1
'如果实现把第y行的所有小正方形下降一行:从第y行扫描至第0行,每扫描一行,把上一行的每个小正方形赋值给该行,并修改每一个小正方形的Location属性的值
While Y >= 0
If IsLineFull(Y) Then
result += 1
For i As Integer = Y To 0 Step -1
If i > 0 Then
For x As Integer = 0 To Width - 1
ArrGameField(x, i) = ArrGameField(x, i - 1)
If Not ArrGameField(x, i) Is Nothing Then
ArrGameField(x, i).Location = New Point(ArrGameField(x, i).Location.X, ArrGameField(x, i).Location.Y + SquareSize.Height)
End If
Next
Else
For x As Integer = 0 To Width - 1
ArrGameField(x, i) = Nothing
Next
End If
Next
Else
2021-10-22 22:23:34
43KB
游戏
VB
1