用VB制作拼图游戏,求代码
功能要求(1)单击“分割图片”按钮,可以将原始图片等分为六部分(注:水平方向三等分,垂直方向二等分),并将图片分割后的每一小部分随机放入界面下半部分的六个小图片框中,如图...
功能要求
(1)单击“分割图片”按钮,可以将原始图片等分为六部分(注:水平方向三等分,垂直方向二等分),并将图片分割后的每一小部分随机放入界面下半部分的六个小图片框中,如图3-2所示。(注意:应保证每次分割的图像块随机显示在小图片框中)。
(2)按住鼠标左键拖动每个小图片框至“拼接后的图片”框中。当小图片框到达合适的位置(注意:位置由框中直线划分出的区域决定)后释放鼠标,小图片框能自动放置在指定的区域中。图3-3为拼接了四部分之后,正在拖动第五部分的示意图;图3-4为拼接完成后的用户界面示意图。
(3)单击“还原”按钮后,恢复为图3-1所示的初始界面。
如需要示意图片请加495595997
麻烦各位了 展开
(1)单击“分割图片”按钮,可以将原始图片等分为六部分(注:水平方向三等分,垂直方向二等分),并将图片分割后的每一小部分随机放入界面下半部分的六个小图片框中,如图3-2所示。(注意:应保证每次分割的图像块随机显示在小图片框中)。
(2)按住鼠标左键拖动每个小图片框至“拼接后的图片”框中。当小图片框到达合适的位置(注意:位置由框中直线划分出的区域决定)后释放鼠标,小图片框能自动放置在指定的区域中。图3-3为拼接了四部分之后,正在拖动第五部分的示意图;图3-4为拼接完成后的用户界面示意图。
(3)单击“还原”按钮后,恢复为图3-1所示的初始界面。
如需要示意图片请加495595997
麻烦各位了 展开
2个回答
展开全部
Dim a(0 To 5) As Integer
Private Sub crearnd() '随机分配分割后的图片
Randomize
For i = 0 To 5
a(i) = Int(Rnd * 6)
If i >= 2 Then
For j = 0 To i - 1
If a(j) = a(i) Then
i = i - 1
End If
Next
End If
Next
End Sub
Private Sub Form_Load()
For i = 0 To 5
Picture2(i).Width = Picture1.Width / 3
Picture2(i).Height = Picture1.Height / 2
Next i
End Sub
Private Sub spi_CLICK()
crearnd
Picture2(a(0)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(1)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(2)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, 2 * Picture1.ScaleWidth / 3, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(3)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, 0, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(4)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(5)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, 2 * Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(0).Move Picture1.Width, 0
Picture2(1).Left = Picture1.Width + Picture2(0).Width: Picture2(1).Top = 0
Picture2(2).Left = Picture1.Width + Picture2(0).Width + Picture2(1).Width: Picture2(2).Top = 0
Picture2(3).Left = Picture1.Width: Picture2(3).Top = Picture2(0).Height
Picture2(4).Left = Picture1.Width + Picture2(3).Width: Picture2(4).Top = Picture2(1).Height
Picture2(5).Left = Picture1.Width + Picture2(3).Width + Picture2(4).Width: Picture2(5).Top = Picture2(2).Height
End Sub
Private Sub Picture2_DragDrop(index As Integer, Source As Control, X As Single, Y As Single)
Dim PIC As StdPicture
Set PIC = Source.Image
Set Source.Picture = Picture2(index).Image
Set Picture2(index).Picture = PIC
End Sub
在窗体上建立一个picture1和一个picture2(index)控件数组,总共包含6个图片框,然后给所有的图片框的autoredraw属性设置为true,就ok了,费了我好的劲,有问题再给我说
至于你要求的界面,我没看见你的图啊
已经发送,请查收
Private Sub crearnd() '随机分配分割后的图片
Randomize
For i = 0 To 5
a(i) = Int(Rnd * 6)
If i >= 2 Then
For j = 0 To i - 1
If a(j) = a(i) Then
i = i - 1
End If
Next
End If
Next
End Sub
Private Sub Form_Load()
For i = 0 To 5
Picture2(i).Width = Picture1.Width / 3
Picture2(i).Height = Picture1.Height / 2
Next i
End Sub
Private Sub spi_CLICK()
crearnd
Picture2(a(0)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(1)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(2)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, 2 * Picture1.ScaleWidth / 3, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(3)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, 0, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(4)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(5)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, 2 * Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(0).Move Picture1.Width, 0
Picture2(1).Left = Picture1.Width + Picture2(0).Width: Picture2(1).Top = 0
Picture2(2).Left = Picture1.Width + Picture2(0).Width + Picture2(1).Width: Picture2(2).Top = 0
Picture2(3).Left = Picture1.Width: Picture2(3).Top = Picture2(0).Height
Picture2(4).Left = Picture1.Width + Picture2(3).Width: Picture2(4).Top = Picture2(1).Height
Picture2(5).Left = Picture1.Width + Picture2(3).Width + Picture2(4).Width: Picture2(5).Top = Picture2(2).Height
End Sub
Private Sub Picture2_DragDrop(index As Integer, Source As Control, X As Single, Y As Single)
Dim PIC As StdPicture
Set PIC = Source.Image
Set Source.Picture = Picture2(index).Image
Set Picture2(index).Picture = PIC
End Sub
在窗体上建立一个picture1和一个picture2(index)控件数组,总共包含6个图片框,然后给所有的图片框的autoredraw属性设置为true,就ok了,费了我好的劲,有问题再给我说
至于你要求的界面,我没看见你的图啊
已经发送,请查收
更多追问追答
追问
请问都需要什么控件呢?
追答
你发个邮箱,我把源文件给你发过来,你看看就知道了,用到的控件很多啊
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不懂·
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询