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

Command2(PreviewNum(0)).Visible = True Command2(PreviewNum(1)).Visible = True Command2(PreviewNum(2)).Visible = True Command2(PreviewNum(3)).Visible = True End Select End Sub

Private Sub beginGame_Click() Dim i As Integer Dim j As Integer

'游戏区图片控件获得焦点 Picture1.SetFocus

'根据设置的游戏速度来定义方块的下降速度 Timer2.Interval = 1000 / Val(Text2.Text) '根据设置的游戏难度来产生不同的地基

For i = 19 To 20 - Val(Text1.Text) Step -1 For j = i * 10 To i * 10 + 9

If Rnd >= 0.5 Then Command1(j).Visible = True Next Next

'引用预览区已经产生的方块 For i = 0 To 3

GameNum(i) = PreviewNum(i) Next

'在游戏区显示方块 ShowFanku (0) '获得当前方块状态

GameSituation = PreviewSituation '打开计时器

Timer2.Enabled = True

'将预览区的方块设置为不可见 HideFanku (1)

'在预览区重新产生方块 LoadFanku ShowFanku (1)

StopGame.Enabled = True End Sub

Private Sub Command3_Click()

End Sub

'退出游戏菜单

6

Private Sub ExitGame_Click() End End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If t = 0 Then HideFanku (0)

Select Case KeyCode

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

'点击向左键 Case vbKeyLeft

If LeftAble() = True Then For j = 0 To 3

Command1(GameNum(j) - 1).Visible = True GameNum(j) = GameNum(j) - 1 Next j End If

ShowFanku (0)

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

'点击向下键 Case vbKeyDown

If DownAble() = True Then For j = 0 To 3

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

ShowFanku (0)

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

'点击向右键 Case vbKeyRight

If RightAble() = True Then For j = 0 To 3

Command1(GameNum(j) + 1).Visible = True GameNum(j) = GameNum(j) + 1 Next j End If

ShowFanku (0)

7

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

'点击旋转键(向上键) Case vbKeyUp

ShowFanku (0) Zhuan

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

Case Else

ShowFanku (0) End Select End If End Sub

Private Sub Form_Load() Dim i As Integer '创建游戏区的方块 For i = 1 To 199 Load Command1(i) Next i

'在游戏区以10×20排列方块 For i = 0 To 199

Command1(i).Left = (i Mod 10) Command1(i).Top = i \\ 10 Command1(i).Visible = False Next i

'创建预览区的方块 For i = 1 To 39

Load Command2(i) Next i

'在预览区排列方块 For i = 0 To 39

Command2(i).Left = (i Mod 10) - 3 Command2(i).Top = i \\ 10 Command2(i).Visible = False Next i Randomize LoadFanku ShowFanku (1) End Sub

8

'级别菜单组,索引值从1开始

Private Sub grade_Click(Index As Integer) Dim j As Integer '取消所有级别的复选 For j = 1 To 5

grade(j).Checked = False Next

'在当前选择的级别后打勾 grade(Index).Checked = True '修改游戏设置中的级别 Text1.Text = Index End Sub

'帮助菜单

Private Sub helpAbout_Click() Dim Msg As String

Msg = \键盘控制方法:\

Msg = Msg & \左右光标键控制方块左右移动。\

Msg = Msg & \上光标键控制方块顺时针旋转90度。\

Msg = Msg & \下光标键控制方块加速向下移动。\ MsgBox Msg, vbOKOnly + vbQuestion, Me.Caption End Sub

'继续游戏菜单

Private Sub ResumeGame_Click() Timer2.Enabled = True

ResumeGame.Enabled = False StopGame.Enabled = True End Sub

'速度菜单组,索引值从1开始

Private Sub speed_Click(Index As Integer) Dim j As Integer '取消所有速度的复选 For j = 1 To 5

speed(j).Checked = False Next

'在当前选择的速度后打勾 speed(Index).Checked = True '修改游戏设置中的速度 Text2.Text = Index End Sub

'暂停游戏菜单

9

Private Sub StopGame_Click() Timer2.Enabled = False ResumeGame.Enabled = True StopGame.Enabled = False End Sub

Private Sub Timer1_Timer()

'产生随机的RGB颜色,改变字体的颜色 Randomize

Label1.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) End Sub

Private Sub LoadFanku() '随机产生一种方块的过程 Select Case Int(Rnd * 6) '长条型方块 Case 0

'长条型方块的两种变形 Select Case Int(Rnd * 2) Case 0

PreviewNum(0) = 3 PreviewNum(1) = 4 PreviewNum(2) = 5 PreviewNum(3) = 6 PreviewSituation = 0 Case 1

PreviewNum(0) = 5 PreviewNum(1) = 15 PreviewNum(2) = 25 PreviewNum(3) = 35 PreviewSituation = 1 End Select

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

'正方形方块 Case 1

PreviewNum(0) = 4 PreviewNum(1) = 5 PreviewNum(2) = 14 PreviewNum(3) = 15 PreviewSituation = 2 '正S型方块 Case 2

'正S型方块的两种变形

10

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