
如何用VB编写拼图游戏? 10
最好是可以让玩家自定义拼图片数的那种而且可以让玩家选择喜欢的图片类型,我自己会准备很多图片。希望把全部的程序发过来,还要EXE格式的确定能玩我的邮箱:1181666727...
最好是可以让玩家自定义拼图片数的那种
而且可以让玩家选择喜欢的图片类型,我自己会准备很多图片。
希望把全部的程序发过来,还要EXE格式的确定能玩
我的邮箱:1181666727@qq.com 展开
而且可以让玩家选择喜欢的图片类型,我自己会准备很多图片。
希望把全部的程序发过来,还要EXE格式的确定能玩
我的邮箱:1181666727@qq.com 展开
2个回答
展开全部
'给你代码,你自己编吧
'你先在窗体上画一个图片控件Picture1,再把这代码复制进去,运行后看看是不是能拖动了。
'然后再多画几个图片控件,代码以此类推
'有点VB经验的人都会这个
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Dim blnDragging As Boolean
Dim offsetX As Single, offsetY As Single
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnDragging Then
Picture1.Move X - offsetX, Y - offsetY
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnDragging = False
ReleaseCapture
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
blnDragging = True
SetCapture Me.hwnd
offsetX = X
offsetY = Y
End If
End Sub
'你先在窗体上画一个图片控件Picture1,再把这代码复制进去,运行后看看是不是能拖动了。
'然后再多画几个图片控件,代码以此类推
'有点VB经验的人都会这个
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Dim blnDragging As Boolean
Dim offsetX As Single, offsetY As Single
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnDragging Then
Picture1.Move X - offsetX, Y - offsetY
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnDragging = False
ReleaseCapture
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
blnDragging = True
SetCapture Me.hwnd
offsetX = X
offsetY = Y
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Dim i As Integer'定义循环变量
Dim j As Integer
Dim step As Integer
Dim x(8) As Integer'定义一个数组,用来存放随机编号
Private Sub Command1_Click()�
init'初始化游戏
Command1.Enabled = False'使开始按钮失效
End Sub
Private Sub Form_Load()�
Randomize'起始随机数产生器
End Sub
Sub init()'初始化游戏子程序
For i = 0 To 7'随机产生不重复的8个编号(从0到7)
a0: x(i)=Int(Rnd*8)
For j = 0 To i - 1
If x(i)=x(j) Then GoTo a0
Next
Next
For i = 0 To 7
Image1(i).Enabled = True'使Image1响应鼠标事件
Image1(x(i)).Picture = PictureClip1.GraphicCell(i)'让图片的8个单元分别赋予 8个Image控件
Next
Image1(8).Picture = LoadPicture(“”)'空位用于移动图片
End Sub
Private Sub Image1_Click(Index As Integer)'注意索引值的运用
Select Case Index Mod 3'把9个Image控件分成三列
Case 0'当鼠标点击第1列时
If Image1(Index + 1).Picture = LoadPicture(“”) Then'判断右边是否为空
Image1(Index + 1).Picture = Image1(Index).Picture'交换图片
Image1(Index).Picture=LoadPicture(“”)win'测试是否拼图成功
End If
Case 1'当鼠标点击第2列时
If Image1(Index - 1).Picture = LoadPicture(“”)Then'判断左边是否为空
Image1(Index - 1).Picture = Image1(Index).Picture
Image1(Index).Picture=LoadPicture(“”)
win
End If
If Image1(Index + 1).Picture = LoadPicture(“”)Then'判断右边是否为空
Image1(Index + 1).Picture = Image1(Index).Picture
Image1(Index).Picture=LoadPicture(“”)
win
End If
Case 2'当鼠标点击第3列时
If Image1(Index - 1).Picture = LoadPicture(“”)Then'判断左边是否为空
Image1(Index - 1).Picture = Image1(Index).Picture
Image1(Index).Picture=LoadPicture(“”)
win
End If
End Select
Select Case Index\ 3'把9个Image控件分成三行
Case 0'当鼠标点击第1行时
If Image1(Index + 3).Picture = LoadPicture(“”)Then'判断下边是否为空
Image1(Index + 3).Picture = Image1(Index).Picture
Image1(Index).Picture=LoadPicture(“”)
win
End If
Case 1'当鼠标点击第2行时
If Image1(Index - 3).Picture = LoadPicture(“”)Then'判断上边是否为空
Image1(Index - 3).Picture = Image1(Index).Picture
Image1(Index).Picture=LoadPicture(“”)
win
End If
If Image1(Index + 3).Picture = LoadPicture(“”)Then'判断下边是否为空
Image1(Index + 3).Picture = Image1(Index).Picture
Image1(Index).Picture=LoadPicture(“”)
win
End If
Case 2'当鼠标点击第3行时
If Image1(Index - 3).Picture = LoadPicture(“”)Then'判断上边是否为空
Image1(Index - 3).Picture = Image1(Index).Picture
Image1(Index).Picture=LoadPicture(“”)
win
End If
End Select
End Sub
Sub win()'测试是否拼图成功的子程序
Dim num As Integer
step=step + 1'步数加1
Label2.Caption= step
For i = 0 To 8'判断图块是否全部就位
If Image1(i).Picture= PictureClip1.GraphicCell(i) Then num = num + 1
Next
If num ?=8 Then
MsgBox “你真棒!”
For i=0 To 8
Image1 (i).Enabled=False'使之不响应鼠标事件
Next
Command1.Enabled=True'恢复命令按钮
End If
End Sub
Dim i As Integer'定义循环变量
Dim j As Integer
Dim step As Integer
Dim x(8) As Integer'定义一个数组,用来存放随机编号
Private Sub Command1_Click()�
init'初始化游戏
Command1.Enabled = False'使开始按钮失效
End Sub
Private Sub Form_Load()�
Randomize'起始随机数产生器
End Sub
Sub init()'初始化游戏子程序
For i = 0 To 7'随机产生不重复的8个编号(从0到7)
a0: x(i)=Int(Rnd*8)
For j = 0 To i - 1
If x(i)=x(j) Then GoTo a0
Next
Next
For i = 0 To 7
Image1(i).Enabled = True'使Image1响应鼠标事件
Image1(x(i)).Picture = PictureClip1.GraphicCell(i)'让图片的8个单元分别赋予 8个Image控件
Next
Image1(8).Picture = LoadPicture(“”)'空位用于移动图片
End Sub
Private Sub Image1_Click(Index As Integer)'注意索引值的运用
Select Case Index Mod 3'把9个Image控件分成三列
Case 0'当鼠标点击第1列时
If Image1(Index + 1).Picture = LoadPicture(“”) Then'判断右边是否为空
Image1(Index + 1).Picture = Image1(Index).Picture'交换图片
Image1(Index).Picture=LoadPicture(“”)win'测试是否拼图成功
End If
Case 1'当鼠标点击第2列时
If Image1(Index - 1).Picture = LoadPicture(“”)Then'判断左边是否为空
Image1(Index - 1).Picture = Image1(Index).Picture
Image1(Index).Picture=LoadPicture(“”)
win
End If
If Image1(Index + 1).Picture = LoadPicture(“”)Then'判断右边是否为空
Image1(Index + 1).Picture = Image1(Index).Picture
Image1(Index).Picture=LoadPicture(“”)
win
End If
Case 2'当鼠标点击第3列时
If Image1(Index - 1).Picture = LoadPicture(“”)Then'判断左边是否为空
Image1(Index - 1).Picture = Image1(Index).Picture
Image1(Index).Picture=LoadPicture(“”)
win
End If
End Select
Select Case Index\ 3'把9个Image控件分成三行
Case 0'当鼠标点击第1行时
If Image1(Index + 3).Picture = LoadPicture(“”)Then'判断下边是否为空
Image1(Index + 3).Picture = Image1(Index).Picture
Image1(Index).Picture=LoadPicture(“”)
win
End If
Case 1'当鼠标点击第2行时
If Image1(Index - 3).Picture = LoadPicture(“”)Then'判断上边是否为空
Image1(Index - 3).Picture = Image1(Index).Picture
Image1(Index).Picture=LoadPicture(“”)
win
End If
If Image1(Index + 3).Picture = LoadPicture(“”)Then'判断下边是否为空
Image1(Index + 3).Picture = Image1(Index).Picture
Image1(Index).Picture=LoadPicture(“”)
win
End If
Case 2'当鼠标点击第3行时
If Image1(Index - 3).Picture = LoadPicture(“”)Then'判断上边是否为空
Image1(Index - 3).Picture = Image1(Index).Picture
Image1(Index).Picture=LoadPicture(“”)
win
End If
End Select
End Sub
Sub win()'测试是否拼图成功的子程序
Dim num As Integer
step=step + 1'步数加1
Label2.Caption= step
For i = 0 To 8'判断图块是否全部就位
If Image1(i).Picture= PictureClip1.GraphicCell(i) Then num = num + 1
Next
If num ?=8 Then
MsgBox “你真棒!”
For i=0 To 8
Image1 (i).Enabled=False'使之不响应鼠标事件
Next
Command1.Enabled=True'恢复命令按钮
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询