您好,欢迎光临本网站![请登录][注册会员]  
文件名称: VB版数字排序拼图小游戏
  所属分类: VB
  开发工具:
  文件大小: 13kb
  下载次数: 0
  上传时间: 2010-12-14
  提 供 者: migge******
 详细说明: VB版数字排序拼图小游戏 Option Explicit Dim Label2X As Integer '记录标签控件数组中要移动的标签控件左上角X的位置 Dim Label2Y As Integer '记录标签控件数组中要移动的标签控件左上角Y的位置 '让标签数组中的每个标签控件上显示的数字是随机的,无重复的 Private Sub Init() Randomize Dim a(7) As Integer Dim i As Integer, k As Integer Label1.Caption = "" For i = 0 To 7 a(i) = i Next For i = 0 To 7 k = Int(Rnd * 8) Do While a(k) = -1 'a(k)=-1表示该数组元素对应的数字已经被使用过了 k = Int(Rnd * 8) '重新生成k的值,直到a(k)的值不等于-1 Loop Label2(i).Caption = Trim(Str (a(k))) a(k) = -1 'a(k)的值已经使用了,不能再用,重新赋值为-1与其他的元素值相区别 Next i End Sub Private Sub cb_Click() MsgBox "欢迎观临 陈彬 020901033" End Sub Private Sub Command1_Click() Dim x As Integer, y As Integer Dim z As Integer Init Picture1.Enabled = True '让空白标签Label1出现的位置随机 Randomize '记录下空白标签Label1的位置 x = Label1.Left y = Label1.Top z = Int(Rnd * 8) '将空白标签Label1和标签控件数组任一控件交换位置 Label1.Move Label2(z).Left, Label2(z).Top Label2(z).Move x, y Command1.Enabled = False End Sub Private Sub Command2_Click() End End Sub Private Sub Form_Load() Dim i As Integer Picture1.Enabled = False '在标签中显示游戏说明信息 Label3.Caption = "如左图所示,将数字按0-7顺" & vbCrLf & vbCrLf & "序依次排列,即取得胜利。" '在标签中显示排列规则后的数字顺序 Label1.Caption = 0 For i = 0 To 6 Label2(i).Caption = i + 1 Next End Sub Private Sub Label1_DragDrop(Source As Control, x As Single, y As Single) Dim Label1X As Integer '记录空白控件Label1左上角X的位置 Dim Label1Y As Integer '记录空白控件Label1左上角Y的位置 Dim flag(3) As Boolean '获取空白控件Label1的位置 Label1X = Label1.Left Label1Y = Label1.Top '要移动的控件位于空白控件Label1的正左侧 flag(0) = (Label2X = Label1X - Source.Width) And (Label2Y = Label1Y) '要移动的控件位于空白控件Label1的正右侧 flag(1) = (Label2X = Label1X + Source.Width) And (Label2Y = Label1Y) '要移动的控件位于空白控件Label1的正上方 flag(2) = (Label2X = Label1X) And (Label2Y = Label1Y - Source.Height) '要移动的控件位于空白控件Label1的正下方 flag(3) = (Label2X = Label1X) And (Label2Y = Label1Y + Source.Height) If flag(0) Or flag(1) Or flag(2) Or flag(3) Then Label1.Move Label2X, Label2Y Source.Move Label1X, Label1Y End If Win End Sub Private Sub Label2_MouseDown(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single) If Button = vbLeftButton Then '如果按下鼠标左键 '记录下要拖动控件的位置 Label2X = Label2(Index).Left Label2Y = Label2(Index).Top Label2(Index).Drag 1 '启动拖动操作 End If End Sub Private Sub Label2_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single) Label2(Index).Drag 2 '结束拖动操作 End Sub Private Sub Win() Dim winner As Integer Dim i As Integer Dim answer As Integer '对于给定的标签控件数组中的任一标签控件,可以落在符合要求(对应位置应显示对应数字) '的八个位置中的任一位置 '利用循环语句对标签控件数组中的每个标签控件进行检查,如果其落在某一符号要求的位置, '则变量winner的值加1,如果所有标签控件都落在符号要求的位置,则变量winner的值应为8 For i = 0 To 7 If Label2(i).Left = 0 And Label2(i).Top = 0 And _ Label2(i).Caption = 0 Then winner = winner + 1 ElseIf Label2(i).Left = Label2(i).Width And Label2(i).Top = 0 And _ Label2(i).Caption = 1 Then winner = winner + 1 ElseIf Label2(i).Left = 2 * Label2(i).Width And Label2(i).Top = 0 And _ Label2(i).Caption = 2 Then winner = winner + 1 ElseIf Label2(i).Left = 0 And Label2(i).Top = Label2(i).Height And _ Label2(i).Caption = 3 Then winner = winner + 1 ElseIf Label2(i).Left = Label2(i).Width And Label2(i).Top = Label2(i).Height And _ Label2(i).Caption = 4 Then winner = winner + 1 ElseIf Label2(i).Left = 2 * Label2(i).Width And Label2(i).Top = Label2(i).Height And _ Label2(i).Caption = 5 Then winner = winner + 1 ElseIf Label2(i).Left = 0 And Label2(i).Top = 2 * Label2(i).Height And _ Label2(i).Caption = 6 Then winner = winner + 1 ElseIf Label2(i).Left = Label2(i).Width And Label2(i).Top = 2 * Label2(i).Height And _ Label2(i).Caption = 7 Then winner = winner + 1 End If Next i If winner = 8 Then MsgBox " 恭喜您,胜利了!", 0 + 64 + 0, "提示" Picture1.Enabled = False answer = MsgBox("还继续吗?", 4 + 32 + 0, "提示") If answer = vbYes Then Command1.Enabled = True Else End End If End If End Sub ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 输入关键字,在本站1000多万海量源码库中尽情搜索: