📄 main_f.frm
字号:
End
Begin VB.Menu Game_Music
Caption = " 06 "
Index = 6
End
Begin VB.Menu Game_Music
Caption = " 07 "
Index = 7
End
Begin VB.Menu Game_Music
Caption = " 08 "
Index = 8
End
Begin VB.Menu Game_Music
Caption = " 09 "
Index = 9
End
End
Begin VB.Menu GameSoundFaga
Caption = "系统声音"
Begin VB.Menu GameSoundFag
Caption = " 关闭 "
Index = 0
End
Begin VB.Menu GameSoundFag
Caption = " 打开 "
Checked = -1 'True
Index = 1
End
End
Begin VB.Menu GameMusicFag1
Caption = "背景音乐"
Begin VB.Menu GameMusicFag
Caption = " 关闭 "
Index = 0
End
Begin VB.Menu GameMusicFag
Caption = " 打开 "
Checked = -1 'True
Index = 1
End
End
End
Begin VB.Menu Help
Caption = "帮助(&H)"
Begin VB.Menu Help_R
Caption = "游戏规则"
Shortcut = ^R
End
Begin VB.Menu About
Caption = "关于"
Shortcut = ^I
End
End
End
Attribute VB_Name = "Main_F"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public BackMusic As New Mmusic
Dim mx As Integer
Private Sub Form_Load()
mx = 1
Timer1.Enabled = True
Are(0).Picture = LoadPicture("pic/1.jpg", , , 20, 20) '重pic目录下导入方块,墙,石化后的方块的元素
Are(1).Picture = LoadPicture("pic/2.jpg", , , 20, 20) '通过添加pic控件和改写显示部分可以加入更多图形,实现多种图形样式的方块
Are(2).Picture = LoadPicture("pic/3.jpg", , , 20, 20)
Main_P.ScaleMode = 3 '这不用解释了吧
Next_P.ScaleMode = 3
Main_F.Height = (Module.MapY + 1) * 350 + 2 '初始化主窗体的高和宽
Main_F.Width = (Module.MapX + 1) * 340 + 1800
Main_P.Height = (Module.MapY + 1) * 20 + 2 '初始化pic显示控件的高和宽
Main_P.Width = (Module.MapX + 1) * 20 + 2
Frame1.Top = 20 '初始化右边frame的高和宽,并确定它在main_f中的位置
Frame1.Left = Main_P.Width + 20
Frame1.Height = (Module.MapY + 1) * 20 + 2
Module.GameInfo.GameSpeed = 100 '初始游戏速度
Module.res_start '初始地图数组并显示
Module.GameInfo.GameLevel = 1 '初始等级为1
GameInfo.GameSoundFag = True '默认系统声音和背景音乐为打开
GameInfo.GameMusicFag = True
End Sub
'上面一些窗体以及相应其他外观的初始是为了以后只需添加一个检测屏幕分辨率的api就可以让本程序适应不同分辨率而设
'而且上面初始化会根据地图数组的大小而改变。改变数组大小窗体会自动适应
Private Sub Timer_Timer()
Module.Game_speed '调用Game_speed函数,确定相应的速度和等级,并检测是否升级
Timer.Interval = Module.GameInfo.GameSpeed '把速度给到time
Level_L.Caption = Game_level_Num(Module.GameInfo.GameLevel).Caption '显示等级
If BackMusic.Status = "stopped" Then '得到music类的“状态”属性,判断背景音乐是否停止(播放完毕)
Randomize
If Module.Startfag = True Then '如果游戏在进行(非暂停和停止状态)
Game_Music_Click (Int(9 * Rnd + 1)) '随机从9首背影音乐中选一首,并触发菜单Game_Music_Click(选取的序号)
Exit Sub
End If
End If
Module.Start '调用start
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Timer.Enabled = False Then '如果游戏停止(timer停止,即暂停和停止)则对keydown事件不做任何处理
Exit Sub '避免出现暂停状态还可以改变方块以及其他不该出现的状况
End If
Select Case KeyCode
Case 32
s = Module.Move("state", Module.fang1) '按下space时,触发move做相应处理(参数“state”等,是当前触发该事件的情况参数。不同情况move作不同处理)
Case 40
Timer.Enabled = False
s = Module.Move("down", Module.fang1)
Timer.Enabled = True
Case 39
s = Module.Move("right", Module.fang1)
Case 38
Case 37
s = Module.Move("left", Module.fang1)
End Select
End Sub
Public Sub Game_New_Click() '菜单的Game_New_Click,(选择新游戏)
If Startfag = True Then '当游戏正在进行中时,询问用户
BackMusic.mmPause '停止背影音乐
msg = MsgBox("您的游戏还没结束,你确定重新玩吗?", 36, "系统提示") '询问
If msg = vbNo Then
If Game_Stop.Caption = "暂停" And Module.GameInfo.GameMusicFag = True Then '选择“否”而且游戏不在暂停状态且音乐是开启状态时
BackMusic.mmPlay '继续播放音乐
End If
Exit Sub '不执行下面程序直接退出过程
End If
End If
Module.res_start '选择“是”后,初始化地图
Timer.Interval = Module.GameInfo.GameSpeed '初始速度
s = Module.Next_are(Module.fang1) '初始下一个方块给到fang1
s = Module.Next_are(Module.fang1) '第2次初始.实际上是初始一个fangnext和fang1
s = Module.zuobiao(fang1) '设定fang1初始坐标
Module.Startfag = True '开始标志设为true
Timer.Enabled = True 'timer工作
Game_Stop.Enabled = True '菜单中“暂停”显示
Game_Stop.Caption = "暂停"
If Module.GameInfo.GameMusicFag = True Then '如果音乐开关打开则播放音乐
BackMusic.mmPlay
End If
End Sub
'以下皆是菜单中的事件处理过程过于琐碎不做祥解:)
'
'
Private Sub Game_Stop_Click() '菜单中“暂停/继续”处理
If Game_Stop.Caption = "继续" Then
Timer.Enabled = True
If Module.GameInfo.GameMusicFag <> False Then
BackMusic.mmPlay
End If
Game_Stop.Caption = "暂停"
Else
Timer.Enabled = False
BackMusic.mmPause
Game_Stop.Caption = "继续"
End If
End Sub
Private Sub Game_Quit_Click()
End
End Sub
Public Sub Game_level_Num_Click(Index As Integer) '菜单中“级别”子选项处理
Dim level
level = Module.GameInfo.GameLevel
If Module.Startfag = True Then
BackMusic.mmPause
msg = MsgBox("您选择级别必须重新开始", 36, "系统提示")
If msg = vbNo Then
Module.GameInfo.GameLevel = level
BackMusic.mmPlay
Exit Sub
Else
Module.Startfag = False
Game_New_Click
End If
End If
For x = 1 To 5
If x <> Index Then
Game_level_Num(x).Checked = False
Else
Game_level_Num(x).Checked = True
Module.GameInfo.GameLevel = x
End If
Next x
End Sub
Public Sub Game_Music_Click(Index As Integer) '音乐选择处理
Game_Music(Index).Checked = True
mx = Index
Timer1.Enabled = True '调用timer1实现下面注释的这些控制音乐的功能
'If Game_Stop.Caption <> "继续" And Startfag = True And Module.GameInfo.GameMusicFag = True Then
'BackMusic.mmOpen (".\sound\m" & Index & ".mid")
'BackMusic.mmPlay
'Else
'BackMusic.mmOpen (".\sound\m" & Index & ".mid")
'BackMusic.mmStop
'BackMusic.setfile (".\sound\m" & Index & ".mid")
'End If
For i = 1 To 9
If i <> Index Then
Game_Music(i).Checked = False
End If
Next i
End Sub
Private Sub GameSoundFag_Click(Index As Integer) '菜单中系统声音开关处理
If Index = 1 Then
GameSoundFag(1).Checked = True
GameSoundFag(0).Checked = False
Module.GameInfo.GameSoundFag = True
Else
GameSoundFag(1).Checked = False
GameSoundFag(0).Checked = True
Module.GameInfo.GameSoundFag = False
End If
End Sub
Private Sub GameMusicFag_Click(Index As Integer) '菜单中音乐开关处理
If Index = 1 Then
GameMusicFag(1).Checked = True
GameMusicFag(0).Checked = False
Module.GameInfo.GameMusicFag = True
If Timer.Enabled <> False Then
BackMusic.mmPlay
End If
Else
GameMusicFag(1).Checked = False
GameMusicFag(0).Checked = True
Module.GameInfo.GameMusicFag = False
BackMusic.mmPause
End If
End Sub
Private Sub About_Click() 'about窗体
About_F.Visible = True
End Sub
Private Sub Help_R_Click() 'help窗体
Help_F.Visible = True
End Sub
'由于open背影音乐过慢,本来想在timer1中预处理可是实现不是十分理想:(,看来得用其他方法。
Private Sub Timer1_Timer()
If Game_Stop.Caption <> "继续" And Startfag = True And Module.GameInfo.GameMusicFag = True Then
BackMusic.mmOpen (".\sound\m" & mx & ".mid")
BackMusic.mmPlay
Else
BackMusic.mmOpen (".\sound\m" & mx & ".mid")
'BackMusic.mmStop
'BackMusic.setfile (".\sound\m" & Index & ".mid")
End If
Timer1.Enabled = False
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -