拼图游戏源代码

2023-10-02 10:56:24   第一文档网     [ 字体: ] [ 阅读: ] [ 文档下载 ]
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。下载word有问题请添加QQ:admin处理,感谢您的支持与谅解。点击这里给我发消息

#第一文档网# 导语】以下是®第一文档网的小编为您整理的《拼图游戏源代码》,欢迎阅读!
拼图,源代码,游戏



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

相关推荐
推荐阅读