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