利用vb作一个拼图小程序,请问高手
1、图片的切割(语法)
2、图片使用的控件和移动图片的算法
如有例子请给我一个,我这里谢谢了
也可告知算法
1、图片的切割(语法)
2、图片使用的控件和移动图片的算法
如有例子请给我一个,我这里谢谢了
也可告知算法
解决方案 »
- VB又出怪问题了,不知道是他疯还是我疯。。。
- vb 用net use 访问网络共享文件夹
- 有没有什么方法或工具单独测试VB函数或过程?
- 为什么VB的IDE,老是会出现运行一段时间,无故退出?请了解这个问题的朋友帮忙!
- 如何将图片的一部分扩大
- 无锡KEC招聘员工(vb程序员,美工设计人员,网管,硬件维护人员各一名)!!!
- 撒分~!!!(版主给个面子不要删除行不?!:))
- 如何用listview控件显示数据库的内容?急!!
- 500元求购VB读取地磅源码
- 如何用winsock提交多条记录?如:姓名,性别,地址,接收到后又把他们分开,好像可以用数组来提交,但我搞不清楚。。
- 怎样获知目前的光标是在第二个Txtfields(2)中?
- 数据运算问题
一样的,用paintpicture,stretchblt API都可以
窗体上加两个PictureBox(ScaleMode=3,AutoRedraw=True,Picture2用于选图片,用户在Picture1上操作),一个Command。Option ExplicitPrivate Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function DrawEdge Lib "user32" (ByVal hdc As Long, qrc As RECT, ByVal edge As Long, ByVal grfFlags As Long) As Long
Private Const SRCCOPY = &HCC0020Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypePrivate arr(15) As Integer
Private prevX As Integer
Private prevY As IntegerPrivate Sub Init()
Dim i As Integer
Dim tmp As Integer
Dim tmpValue As Integer
For i = 0 To 14
arr(i) = i
Next i
arr(15) = -1
Randomize Timer
For i = 0 To 14
tmp = Int(Rnd() * 15)
If tmp <> 12 And i <> 12 Then
tmpValue = arr(tmp)
arr(tmp) = arr(i)
arr(i) = tmpValue
End If
Next i
prevX = 5
prevY = 0
End SubPrivate Sub DrawBlocks()
Dim i As Integer
Dim hBrush As Long
Dim rc As RECT
For i = 0 To 15
rc.Left = Int(i / 3) * 40
rc.Right = rc.Left + 40
rc.Top = (i Mod 3) * 40
rc.Bottom = rc.Top + 40
If arr(i) >= 0 Then
BitBlt Picture1.hdc, rc.Left, rc.Top, 40, 40, Picture2.hdc, Int(arr(i) / 3) * 40, (arr(i) Mod 3) * 40, SRCCOPY
DrawEdge Picture1.hdc, rc, 4, 15
Else
hBrush = CreateSolidBrush(RGB(255, 255, 255))
FillRect Picture1.hdc, rc, hBrush
End If
Next i
Picture1.Refresh
End SubPrivate Sub MoveBlock(Index As Integer)
Const MOVETO_LEFT = 1
Const MOVETO_RIGHT = 2
Const MOVETO_TOP = 3
Const MOVETO_BOTTOM = 4
Dim intMoveTo As Integer
Select Case Index
Case 0
If arr(1) = -1 Then intMoveTo = MOVETO_BOTTOM
If arr(3) = -1 Then intMoveTo = MOVETO_RIGHT
Case 1
If arr(0) = -1 Then intMoveTo = MOVETO_TOP
If arr(2) = -1 Then intMoveTo = MOVETO_BOTTOM
If arr(4) = -1 Then intMoveTo = MOVETO_RIGHT
Case 2
If arr(1) = -1 Then intMoveTo = MOVETO_TOP
If arr(5) = -1 Then intMoveTo = MOVETO_RIGHT
Case 13
If arr(12) = -1 Then intMoveTo = MOVETO_TOP
If arr(14) = -1 Then intMoveTo = MOVETO_BOTTOM
If arr(10) = -1 Then intMoveTo = MOVETO_LEFT
Case 14
If arr(13) = -1 Then intMoveTo = MOVETO_TOP
If arr(11) = -1 Then intMoveTo = MOVETO_LEFT
Case 15
If arr(12) = -1 Then intMoveTo = MOVETO_LEFT
Case 3, 6, 9, 12
If arr(Index - 3) = -1 Then intMoveTo = MOVETO_LEFT
If arr(Index + 3) = -1 Then intMoveTo = MOVETO_RIGHT
If arr(Index + 1) = -1 Then intMoveTo = MOVETO_BOTTOM
Case 4, 7, 10
If arr(Index - 3) = -1 Then intMoveTo = MOVETO_LEFT
If arr(Index + 3) = -1 Then intMoveTo = MOVETO_RIGHT
If arr(Index - 1) = -1 Then intMoveTo = MOVETO_TOP
If arr(Index + 1) = -1 Then intMoveTo = MOVETO_BOTTOM
Case 5, 8, 11
If arr(Index - 3) = -1 Then intMoveTo = MOVETO_LEFT
If arr(Index + 3) = -1 Then intMoveTo = MOVETO_RIGHT
If arr(Index - 1) = -1 Then intMoveTo = MOVETO_TOP
End Select
Select Case intMoveTo
Case MOVETO_LEFT
arr(Index - 3) = arr(Index)
arr(Index) = -1
Case MOVETO_RIGHT
arr(Index + 3) = arr(Index)
arr(Index) = -1
Case MOVETO_TOP
arr(Index - 1) = arr(Index)
arr(Index) = -1
Case MOVETO_BOTTOM
arr(Index + 1) = arr(Index)
arr(Index) = -1
Case Else
Exit Sub
End Select
End SubPrivate Sub Command1_Click()
Call Init
Call DrawBlocks
End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Integer
Dim blnGameOver As Boolean
Dim ClickedX As Integer
Dim ClickedY As Integer
ClickedX = Int(X / 40)
ClickedY = Int(Y / 40)
If ClickedX = prevX And ClickedY <> prevY Then
If ClickedY > prevY Then
For i = prevY + 1 To ClickedY
Call MoveBlock(ClickedX * 3 + i)
Next i
Else
For i = prevY - 1 To ClickedY Step -1
Call MoveBlock(ClickedX * 3 + i)
Next i
End If
ElseIf ClickedX <> prevX And ClickedY = prevY Then
If ClickedX > prevX Then
For i = prevX + 1 To ClickedX
Call MoveBlock(i * 3 + ClickedY)
Next i
Else
For i = prevX - 1 To ClickedX Step -1
Call MoveBlock(i * 3 + ClickedY)
Next i
End If
Else
Call MoveBlock(ClickedX * 3 + ClickedY)
End If
Call DrawBlocks
prevX = ClickedX
prevY = ClickedY
blnGameOver = True
For i = 0 To 14
If arr(i) <> i Then
blnGameOver = False
Exit For
End If
Next i
If blnGameOver Then
MsgBox "Game Over!"
End If
End Sub