📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form frmMain
Caption = "俄罗斯方块"
ClientHeight = 7995
ClientLeft = -45
ClientTop = 525
ClientWidth = 6360
Icon = "Form1.frx":0000
KeyPreview = -1 'True
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 399.75
ScaleMode = 2 'Point
ScaleWidth = 318
Begin VB.Timer Timer1
Left = 4320
Top = 7560
End
Begin VB.Frame Frame4
Caption = "当前得分"
Height = 1095
Left = 4320
TabIndex = 7
Top = 5640
Width = 1935
Begin VB.TextBox txtScore
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 120
Locked = -1 'True
TabIndex = 8
Text = "0"
Top = 360
Width = 1695
End
End
Begin VB.Frame Frame3
Caption = "当前速度"
Height = 1095
Left = 4320
TabIndex = 5
Top = 4200
Width = 1935
Begin VB.TextBox txtSpeed
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 120
Locked = -1 'True
TabIndex = 6
Text = "0"
Top = 360
Width = 1695
End
End
Begin VB.Frame Frame2
Caption = "历史最高分"
Height = 1095
Left = 4320
TabIndex = 3
Top = 2760
Width = 1935
Begin VB.TextBox txtHistoryScore
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 120
Locked = -1 'True
TabIndex = 4
Text = "0"
Top = 360
Width = 1695
End
End
Begin VB.Frame Frame1
Caption = "下一个"
Height = 2055
Left = 4320
TabIndex = 1
Top = 120
Width = 1935
Begin VB.PictureBox Picture2
AutoRedraw = -1 'True
Height = 1455
Left = 240
ScaleHeight = 93
ScaleMode = 3 'Pixel
ScaleWidth = 93
TabIndex = 2
Top = 360
Width = 1455
End
End
Begin VB.PictureBox Picture1
AutoRedraw = -1 'True
Height = 7695
Left = 120
ScaleHeight = 509
ScaleMode = 3 'Pixel
ScaleWidth = 267
TabIndex = 0
Top = 120
Width = 4060
End
Begin VB.Line Line2
BorderColor = &H000000FF&
BorderWidth = 5
X1 = 0
X2 = 6
Y1 = 34
Y2 = 34
End
Begin VB.Label labPause
Appearance = 0 'Flat
BackColor = &H80000005&
BackStyle = 0 'Transparent
BorderStyle = 1 'Fixed Single
Caption = " 暂 停"
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 375
Left = 4680
TabIndex = 9
Top = 7080
Width = 1095
End
Begin VB.Menu mnuFile
Caption = "文件(&F)"
Begin VB.Menu mnuStart
Caption = "开始(&N)"
Shortcut = ^N
End
Begin VB.Menu mnuOption
Caption = "选项(&P)"
Shortcut = ^P
End
Begin VB.Menu mnuExit
Caption = "退出(&X)"
Shortcut = ^X
End
End
Begin VB.Menu mnuAbout
Caption = "关于(&A)"
End
Begin VB.Menu mnuHelp
Caption = "帮助(&H)"
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim isGameStart As Boolean '游戏开始标志
Dim isGameOver As Boolean '游戏结束标志
Dim isPause As Boolean '游戏暂停标志
Dim i, j, k As Integer
Dim score As Integer
Dim speed As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If pressOption = False Then KeyCode = 0
Select Case KeyCode
Case 37 'left键按下
Call moveBlockLeft
Case 38 'Up键按下
Call rotateBlock
Case 39 'Right键按下
Call moveBlockRight
Case 40 'Down键按下
Call moveBlockDown
End Select
KeyCode = 0
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If pressOption = True Then KeyAscii = 0
Select Case KeyAscii
Case 65
Case 97
Call moveBlockLeft
Case 87
Case 119
Call rotateBlock
Case 68
Case 100
Call moveBlockRight
Case 83
Case 115
Call moveBlockDown
End Select
KeyAscii = 0
End Sub
Private Sub Form_Load()
isPause = False '游戏开始暂停
'绘出游戏区方格
For j = 0 To 22
For i = 0 To 11
Picture1.Line (22 * i + 2, 22 * j + 2)-(22 * i + 22, 22 * j + 22), , B
Next i
Next j
'绘出预览区方格
For j = 0 To 3
For i = 0 To 3
Picture2.Line (22 * i + 3, 22 * j + 3)-(22 * i + 23, 22 * j + 23), , B
Next i
Next j
'初始化网格
Call GridInit
'初始化配置
Call config
'定义各种方块形状
Call defineBlock
'从文件读取历史最高分
Open App.Path & "\history.dat" For Input As #1
Input #1, highestScore
txtHistoryScore.Text = highestScore
Close #1
End Sub
Private Sub labPause_Click()
If isPause = False Then
isPause = True
Timer1.Enabled = False '禁止方块下落
frmMain.KeyPreview = False '禁止按键响应
labPause.Appearance = 1
labPause.Caption = " 继 续"
Exit Sub
End If
If isPause = True Then
isPause = False
Timer1.Enabled = True '恢复方块下落
frmMain.KeyPreview = True '恢复按键响应
labPause.Appearance = 0
labPause.Caption = " 暂 停"
Exit Sub
End If
End Sub
Private Sub mnuAbout_Click()
Load Form3
Form3.Show
End Sub
Private Sub mnuExit_Click()
'判断当前得分是否超过历史最高分,如果超过,则改写最高分
If Int(highestScore) < Int(txtScore.Text) Then
highestScore = txtScore.Text
Open App.Path & "\history.dat" For Output As #1
Print #1, highestScore
Close #1
End If
Unload frmMain
End Sub
Private Sub mnuHelp_Click()
Load Form4
Form4.Show
End Sub
Private Sub mnuOption_Click()
Load Form2
Form2.Show
End Sub
Private Sub mnuStart_Click()
isGameStart = True
mnuStart.Caption = "重新开始"
Timer1.Enabled = True '激活时钟
Timer1.Interval = 500 / fallGrid '设置游戏速度
Call clrGameZone '清除游戏区
Call clrNextBlockZone '清除预览区
Call dispGameBlock '显示正在下落的方块
Call nextBlockGenerate '生成下一个方块逻辑
If showNextBlock Then Call dispNextBlock '显示预览区的下一个方块
Call GridInit '重新初始化网格
End Sub
Sub dispNextBlock()
For i = 0 To 3
For j = 0 To 3
If blnBlock(nextBlock.blockType, nextBlock.blockDirection, i, j) Then
Picture2.Line (22 * j + 5, 22 * i + 5)-(22 * j + 21, 22 * i + 21), nextBlock.blockColor, BF
End If
Next j
Next i
End Sub
Sub dispGameBlock()
Call BlockInit
For i = 0 To 3
For j = 0 To 3
If blnBlock(currentBlock.blockType, currentBlock.blockDirection, i, j) Then
Picture1.Line (22 * (j + currentBlock.blockPosition.X) + 4, 22 * i + 4)-(22 * (j + currentBlock.blockPosition.X) + 20, 22 * i + 20), currentBlock.blockColor, BF
blnGrid(i, j + currentBlock.blockPosition.X) = True
End If
Next j
Next i
End Sub
Sub clrGameZone()
For j = 0 To 22
For i = 0 To 11
Picture1.Line (22 * i + 4, 22 * j + 4)-(22 * i + 20, 22 * j + 20), &H8000000F, BF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -