Advertisement
jsbsan

tableroCommand

Nov 3rd, 2013
1,868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GAMBAS 3.07 KB | None | 0 0
  1. ' Gambas class file
  2.  
  3. Public AreaDibujo As DrawingArea
  4.  
  5. Public Struct animal
  6.   icono As String
  7.   p As Point
  8. End Struct
  9.  
  10. Public vallas As New Point[]
  11.  
  12. Public ListaAnimales As New Animal[]
  13.  
  14. Public Sub _new()
  15.   'crea lista de animales y sus posiciones
  16.  
  17.   Dim existe As Boolean
  18.   Dim a As Integer
  19.   Dim animaltemp As New Animal
  20.   Dim numero As Integer
  21.   Dim pto As New Point
  22.  
  23.   For a = 0 To 9
  24.     animaltemp = New Animal
  25.     pto = New Point
  26.     numero = Int(Rnd(1, 6))
  27.     animaltemp.icono = Choose(numero, "burro.png", "cerdo.png", "gallina.png", "oveja.png", "vaca.png")
  28.     existe = True
  29.     While existe
  30.       'busco coordenada donde no exista un animal...
  31.       pto.x = Int(Rnd(0, 10))
  32.       pto.y = Int(Rnd(0, 10))
  33.       If busca(pto.x, pto.y) = Null Then
  34.         existe = False
  35.       Endif
  36.     Wend
  37.    
  38.     animaltemp.p = pto
  39.    
  40.     ListaAnimales.Add(animaltemp)
  41.    
  42.   Next
  43.  
  44. End
  45.  
  46. Public Sub dibujalista()
  47.  
  48.   Dim a As Integer
  49.   Dim animaltemp As Animal
  50.   Dim vtemp As Point
  51.  
  52.   Paint.Begin(AreaDibujo)
  53.   Paint.Rectangle(0, 0, AreaDibujo.w, AreaDibujo.w)
  54.   Paint.Brush = Paint.Color(Color.Orange)
  55.   Paint.Fill(True)
  56.  
  57.   Paint.Stroke()
  58.   For a = 0 To ListaAnimales.Max
  59.     animaltemp = ListaAnimales[a]
  60.     Paint.DrawPicture(Picture[animaltemp.icono], animaltemp.p.x * 40, animaltemp.p.y * 40, 40, 40)
  61.    
  62.     Paint.Stroke()
  63.   Next
  64.  
  65.   For a = 0 To Vallas.Max
  66.     vtemp = Vallas[a]
  67.    
  68.     Paint.DrawPicture(Picture["valla.png"], vtemp.x * 40, vtemp.y * 40, 40)
  69.     Paint.Stroke()
  70.   Next
  71.  
  72.   Paint.End()
  73.  
  74. End
  75.  
  76. Public Sub mover(x0 As Integer, y0 As Integer, x1 As Integer, y1 As Integer)
  77.  
  78.   Dim a As Integer
  79.   Dim animaltemp As Animal
  80.   'buscar en la lista si hay animal en x0 e y0
  81.   For a = 0 To ListaAnimales.Max
  82.     animaltemp = ListaAnimales[a]
  83.     If animaltemp.p.X = x0 And animaltemp.p.y = y0 Then
  84.       'hay un animal, y lo cambio de sitio
  85.       animaltemp.p.x = x1
  86.       animaltemp.p.y = y1
  87.      
  88.     Endif
  89.   Next
  90.  
  91. End
  92.  
  93. Public Function busca(x0 As Integer, y0 As Integer) As Animal
  94.  
  95.   Dim animaltemp As Animal
  96.   Dim a As Integer
  97.  
  98.   For a = 0 To ListaAnimales.Max
  99.     animaltemp = ListaAnimales[a]
  100.     If animaltemp.p.X = x0 And animaltemp.p.y = y0 Then
  101.       'hay un animal,y devuelvo true
  102.      
  103.       Return animaltemp
  104.     Endif
  105.   Next
  106.  
  107.   Return Null  
  108.  
  109. End
  110.  
  111. Public Function copia() As Tablero
  112.  
  113.   Dim copiatablero As New Tablero
  114.  
  115.   copiatablero.AreaDibujo = Me.AreaDibujo
  116.   copiatablero.ListaAnimales = ListaAnimales.Copy()
  117.   copiatablero.vallas = vallas.Copy()
  118.   Return copiatablero
  119.  
  120. End
  121.  
  122. Public Function insertarValla(x0 As Integer, y0 As Integer)
  123.  
  124.   Dim vtemp As New Point
  125.  
  126.   vtemp.x = x0
  127.   vtemp.y = y0
  128.  
  129.   vallas.Add(vtemp)
  130.  
  131.   dibujalista()
  132.  
  133. End
  134.  
  135. Public Function quitarValla(x0 As Integer, y0 As Integer)
  136.  
  137.   Dim a As Integer
  138.   Dim vtemp As Point
  139.  
  140.   For a = 0 To vallas.Max
  141.     vtemp = vallas[a]
  142.    
  143.     If vtemp.x = x0 And vtemp.y = y0 Then
  144.       vallas.Delete(a)
  145.       Return
  146.     Endif
  147.   Next
  148.   dibujalista()
  149.  
  150. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement