VB程序设计项目(俄罗斯方块)

'检查游戏区的各行 Dim i As Integer Dim j As Integer Dim k As Integer

For i = 190 To 10 Step -10

If Command1(i).Visible = True And _ Command1(i + 1).Visible = True And _ Command1(i + 2).Visible = True And _ Command1(i + 3).Visible = True And _ Command1(i + 4).Visible = True And _ Command1(i + 5).Visible = True And _ Command1(i + 6).Visible = True And _ Command1(i + 7).Visible = True And _ Command1(i + 8).Visible = True And _ Command1(i + 9).Visible = True Then For j = i + 4 To i Step -1 t = 1

Command1(j).Visible = False

Command1(2 * i + 9 - j).Visible = False For k = 1 To 4000 DoEvents Next t = 0 Next

LineNum = LineNum + 1

For j = i - 1 To 0 Step -1

If Command1(j).Visible = True Then Command1(j).Visible = False Command1(j + 10).Visible = True End If Next

'为了实现连消数行,这里使用递归调用 ClearLine End If Next End Sub

'自定义函数,确定方块是否能下降

Private Function DownAble() As Boolean

If GameNum(0) < 190 And GameNum(1) < 190 And GameNum(2) < 190 And GameNum(3) < 190 Then

If Command1(GameNum(0) + 10).Visible = False And _ Command1(GameNum(1) + 10).Visible = False And _ Command1(GameNum(2) + 10).Visible = False And _

16

Command1(GameNum(3) + 10).Visible = False Then DownAble = True Else

DownAble = False End If Else

DownAble = False End If End Function

'自定义函数,确定方块是否能左移

Private Function LeftAble() As Boolean

If GameNum(0) Mod 10 <> 0 And GameNum(1) Mod 10 <> 0 And GameNum(2) Mod 10 <> 0 And GameNum(3) Mod 10 <> 0 Then

If Command1(GameNum(0) - 1).Visible = False And _ Command1(GameNum(1) - 1).Visible = False And _ Command1(GameNum(2) - 1).Visible = False And _ Command1(GameNum(3) - 1).Visible = False Then LeftAble = True Else

LeftAble = False End If Else

LeftAble = False End If End Function

'自定义函数,确定方块是否能右移

Private Function RightAble() As Boolean

If GameNum(0) Mod 10 <> 9 And GameNum(1) Mod 10 <> 9 And GameNum(2) Mod 10 <> 9 And GameNum(3) Mod 10 <> 9 Then

If Command1(GameNum(0) + 1).Visible = False And _ Command1(GameNum(1) + 1).Visible = False And _ Command1(GameNum(2) + 1).Visible = False And _ Command1(GameNum(3) + 1).Visible = False Then RightAble = True Else

RightAble = False End If Else

RightAble = False End If End Function

17

'定义使方块旋转的过程 Private Sub Zhuan()

Select Case GameSituation

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'长条型方块由横着变成竖立状态 Case 0

If GameNum(0) - 18 >= 2 And GameNum(3) + 9 <= 198 Then If Command1(GameNum(0) - 18).Visible = False And _ Command1(GameNum(1) - 9).Visible = False And _ Command1(GameNum(3) + 9).Visible = False Then HideFanku (0)

GameNum(0) = GameNum(0) - 18 GameNum(1) = GameNum(1) - 9 GameNum(3) = GameNum(3) + 9 ShowFanku (0) GameSituation = 1 End If End If

'由竖立变成横着状态 Case 1

If (GameNum(0) + 18) Mod 10 < 8 And (GameNum(3) - 9) Mod 10 > 0 Then

If Command1(GameNum(0) + 18).Visible = False And _ Command1(GameNum(1) + 9).Visible = False And _ Command1(GameNum(3) - 9).Visible = False Then HideFanku (0)

GameNum(0) = GameNum(0) + 18 GameNum(1) = GameNum(1) + 9 GameNum(3) = GameNum(3) - 9 ShowFanku (0) GameSituation = 0 End If End If

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'正方形方块无变化 Case 2

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

18

'正S型方块的变化 Case 3

If GameNum(0) - 11 > 1 Then

If Command1(GameNum(0) - 11).Visible = False And _ Command1(GameNum(3) + 2).Visible = False Then HideFanku (0)

GameNum(0) = GameNum(0) - 11 GameNum(2) = GameNum(2) - 9 GameNum(3) = GameNum(3) + 2 ShowFanku (0) GameSituation = 4 End If End If Case 4

If (GameNum(3) - 2) Mod 10 < 9 Then

If Command1(GameNum(2) + 9).Visible = False And _ Command1(GameNum(3) - 2).Visible = False Then HideFanku (0)

GameNum(0) = GameNum(0) + 11 GameNum(2) = GameNum(2) + 9 GameNum(3) = GameNum(3) - 2 ShowFanku (0) GameSituation = 3 End If End If

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'反S型方块的变化 Case 5

If GameNum(0) - 9 > 1 Then

If Command1(GameNum(0) - 9).Visible = False And _ Command1(GameNum(3) - 2).Visible = False Then HideFanku (0)

GameNum(0) = GameNum(0) - 9 GameNum(2) = GameNum(2) - 11 GameNum(3) = GameNum(3) - 2 ShowFanku (0) GameSituation = 6 End If End If Case 6

If (GameNum(3) + 2) Mod 10 > 0 Then

If Command1(GameNum(2) + 11).Visible = False And _

19

Command1(GameNum(3) + 2).Visible = False Then HideFanku (0)

GameNum(0) = GameNum(0) + 9 GameNum(2) = GameNum(2) + 11 GameNum(3) = GameNum(3) + 2 ShowFanku (0) GameSituation = 5 End If End If

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'T型方块的变化 Case 7

If GameNum(0) - 9 > 0 Then

If Command1(GameNum(0) - 9).Visible = False Then HideFanku (0)

GameNum(0) = GameNum(0) - 9 GameNum(2) = GameNum(2) + 9 GameNum(3) = GameNum(3) - 11 ShowFanku (0) GameSituation = 8 End If End If Case 8

If (GameNum(0) + 11) Mod 10 > 0 Then

If Command1(GameNum(0) + 11).Visible = False Then HideFanku (0)

GameNum(0) = GameNum(0) + 11 GameNum(2) = GameNum(2) - 11 GameNum(3) = GameNum(3) - 9 ShowFanku (0) GameSituation = 9 End If End If Case 9

If GameNum(0) + 9 < 199 Then

If Command1(GameNum(0) + 9).Visible = False Then HideFanku (0)

GameNum(0) = GameNum(0) + 9 GameNum(2) = GameNum(2) - 9 GameNum(3) = GameNum(3) + 11 ShowFanku (0)

GameSituation = 10

20

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4