甲虫g200.frm
来自「游戏源码大家来看」· FRM 代码 · 共 549 行 · 第 1/2 页
FRM
549 行
'选取图案
Private Sub PCI_Click()
'CancelError 为 True。
On Error GoTo ErrHandler
With CommonDialog1
.DialogTitle = "选择拼图"
.CancelError = True
'ToDo: 设置 common dialog 控件的标志和属性
'设置过滤器。
.Filter = "Pictures (*.bmp;*.jpg;*.gif)|*.bmp;*.jpg;*.gif|所有文件 (*.*)|*.*"
'指定缺省过滤器。
'.FilterIndex = 2
'初始返回或设置文件目录。
.InitDir = (App.Path & "\image\")
'显示“打开”对话框。
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
Dim sfile As String
sfile = .FileName
End With
Picin.Picture = LoadPicture(sfile)
Object_Enabled True
Call Gstart
ErrHandler:
'用户按了“取消”按钮。
'GBegin = False
Exit Sub
End Sub
'Game start
Private Sub Gstart()
'On Error GoTo 1001
Dim i As Integer, j As Integer, s As Integer
GBegin = True '游戏开始,按键生效。
SBegin = False
If Picin.Width > Picin.Height Then
Picout.Width = Form1.ScaleWidth ' Picin.Width
Picout.Height = Form1.ScaleWidth * Picin.Height / Picin.Width
Else
Picout.Height = Form1.ScaleWidth ' Picin.Width
Picout.Width = Form1.ScaleWidth * Picin.Width / Picin.Height
End If
CenterImageZ Picout
ZiseInw = Int(Picin.ScaleWidth / 4)
ZiseInh = Int(Picin.ScaleHeight / 4)
ZiseOutw = Int(Picout.ScaleWidth / 4)
ZiseOuth = Int(Picout.ScaleHeight / 4)
'定义拼图大小
ReDim GImage(3, 3)
For i = 0 To 3
For j = 0 To 3
GImage(i, j).xin = i * ZiseInw
GImage(i, j).yin = j * ZiseInh
Next j, i
For i = 0 To 3
For j = 0 To 3
StretchBlt Picout.hdc, i * ZiseOutw, j * ZiseOuth, ZiseOutw, ZiseOuth, Picin.hdc, i * ZiseInw, j * ZiseInh, ZiseInw, ZiseInh, SRCCOPY
Sdata i, j, i, j, i, j
'Debug.Print GImage(i, j).xin & " " & GImage(i, j).yin & " " & GImage(i, j).xnow & " " & GImage(i, j).ynow
Next j, i
Picout.Refresh
Picin.Picture = LoadPicture("")
Picin.Height = Picout.Height
Picin.Width = Picout.Width
Picin.Picture = Picout.Image
ZiseInw = Int(Picin.ScaleWidth / 4)
ZiseInh = Int(Picin.ScaleHeight / 4)
Again_Click
End Sub
Private Sub Again_Click()
If GBegin = True Then
Dim s As Integer
For s = 0 To 64
Dim MyValue
Randomize ' 对随机数生成器做初始化的动作。
MyValue = Int((4 * Rnd) + 1) ' 生成 1 到 15 之间的随机数值。
Select Case MyValue
Case 1 'vbKeyUp:
Picout_KeyUp vbKeyUp, 0
Case 2 'vbKeyDown:
Picout_KeyUp vbKeyDown, 0
Case 3 'vbKeyLeft:
Picout_KeyUp vbKeyLeft, 0
Case 4 'vbKeyRight:
Picout_KeyUp vbKeyRight, 0
End Select
Next
Stime = Minute(Time$)
'Stime = Second(time$)
Play_wav "Start.wav"
End If
End Sub
Private Sub Form_Load()
'Add 方法的第四个参数设置了 Style 属性。
Dim i As Integer, j As Integer
For i = 1 To 2 '2
StatusBar1.Panels.Add
Next i
With StatusBar1.Panels
.Item(1).AutoSize = sbrContents
.Item(1).MinWidth = 2000
.Item(2).AutoSize = sbrContents
.Item(2).MinWidth = 900
.Item(2).Style = sbrTime
'.Item(2).Key = "Time panel"
.Item(3).AutoSize = sbrContents
.Item(3).MinWidth = 900
.Item(3).Text = "步数:" & Number
'.Item(3).Key = Label4.Caption
End With
Form1.StatusBar1.Panels(1).Text = "[liuhan][liaoli][qisui]"
Object_Enabled False
'按F1键调用与主程序同目录下的help.chm帮助文件,
App.HelpFile = App.Path & "\help\help.chm"
End Sub
Private Sub Form_Unload(Cancel As Integer)
FClose = True
Welcome.Show
End Sub
Private Sub Picout_KeyDown(KeyCode As Integer, Shift As Integer)
If GBegin = True Then SBegin = True
End Sub
Sub Object_Enabled(Answer As Boolean)
Form1.Again.Enabled = Answer
Form1.Toolbar1.Buttons(3).Enabled = Answer
End Sub
'步数计算、播放wav处理
Sub gNumber()
If SBegin = True Then
Number = Number + 1
Play_wav "Medal.wav "
End If
End Sub
'操作处理
Private Sub Picout_KeyUp(KeyCode As Integer, Shift As Integer)
'On Error GoTo 1001
Dim i As Integer, j As Integer, Ti As Integer, Tj As Integer
If GBegin = True Then
Select Case KeyCode
Case vbKeyEscape:
Form1.WindowState = 1
Case vbKeyF4:
Print_Font Picout, "jhhllk", 100, 200
'GAlphaBlend 255, 5, 0, Picin.hdc, 0, 0, Picin.ScaleWidth, Picin.ScaleHeight, Picout.hdc, 0, 0, Picout.ScaleWidth, Picout.ScaleHeight
Case vbKeyUp:
For i = 0 To 3
For j = 0 To 2
If GImage(i, j).xnow = 3 And GImage(i, j).ynow = 3 Then
Tj = j + 1
Gdata i, j, GImage(i, Tj).xnow, GImage(i, Tj).ynow
Gdata i, Tj, 3, 3
gNumber
GoTo 1002 'Exit For
End If
Next j, i
Case vbKeyDown:
For i = 0 To 3
For j = 1 To 3
If GImage(i, j).xnow = 3 And GImage(i, j).ynow = 3 Then
Tj = j - 1
Gdata i, j, GImage(i, Tj).xnow, GImage(i, Tj).ynow
Gdata i, Tj, 3, 3
gNumber
GoTo 1002 'Exit For
End If
Next j, i
Case vbKeyLeft:
For i = 0 To 2
For j = 0 To 3
If GImage(i, j).xnow = 3 And GImage(i, j).ynow = 3 Then
Ti = i + 1
Gdata i, j, GImage(Ti, j).xnow, GImage(Ti, j).ynow
Gdata Ti, j, 3, 3
gNumber
GoTo 1002 'Exit For
End If
Next j, i
Case vbKeyRight:
For i = 1 To 3
For j = 0 To 3
If GImage(i, j).xnow = 3 And GImage(i, j).ynow = 3 Then
Ti = i - 1
Gdata i, j, GImage(Ti, j).xnow, GImage(Ti, j).ynow
Gdata Ti, j, 3, 3
gNumber
GoTo 1002 'Exit For
End If
Next j, i
'Case vbKeyReturn:
End Select
1002:
GDraw
If SBegin = True Then
Gpass
End If
DoEvents
Else
Exit Sub
End If
'1001:
' Resume Next
End Sub
Private Sub Picout_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If GBegin = True Then SBegin = True
End Sub
Private Sub Picout_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If GBegin = True And Button = 1 Then
Dim i As Integer, j As Integer, l As Integer, r As Integer, u As Integer, d As Integer
i = Int(x / ZiseOutw)
j = Int(y / ZiseOuth)
If j - 1 >= 0 Then
If GImage(i, j - 1).xnow = 3 And GImage(i, j - 1).ynow = 3 Then Picout_KeyUp vbKeyUp, Shift
End If
If j + 1 <= 3 Then
If GImage(i, j + 1).xnow = 3 And GImage(i, j + 1).ynow = 3 Then Picout_KeyUp vbKeyDown, Shift
End If
If i - 1 >= 0 Then
If GImage(i - 1, j).xnow = 3 And GImage(i - 1, j).ynow = 3 Then Picout_KeyUp vbKeyLeft, Shift
End If
If i + 1 <= 3 Then
If GImage(i + 1, j).xnow = 3 And GImage(i + 1, j).ynow = 3 Then Picout_KeyUp vbKeyRight, Shift
End If
End If
End Sub
'工具栏
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Index
Case 1
Call Exit_Click
Case 2
Call PCI_Click
Case 3
Call Again_Click
Case 4
关于本程式.Show
Case 6
Case 7
End Select
End Sub
'程式提醒
Private Sub Exit_Click()
Dim msg, Style, Title, Help, Ctxt, Response, MyString
If GBegin = True Then
msg = "决定放弃本局" + Chr(10) + "并退出本程式?" ' 定义信息。
Style = vbOKCancel + vbInformation + vbDefaultButton2 ' 定义按钮。
Else
msg = " See you again!" ' 定义信息。
End If
Title = "See again" ' 定义标题。
Response = MsgBox(msg, Style, Title, Help, Ctxt)
If Response = vbOK Then End ' 用户按下“是”。
End Sub
'移动图片
Public Sub CenterImageZ(dest As Control)
dest.Move (dest.Container.ScaleWidth - dest.Width) / 2, (dest.Container.ScaleHeight - dest.Height) / 2
End Sub
'主页
Private Sub web_MX_Click()
Dim HyperJump
HyperJump = ShellExecute(0&, vbNullString, web, vbNullString, vbNullString, vbNormalFocus)
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?