vb拼图游戏的代码和做法。万分感谢啊!!!!
1个回答
展开全部
刚好做过
Dim i, j, Moves As Integer
Dim filename, pic, temp, Line_text, m As String
Private Sub Form_Load()
'把TilePuzzle控件的起始位置设置成与Image控件相同
TilePuzzle1.Top = Image1.Top
TilePuzzle1.Left = Image1.Left
'把Image控件的图片赋给TilePuzzle1
Set TilePuzzle1.Picture = Image1.Picture
i = 2
j = 2
End Sub
'游戏开始菜单单击事件
Private Sub p1_Click()
Set TilePuzzle1.Picture = Image1.Picture
TilePuzzle1.Cols = i
TilePuzzle1.Rows = j
i = TilePuzzle1.Cols
j = TilePuzzle1.Rows
Image1.Visible = False
TilePuzzle1.Randomize
TilePuzzle1.Visible = True
p1.Caption = "重新开始"
End Sub
'图像加载菜单单击事件
Private Sub p2_Click()
CommonDialog1.Filter = "Jpg(*.jpg)|*.jpg|Gif(*.gif)|*.gif"
CommonDialog1.ShowOpen
pic = CommonDialog1.filename
If pic <> "" Then
Image1.Picture = LoadPicture(pic)
TilePuzzle1.Visible = False
Image1.Visible = True
i = 2
j = 2
Me.Caption = "拼图游戏"
End If
End Sub
'初级菜单单击事件
Private Sub p30_Click()
i = 2
j = 2
p30.Checked = True
p31.Checked = False
p32.Checked = False
End Sub
'中级菜单单击事件
Private Sub p31_Click()
i = 3
j = 3
p30.Checked = False
p31.Checked = True
p32.Checked = False
End Sub
'高级菜单单击事件
Private Sub p32_Click()
i = 4
j = 4
p30.Checked = False
p31.Checked = False
p32.Checked = True
End Sub
Private Sub p4_Click()
End
End Sub
Private Sub TilePuzzle1_Moved()
Moves = Moves + 1
'设置窗体标题
Me.Caption = "拼图游戏 共走" + Format$(Moves) + "步"
End Sub
Private Sub TilePuzzle1_Solved()
If i = 2 Then '玩的是初级游戏
p31.Checked = True
p30.Checked = False
p32.Checked = False
End If
If i = 3 Then '玩的是中级游戏
p31.Checked = False
p30.Checked = False
p32.Checked = True
End If
Moves = 0 '清零游戏步数
Me.Caption = "拼图游戏 " '自动进行下一等级游戏
TilePuzzle1.Cols = i + 1
TilePuzzle1.Rows = j + 1
i = TilePuzzle1.Cols
j = TilePuzzle1.Rows
TilePuzzle1.Randomize 'TilePuzzle1块随即分布
End Sub
Dim i, j, Moves As Integer
Dim filename, pic, temp, Line_text, m As String
Private Sub Form_Load()
'把TilePuzzle控件的起始位置设置成与Image控件相同
TilePuzzle1.Top = Image1.Top
TilePuzzle1.Left = Image1.Left
'把Image控件的图片赋给TilePuzzle1
Set TilePuzzle1.Picture = Image1.Picture
i = 2
j = 2
End Sub
'游戏开始菜单单击事件
Private Sub p1_Click()
Set TilePuzzle1.Picture = Image1.Picture
TilePuzzle1.Cols = i
TilePuzzle1.Rows = j
i = TilePuzzle1.Cols
j = TilePuzzle1.Rows
Image1.Visible = False
TilePuzzle1.Randomize
TilePuzzle1.Visible = True
p1.Caption = "重新开始"
End Sub
'图像加载菜单单击事件
Private Sub p2_Click()
CommonDialog1.Filter = "Jpg(*.jpg)|*.jpg|Gif(*.gif)|*.gif"
CommonDialog1.ShowOpen
pic = CommonDialog1.filename
If pic <> "" Then
Image1.Picture = LoadPicture(pic)
TilePuzzle1.Visible = False
Image1.Visible = True
i = 2
j = 2
Me.Caption = "拼图游戏"
End If
End Sub
'初级菜单单击事件
Private Sub p30_Click()
i = 2
j = 2
p30.Checked = True
p31.Checked = False
p32.Checked = False
End Sub
'中级菜单单击事件
Private Sub p31_Click()
i = 3
j = 3
p30.Checked = False
p31.Checked = True
p32.Checked = False
End Sub
'高级菜单单击事件
Private Sub p32_Click()
i = 4
j = 4
p30.Checked = False
p31.Checked = False
p32.Checked = True
End Sub
Private Sub p4_Click()
End
End Sub
Private Sub TilePuzzle1_Moved()
Moves = Moves + 1
'设置窗体标题
Me.Caption = "拼图游戏 共走" + Format$(Moves) + "步"
End Sub
Private Sub TilePuzzle1_Solved()
If i = 2 Then '玩的是初级游戏
p31.Checked = True
p30.Checked = False
p32.Checked = False
End If
If i = 3 Then '玩的是中级游戏
p31.Checked = False
p30.Checked = False
p32.Checked = True
End If
Moves = 0 '清零游戏步数
Me.Caption = "拼图游戏 " '自动进行下一等级游戏
TilePuzzle1.Cols = i + 1
TilePuzzle1.Rows = j + 1
i = TilePuzzle1.Cols
j = TilePuzzle1.Rows
TilePuzzle1.Randomize 'TilePuzzle1块随即分布
End Sub
追问
怎么有些控件,我都没有学过啊。在哪添加啊?
追答
抱歉,tilepuzzle是ocx控件,用户控件。。就是就是整合了9个Image的一个控件了,只是多了两个属性
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询