【#第一文档网# 导语】以下是®第一文档网的小编为您整理的《拼图游戏源代码》,欢迎阅读!
Option Explicit Dim imageid(8) As Integer '记录图片排列的顺序的数组 Dim position As Integer '被点击的图片位置 Dim xposition As Integer '空图片的位置 Dim movetimes As Integer '记录移动次数 Dim calposition As Integer '用于计算位置 Dim started As Boolean '是否开始 Dim win As Boolean '是否胜利 Dim pic(9) As Picture '存储图像的数组对象 Dim pic1 As Picture Private Sub Command1_Click() Dim i As Integer Dim temp(8) As Integer Dim chosennumber As Integer For i = 0 To 7 temp(i) = i Next Randomize For i = 7 To 0 Step -1 chosennumber = Int(i * Rnd) imageid(7 - i) = temp(chosennumber) temp(chosennumber) = temp(i) Next For i = 0 To 7 Picture1(i).Picture = pic(imageid(i)) Next Picture1(9).Picture = pic(8) Picture1(8).Picture = pic(9) xposition = 8 started = True movetimes = 0 End Sub Private Sub Form_Load() Dim i As Integer For i = 0 To 8 Set pic(i) = Picture1(i).Picture Next End Sub Private Sub Picture1_Click(Index As Integer) Dim i As Integer Dim response As Integer position = Index If started = False Then Exit Sub End If If (position <> 0) And (position <> 3) And (position <> 6) Then calposition = position - 1 If calposition = xposition Then cvale End If End If If (position <> 2) And (position <> 5) And (position <> 9) Then calposition = position + 1 If calposition = xposition Then cvale End If End If Text1.Text = Str(position) If position <= 5 Then calposition = position + 3 Text2.Text = Str(calposition) If calposition = xposition Then cvale End If End If If position >= 3 And position <> 9 Then calposition = position - 3 If calposition = xposition Then cvale End If End If win = True For i = 0 To 7 If imageid(i) <> i Then win = False Exit For End If Next If win = True Then MsgBox "恭喜恭喜!您很聪明" & "共移动" & vbCrLf & movetimes & "次", vbOKOnly started = False End If End Sub Private Sub cvale() Set pic1 = Picture1(position).Picture 本文来源:https://www.dywdw.cn/6a368f2a453610661ed9f41c.html