\' Gambas class file
Private colaDeshacer As New Comando[]
Private colaRehacer As New Comando[]
Private bandera As Integer \'movimiento pos inicial, 2 indica movimiento pos final, 3 significa que va a insertar vallas
Private tab As New Tablero
Public Struct animal
icono As String
p As Point
End Struct
\'para usar una estructura antes debe de estar definida
Public animaltmp As Animal
Public Sub _new()
End
Public Sub Form_Open()
Randomize
bandera = 1
Me.center
tab.AreaDibujo = DrawingArea1
tab.dibujalista()
TextLabelMensaje.text = "Mensaje: Haga click en algun animal, y muevelo a otra posicion"
End
Public Sub DrawingArea1_MouseDown()
Dim movtemp As Mover
Dim insertatmp As Insertar
Select Case bandera
Case 2
\'con la coordenada obtenida, crea la orden "mover" y la ejecuta
\'veo si existe algun animal en la posicion nueva...
If tab.busca(Mouse.x \\ 40, Mouse.y \\ 40) <> Null Then
\'existe un animal en esa posicion
Else
ListBoxDeshacer.Add("Mover " & Replace(animaltmp.icono, ".png", "") & " (" & Str$(animaltmp.p.x) & "," & Str$(animaltmp.p.y) & " a " & Str$(Mouse.x \\ 40) & "," & Str(Mouse.y \\ 40) & ")")
\'hago el movimiento
movtemp = New Mover(tab, animaltmp.p.X, animaltmp.p.y, Mouse.x \\ 40, Mouse.y \\ 40)
movtemp.ejecutar()
colaDeshacer.add(movtemp)
colaRehacer.clear()
ListBoxRehacer.Clear()
animaltmp = Null
bandera = 1
Endif
Return
Case 1
animaltmp = tab.busca(Mouse.x \\ 40, Mouse.y \\ 40)
If animaltmp = Null Then
Print "no encuntro nada"
Else
Print animaltmp.icono
bandera = 2
Endif
Case 3
insertatmp = New Insertar(tab, Mouse.x \\ 40, Mouse.y \\ 40)
insertatmp.ejecutar()
colaDeshacer.Add(insertatmp)
ListBoxDeshacer.Add("insertado valla en x:" & Str$(Mouse.x \\ 40) & " y:" & Str(Mouse.y \\ 40))
colaRehacer.Clear()
ListBoxRehacer.Clear()
End Select
End
Public Sub ToolButtonDeshacer_Click()
Dim operacion As Comando
If colaDeshacer.max > -1 Then
operacion = colaDeshacer.Pop()
operacion.deshacer()
colaRehacer.Push(operacion)
\'lista donde se muestran las juegadas
\'pongo el cursor en la ultima linea
ListBoxDeshacer.Index = ListBoxDeshacer.count - 1
\'lo aƱado a la lista de rehacer
ListBoxRehacer.Add(ListBoxDeshacer.text)
\'lo borro de la lista de deshacer
ListBoxDeshacer.Remove(ListBoxDeshacer.count - 1)
Else
Message.Info("No hay nada que deshacer")
Endif
End
Public Sub ToolButtonRehacer_Click()
Dim operacion As Comando
If colaRehacer.max > -1 Then
operacion = colaRehacer.Pop()
operacion.ejecutar()
colaDeshacer.Add(operacion)
\'listas
ListBoxRehacer.Index = ListBoxRehacer.count - 1
ListBoxDeshacer.Add(ListBoxRehacer.text)
ListBoxRehacer.Remove(ListBoxRehacer.count - 1)
Else
Message.Info("No hay nada que rehacer")
Endif
End
Public Sub ToolButtonInsertar_Click()
bandera = 3
TextLabelMensaje.Text = "Mensaje: Inserta una valla"
End
Public Sub ToolButtonMover_Click()
bandera = 1
TextLabelMensaje.text = "Mensaje: Haga click en algun animal, y muevelo a otra posicion"
End