Idea básica para armar un programa de este tipo.
Observalo en youtube:
' gambas class file
Public Cantidad_Sprites As Picture[]
Public XpictureBox As PictureBox
Public TagOrdenado As String[]
Public Repeticiones As Integer = 200
Public Intentos As Integer
Public PICactual As Picture
Public pbActual As PictureBox
Public Sub Form_Open()
Label1.Text = "by postapase v. " & Application.Version
ReiniciarVariables()
SepararImagenes("casa.jpeg", 3, 3)
End
Public Sub SepararImagenes(path As String, filas As Integer, columnas As Integer)
'subrutina extraida y modificada del ejemplo de Julio 1945
Dim i As Image
Dim fila As Integer
Dim columna As Integer
Dim imagenAncho As Integer
Dim imagenLargo As Integer
Dim fichero As Picture
Dim contador As Integer = 1
Dim ruta As String
Dim a As Integer
i = Image.Load(path)
PictureBox1.Visible = False
PictureBox1.Picture = Picture.Load(path)
Cantidad_Sprites = New Picture[]
imagenAncho = i.w / columnas
imagenlargo = i.h / filas
For fila = 1 To filas
For columna = 1 To columnas
fichero = New Picture(imagenAncho, imagenLargo, Color.Transparent)
Paint.Begin(fichero)
Paint.DrawImage(i, 0, 0, imagenAncho, imagenLargo, 1, Rect((columna - 1) * imagenAncho, (fila - 1) * imagenLargo, imagenancho, imagenlargo))
Paint.Stroke()
Paint.Fill
Paint.End()
Wait 0.1
ruta = "/tmp/dibujo" & Str$(contador) & ".png"
fichero.Save(ruta)
Wait 0.1
Cantidad_Sprites.Add(fichero)
TagOrdenado.Add(ruta)
Select Case contador
Case 1
pb1.Tag = ruta
Case 2
pb2.Tag = ruta
Case 3
pb3.Tag = ruta
Case 4
pb4.Tag = ruta
Case 5
pb5.Tag = ruta
Case 6
pb6.Tag = ruta
Case 7
pb7.Tag = ruta
Case 8
pb8.Tag = ruta
Case 9
pb9.Tag = ruta
End Select
contador += 1
Next
Next
For a = 1 To Repeticiones
Desordenar()
Next
Refrescar2()
End
Public Sub btnOtraImagen_Click()
Dialog.Path = User.Home
Dialog.Filter = ["*.png;*.jpg;*.jpeg;*.bmp", "Picture files"]
If Dialog.OpenFile() Then Return
Select Case File.Ext(Dialog.Path)
Case "png", "jpg", "jpeg", "bmp"
Case Else
Message.Error("Imagen no válida!")
Return
End Select
ReiniciarVariables()
SepararImagenes(Dialog.Path, 3, 3)
End
Public Sub parte2_Drag()
Print Last.Name
XpictureBox.Drag(XpictureBox.Picture)
End
Public Sub parte2_Drop()
Print Last.Name
End
Public Sub parte2_DblClick()
Print Last.Name
End
Public Sub pb9_MouseDrag()
Drag.Icon = pb9.Picture
If Mouse.Left Then
pb9.Drag(pb9.Tag)
Endif
End
Public Sub pb8_Drop()
Dim MiTag As String
MiTag = pb8.Tag
pb8.Picture = Picture.Load(Drag.Data)
pb8.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb6_MouseDrag()
Drag.Icon = pb6.Picture
If Mouse.Left Then
pb6.Drag(pb6.Tag)
Endif
End
Public Sub Refrescar()
pb1.Picture = Picture.Load(pb1.Tag)
pb2.Picture = Picture.Load(pb2.Tag)
pb3.Picture = Picture.Load(pb3.Tag)
Wait 0.2
pb4.Picture = Picture.Load(pb4.Tag)
pb5.Picture = Picture.Load(pb5.Tag)
pb6.Picture = Picture.Load(pb6.Tag)
Wait 0.2
pb7.Picture = Picture.Load(pb7.Tag)
pb8.Picture = Picture.Load(pb8.Tag)
pb9.Picture = Picture.Load(pb9.Tag)
If Intentos > 5 Then
btnSolucion.Visible = True
Endif
Inc Intentos
End
Public Sub Desordenar()
Dim max As Integer
Dim uno As Integer
Dim dos As Integer
Randomize
max = TagOrdenado.Max
uno = Rand(0, max)
dos = Rand(0, max)
Repeat
dos = Rand(0, max)
Until uno <> dos
Swap TagOrdenado[uno], TagOrdenado[dos]
End
Public Sub Refrescar2()
pb1.Tag = TagOrdenado[0]
pb2.Tag = TagOrdenado[1]
pb3.Tag = TagOrdenado[2]
pb4.Tag = TagOrdenado[3]
pb5.Tag = TagOrdenado[4]
pb6.Tag = TagOrdenado[5]
pb7.Tag = TagOrdenado[6]
pb8.Tag = TagOrdenado[7]
pb9.Tag = TagOrdenado[8]
pb1.Picture = Null
pb2.Picture = Null
pb3.Picture = Null
pb4.Picture = Null
pb5.Picture = Null
pb6.Picture = Null
pb7.Picture = Null
pb8.Picture = Null
pb9.Picture = Null
Wait 0.5
Refrescar()
End
Public Sub pb5_MouseDrag()
Drag.Icon = pb5.Picture
If Mouse.Left Then
pb5.Drag(pb5.Tag)
Endif
End
Public Sub pb9_Drop()
Dim MiTag As String
MiTag = pb9.Tag
pb9.Picture = Picture.Load(Drag.Data)
pb9.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb7_Drop()
Dim MiTag As String
MiTag = pb7.Tag
pb7.Picture = Picture.Load(Drag.Data)
pb7.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb6_Drop()
Dim MiTag As String
MiTag = pb6.Tag
pb6.Picture = Picture.Load(Drag.Data)
pb6.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb5_Drop()
Dim MiTag As String
MiTag = pb5.Tag
pb5.Picture = Picture.Load(Drag.Data)
pb5.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb7_MouseDrag()
Drag.Icon = pb7.Picture
If Mouse.Left Then
pb7.Drag(pb7.Tag)
Endif
End
Public Sub pb4_MouseDrag()
Drag.Icon = pb4.Picture
If Mouse.Left Then
pb4.Drag(pb4.Tag)
Endif
End
Public Sub pb8_MouseDrag()
Drag.Icon = pb8.Picture
If Mouse.Left Then
pb8.Drag(pb8.Tag)
Endif
End
Public Sub pb1_MouseDrag()
Drag.Icon = pb1.Picture
If Mouse.Left Then
pb1.Drag(pb1.Tag)
Endif
End
Public Sub pb2_MouseDrag()
Drag.Icon = pb2.Picture
If Mouse.Left Then
pb2.Drag(pb2.Tag)
Endif
End
Public Sub pb3_MouseDrag()
Drag.Icon = pb3.Picture
If Mouse.Left Then
pb3.Drag(pb3.Tag)
Endif
End
Public Sub pb4_Drop()
Dim MiTag As String
MiTag = pb4.Tag
pb4.Picture = Picture.Load(Drag.Data)
pb4.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb1_Drop()
Dim MiTag As String
MiTag = pb1.Tag
pb1.Picture = Picture.Load(Drag.Data)
pb1.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb2_Drop()
Dim MiTag As String
MiTag = pb2.Tag
pb2.Picture = Picture.Load(Drag.Data)
pb2.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb3_Drop()
Dim MiTag As String
MiTag = pb3.Tag
pb3.Picture = Picture.Load(Drag.Data)
pb3.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub btnDesordenar_Click()
Desordenar()
Refrescar2
End
Public Sub ReiniciarVariables()
PBactual = New PictureBox(Me)
TagOrdenado = New String[]
Intentos = 0
btnSolucion.Visible = False
End
Public Sub btnSolucion_Click()
PictureBox1.Visible = Not PictureBox1.Visible
End
Public Sub cbxFotos_Click()
ReiniciarVariables()
SepararImagenes(cbxFotos.Text, 3, 3)
End
Public Cantidad_Sprites As Picture[]
Public XpictureBox As PictureBox
Public TagOrdenado As String[]
Public Repeticiones As Integer = 200
Public Intentos As Integer
Public PICactual As Picture
Public pbActual As PictureBox
Public Sub Form_Open()
Label1.Text = "by postapase v. " & Application.Version
ReiniciarVariables()
SepararImagenes("casa.jpeg", 3, 3)
End
Public Sub SepararImagenes(path As String, filas As Integer, columnas As Integer)
'subrutina extraida y modificada del ejemplo de Julio 1945
Dim i As Image
Dim fila As Integer
Dim columna As Integer
Dim imagenAncho As Integer
Dim imagenLargo As Integer
Dim fichero As Picture
Dim contador As Integer = 1
Dim ruta As String
Dim a As Integer
i = Image.Load(path)
PictureBox1.Visible = False
PictureBox1.Picture = Picture.Load(path)
Cantidad_Sprites = New Picture[]
imagenAncho = i.w / columnas
imagenlargo = i.h / filas
For fila = 1 To filas
For columna = 1 To columnas
fichero = New Picture(imagenAncho, imagenLargo, Color.Transparent)
Paint.Begin(fichero)
Paint.DrawImage(i, 0, 0, imagenAncho, imagenLargo, 1, Rect((columna - 1) * imagenAncho, (fila - 1) * imagenLargo, imagenancho, imagenlargo))
Paint.Stroke()
Paint.Fill
Paint.End()
Wait 0.1
ruta = "/tmp/dibujo" & Str$(contador) & ".png"
fichero.Save(ruta)
Wait 0.1
Cantidad_Sprites.Add(fichero)
TagOrdenado.Add(ruta)
Select Case contador
Case 1
pb1.Tag = ruta
Case 2
pb2.Tag = ruta
Case 3
pb3.Tag = ruta
Case 4
pb4.Tag = ruta
Case 5
pb5.Tag = ruta
Case 6
pb6.Tag = ruta
Case 7
pb7.Tag = ruta
Case 8
pb8.Tag = ruta
Case 9
pb9.Tag = ruta
End Select
contador += 1
Next
Next
For a = 1 To Repeticiones
Desordenar()
Next
Refrescar2()
End
Public Sub btnOtraImagen_Click()
Dialog.Path = User.Home
Dialog.Filter = ["*.png;*.jpg;*.jpeg;*.bmp", "Picture files"]
If Dialog.OpenFile() Then Return
Select Case File.Ext(Dialog.Path)
Case "png", "jpg", "jpeg", "bmp"
Case Else
Message.Error("Imagen no válida!")
Return
End Select
ReiniciarVariables()
SepararImagenes(Dialog.Path, 3, 3)
End
Public Sub parte2_Drag()
Print Last.Name
XpictureBox.Drag(XpictureBox.Picture)
End
Public Sub parte2_Drop()
Print Last.Name
End
Public Sub parte2_DblClick()
Print Last.Name
End
Public Sub pb9_MouseDrag()
Drag.Icon = pb9.Picture
If Mouse.Left Then
pb9.Drag(pb9.Tag)
Endif
End
Public Sub pb8_Drop()
Dim MiTag As String
MiTag = pb8.Tag
pb8.Picture = Picture.Load(Drag.Data)
pb8.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb6_MouseDrag()
Drag.Icon = pb6.Picture
If Mouse.Left Then
pb6.Drag(pb6.Tag)
Endif
End
Public Sub Refrescar()
pb1.Picture = Picture.Load(pb1.Tag)
pb2.Picture = Picture.Load(pb2.Tag)
pb3.Picture = Picture.Load(pb3.Tag)
Wait 0.2
pb4.Picture = Picture.Load(pb4.Tag)
pb5.Picture = Picture.Load(pb5.Tag)
pb6.Picture = Picture.Load(pb6.Tag)
Wait 0.2
pb7.Picture = Picture.Load(pb7.Tag)
pb8.Picture = Picture.Load(pb8.Tag)
pb9.Picture = Picture.Load(pb9.Tag)
If Intentos > 5 Then
btnSolucion.Visible = True
Endif
Inc Intentos
End
Public Sub Desordenar()
Dim max As Integer
Dim uno As Integer
Dim dos As Integer
Randomize
max = TagOrdenado.Max
uno = Rand(0, max)
dos = Rand(0, max)
Repeat
dos = Rand(0, max)
Until uno <> dos
Swap TagOrdenado[uno], TagOrdenado[dos]
End
Public Sub Refrescar2()
pb1.Tag = TagOrdenado[0]
pb2.Tag = TagOrdenado[1]
pb3.Tag = TagOrdenado[2]
pb4.Tag = TagOrdenado[3]
pb5.Tag = TagOrdenado[4]
pb6.Tag = TagOrdenado[5]
pb7.Tag = TagOrdenado[6]
pb8.Tag = TagOrdenado[7]
pb9.Tag = TagOrdenado[8]
pb1.Picture = Null
pb2.Picture = Null
pb3.Picture = Null
pb4.Picture = Null
pb5.Picture = Null
pb6.Picture = Null
pb7.Picture = Null
pb8.Picture = Null
pb9.Picture = Null
Wait 0.5
Refrescar()
End
Public Sub pb5_MouseDrag()
Drag.Icon = pb5.Picture
If Mouse.Left Then
pb5.Drag(pb5.Tag)
Endif
End
Public Sub pb9_Drop()
Dim MiTag As String
MiTag = pb9.Tag
pb9.Picture = Picture.Load(Drag.Data)
pb9.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb7_Drop()
Dim MiTag As String
MiTag = pb7.Tag
pb7.Picture = Picture.Load(Drag.Data)
pb7.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb6_Drop()
Dim MiTag As String
MiTag = pb6.Tag
pb6.Picture = Picture.Load(Drag.Data)
pb6.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb5_Drop()
Dim MiTag As String
MiTag = pb5.Tag
pb5.Picture = Picture.Load(Drag.Data)
pb5.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb7_MouseDrag()
Drag.Icon = pb7.Picture
If Mouse.Left Then
pb7.Drag(pb7.Tag)
Endif
End
Public Sub pb4_MouseDrag()
Drag.Icon = pb4.Picture
If Mouse.Left Then
pb4.Drag(pb4.Tag)
Endif
End
Public Sub pb8_MouseDrag()
Drag.Icon = pb8.Picture
If Mouse.Left Then
pb8.Drag(pb8.Tag)
Endif
End
Public Sub pb1_MouseDrag()
Drag.Icon = pb1.Picture
If Mouse.Left Then
pb1.Drag(pb1.Tag)
Endif
End
Public Sub pb2_MouseDrag()
Drag.Icon = pb2.Picture
If Mouse.Left Then
pb2.Drag(pb2.Tag)
Endif
End
Public Sub pb3_MouseDrag()
Drag.Icon = pb3.Picture
If Mouse.Left Then
pb3.Drag(pb3.Tag)
Endif
End
Public Sub pb4_Drop()
Dim MiTag As String
MiTag = pb4.Tag
pb4.Picture = Picture.Load(Drag.Data)
pb4.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb1_Drop()
Dim MiTag As String
MiTag = pb1.Tag
pb1.Picture = Picture.Load(Drag.Data)
pb1.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb2_Drop()
Dim MiTag As String
MiTag = pb2.Tag
pb2.Picture = Picture.Load(Drag.Data)
pb2.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub pb3_Drop()
Dim MiTag As String
MiTag = pb3.Tag
pb3.Picture = Picture.Load(Drag.Data)
pb3.Tag = Drag.Data
Drag.Source.Tag = MiTag
Refrescar()
End
Public Sub btnDesordenar_Click()
Desordenar()
Refrescar2
End
Public Sub ReiniciarVariables()
PBactual = New PictureBox(Me)
TagOrdenado = New String[]
Intentos = 0
btnSolucion.Visible = False
End
Public Sub btnSolucion_Click()
PictureBox1.Visible = Not PictureBox1.Visible
End
Public Sub cbxFotos_Click()
ReiniciarVariables()
SepararImagenes(cbxFotos.Text, 3, 3)
End
El ejemplo se encuentra en la granja de gambas.
No hay comentarios.:
Publicar un comentario