Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Gambas class file
- Public AreaDibujo As DrawingArea
- Public Struct animal
- icono As String
- p As Point
- End Struct
- Public vallas As New Point[]
- Public ListaAnimales As New Animal[]
- Public Sub _new()
- 'crea lista de animales y sus posiciones
- Dim existe As Boolean
- Dim a As Integer
- Dim animaltemp As New Animal
- Dim numero As Integer
- Dim pto As New Point
- For a = 0 To 9
- animaltemp = New Animal
- pto = New Point
- numero = Int(Rnd(1, 6))
- animaltemp.icono = Choose(numero, "burro.png", "cerdo.png", "gallina.png", "oveja.png", "vaca.png")
- existe = True
- While existe
- 'busco coordenada donde no exista un animal...
- pto.x = Int(Rnd(0, 10))
- pto.y = Int(Rnd(0, 10))
- If busca(pto.x, pto.y) = Null Then
- existe = False
- Endif
- Wend
- animaltemp.p = pto
- ListaAnimales.Add(animaltemp)
- Next
- End
- Public Sub dibujalista()
- Dim a As Integer
- Dim animaltemp As Animal
- Dim vtemp As Point
- Paint.Begin(AreaDibujo)
- Paint.Rectangle(0, 0, AreaDibujo.w, AreaDibujo.w)
- Paint.Brush = Paint.Color(Color.Orange)
- Paint.Fill(True)
- Paint.Stroke()
- For a = 0 To ListaAnimales.Max
- animaltemp = ListaAnimales[a]
- Paint.DrawPicture(Picture[animaltemp.icono], animaltemp.p.x * 40, animaltemp.p.y * 40, 40, 40)
- Paint.Stroke()
- Next
- For a = 0 To Vallas.Max
- vtemp = Vallas[a]
- Paint.DrawPicture(Picture["valla.png"], vtemp.x * 40, vtemp.y * 40, 40)
- Paint.Stroke()
- Next
- Paint.End()
- End
- Public Sub mover(x0 As Integer, y0 As Integer, x1 As Integer, y1 As Integer)
- Dim a As Integer
- Dim animaltemp As Animal
- 'buscar en la lista si hay animal en x0 e y0
- For a = 0 To ListaAnimales.Max
- animaltemp = ListaAnimales[a]
- If animaltemp.p.X = x0 And animaltemp.p.y = y0 Then
- 'hay un animal, y lo cambio de sitio
- animaltemp.p.x = x1
- animaltemp.p.y = y1
- Endif
- Next
- End
- Public Function busca(x0 As Integer, y0 As Integer) As Animal
- Dim animaltemp As Animal
- Dim a As Integer
- For a = 0 To ListaAnimales.Max
- animaltemp = ListaAnimales[a]
- If animaltemp.p.X = x0 And animaltemp.p.y = y0 Then
- 'hay un animal,y devuelvo true
- Return animaltemp
- Endif
- Next
- Return Null
- End
- Public Function copia() As Tablero
- Dim copiatablero As New Tablero
- copiatablero.AreaDibujo = Me.AreaDibujo
- copiatablero.ListaAnimales = ListaAnimales.Copy()
- copiatablero.vallas = vallas.Copy()
- Return copiatablero
- End
- Public Function insertarValla(x0 As Integer, y0 As Integer)
- Dim vtemp As New Point
- vtemp.x = x0
- vtemp.y = y0
- vallas.Add(vtemp)
- dibujalista()
- End
- Public Function quitarValla(x0 As Integer, y0 As Integer)
- Dim a As Integer
- Dim vtemp As Point
- For a = 0 To vallas.Max
- vtemp = vallas[a]
- If vtemp.x = x0 And vtemp.y = y0 Then
- vallas.Delete(a)
- Return
- Endif
- Next
- dibujalista()
- End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement