1、《VB制作拼图游戏:简单算法》 1、首先按照截图把控件添加好! (技巧:PS处理322*322的图片,划分切块,形成九个小图片,这里采用的是Jpg格式,然后采用Command按钮来显示这些图片,同学们也可以采用Label,是一样的,重点是鼠标单击事件!注意:添加九个Command按钮,一定要设置每个按钮的Height、Width、Top、Left值来完成对图片的吻合拼接,这样可以使界面看起来美观大方!) 2、界面的设计 这里很多同学习惯更改Command的Caption值来显示某些文本,但要注意,你这里很可能为了美观会使用自己机子上单独安装的某些字体,这些字体拿到其
2、他机子上是不生效的,那么怎么办呢?这里有个比较“笨拙的方法”——你可以利用Word工具打好想要显示的文本,设置个性字体,然后截图,插入到Command上面,这样的话,无论是什么字体,都可以显示了,因为图片的属性是无法更改的!这个方法同样可以用来美化Label!当然了,自己究竟怎么样设计,就靠想象力了,最终得到的效果是要有一个美观、简洁大方的界面! 3、算法设计(全部代码) Dim Num As Integer Private Sub Command1_Click() If Command2.Picture = Command11.Picture Then Command2.Pic
3、ture = Command1.Picture Command1.Picture = Command11.Picture End If If Command4.Picture = Command11.Picture Then Command4.Picture = Command1.Picture Command1.Picture = Command11.Picture End If End Sub Private Sub Command11_Click() MsgBox ("开发者:孔世明" & vbCrLf & "学院:信息科学与技术学院" & vbCrLf & "专业
4、软件工程" & vbCrLf & "班级:软件一班" & vbCrLf & "学号:201213040117") End Sub Private Sub Command12_Click() Num = Num + 1 If Num = 1 Then Command9.Picture = Command11.Picture End If If Num = 2 Then MsgBox ("亲~~不能重复开始哦!~") End If If Num = 3 Then MsgBox ("亲~~再说一次,不能重复开始!!") End If If Num > 3 Then
5、MsgBox ("请不要放弃治疗!!!") End If End Sub Private Sub Command2_Click() If Command1.Picture = Command11.Picture Then Command1.Picture = Command2.Picture Command2.Picture = Command11.Picture End If If Command3.Picture = Command11.Picture Then Command3.Picture = Command2.Picture Command2.Picture
6、 = Command11.Picture End If If Command5.Picture = Command11.Picture Then Command5.Picture = Command2.Picture Command2.Picture = Command11.Picture End If End Sub Private Sub Command3_Click() If Command2.Picture = Command11.Picture Then Command2.Picture = Command3.Picture Command3.Picture
7、 Command11.Picture End If If Command6.Picture = Command11.Picture Then Command6.Picture = Command3.Picture Command3.Picture = Command11.Picture End If End Sub Private Sub Command4_Click() If Command1.Picture = Command11.Picture Then Command1.Picture = Command4.Picture Command4.Picture =
8、 Command11.Picture End If If Command5.Picture = Command11.Picture Then Command5.Picture = Command4.Picture Command4.Picture = Command11.Picture End If If Command7.Picture = Command11.Picture Then Command7.Picture = Command4.Picture Command4.Picture = Command11.Picture End If End Sub Pri
9、vate Sub Command5_Click() If Command2.Picture = Command11.Picture Then Command2.Picture = Command5.Picture Command5.Picture = Command11.Picture End If If Command4.Picture = Command11.Picture Then Command4.Picture = Command5.Picture Command5.Picture = Command11.Picture End If If Command6.Pic
10、ture = Command11.Picture Then Command6.Picture = Command5.Picture Command5.Picture = Command11.Picture End If If Command8.Picture = Command11.Picture Then Command8.Picture = Command5.Picture Command5.Picture = Command11.Picture End If End Sub Private Sub Command6_Click() If Command3.Pict
11、ure = Command11.Picture Then Command3.Picture = Command6.Picture Command6.Picture = Command11.Picture End If If Command5.Picture = Command11.Picture Then Command5.Picture = Command6.Picture Command6.Picture = Command11.Picture End If If Command9.Picture = Command11.Picture Then Command9.Pic
12、ture = Command6.Picture Command6.Picture = Command11.Picture End If End Sub Private Sub Command7_Click() If Command4.Picture = Command11.Picture Then Command4.Picture = Command7.Picture Command7.Picture = Command11.Picture End If If Command8.Picture = Command11.Picture Then Command8.Pict
13、ure = Command7.Picture Command7.Picture = Command11.Picture End If End Sub Private Sub Command8_Click() If Command5.Picture = Command11.Picture Then Command5.Picture = Command8.Picture Command8.Picture = Command11.Picture End If If Command7.Picture = Command11.Picture Then Command7.Pictu
14、re = Command8.Picture Command8.Picture = Command11.Picture End If If Command9.Picture = Command11.Picture Then Command9.Picture = Command8.Picture Command8.Picture = Command11.Picture End If End Sub Private Sub Command9_Click() If Command6.Picture = Command11.Picture Then Command6.Pictur
15、e = Command9.Picture Command9.Picture = Command11.Picture End If If Command8.Picture = Command11.Picture Then Command8.Picture = Command9.Picture Command9.Picture = Command11.Picture End If End Sub 【应该看得出来,这里的算法只有一个:判断某个按钮相邻的Command显示图片是否为“空白”,若是,则交换图片显示,但要注意,这里还要引入第三个Command当做“中转站”,这其实和C++里面交换某两个变量的值是一个道理,如果没有这个媒介,那么图片交换两次,最终会没有变化。】






