Advertisement
jsbsan

fmaintablero

Oct 8th, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.65 KB | None | 0 0
  1. ' Gambas class file
  2.  
  3. Public tablero As ClassTablero
  4. Public d As Integer = 40
  5. Public ProducidoClick As New Boolean[]
  6. Public col As New Integer[]
  7. Public jugadores As Variant[]
  8. Public texto As New String[] ''resumiendo los jugadores elegidos..
  9.  
  10. Public Sub _new()
  11.  
  12. End
  13.  
  14. Public Sub Form_Open()
  15.  
  16. Timer1.Enabled = False
  17. ProducidoClick.Add(False)
  18. col.Add(0)
  19.  
  20. dibujatablero(tablero.muestra())
  21.  
  22. End
  23.  
  24. Public Sub form_Show()
  25.  
  26. textlabelPartida.text = texto[0]
  27. Timer1.Enabled = True
  28.  
  29. End
  30.  
  31. Public Sub dibujatableroCuarteta(valores As Integer[])
  32.  
  33. Dim a, b As Integer
  34. Dim x, y As Integer
  35.  
  36. Paint.Begin(DrawingAreaTablero)
  37. For a = 0 To 3
  38. Paint.Brush = Paint.Color(Color.green)
  39. y = valores[a * 2]
  40. x = valores[a * 2 + 1]
  41. ' Print "y: ", y, "x: ", x
  42. Paint.Ellipse((x) * d + (d - 5) / 2, (y) * d + (d - 5) / 2, (d - 5) / 2, (d - 5) / 2)
  43. Paint.Fill(True)
  44. Paint.Stroke()
  45.  
  46. Next
  47. Paint.End()
  48. ' Print "................"
  49.  
  50. End
  51.  
  52. Public Sub dibujatablero(texto As Integer[])
  53.  
  54. Dim a, b As Integer
  55.  
  56. dibujatableroInicial()
  57. Paint.Begin(DrawingAreaTablero)
  58.  
  59. For a = 0 To 6
  60. For b = 0 To 6
  61. If texto[a, b] = 1 Then
  62. Paint.Brush = Paint.Color(Color.orange)
  63. Paint.Ellipse((b) * d + 10, (a) * d + 10, d - 5, d - 5)
  64. Paint.Fill(True)
  65. Paint.Stroke()
  66. Else
  67. If texto[a, b] = -1 Then
  68. Paint.Brush = Paint.Color(Color.yellow)
  69.  
  70. Paint.Ellipse((b) * d + 10, (a) * d + 10, d - 5, d - 5)
  71. Paint.Fill(True)
  72. Paint.Stroke()
  73. Endif
  74. Endif
  75.  
  76. Next
  77. Next
  78.  
  79. Paint.End
  80.  
  81. End
  82.  
  83. Public Sub dibujatableroInicial()
  84.  
  85. Dim a, b As Integer
  86.  
  87. DrawingAreaTablero.Cached = True
  88. Paint.Begin(DrawingAreaTablero)
  89.  
  90. For a = 0 To 6
  91. For b = 0 To 6
  92.  
  93. Paint.Ellipse(a * d + 10, b * d + 10, d - 5, d - 5)
  94. Paint.Fill(True)
  95. Next
  96. Next
  97. Paint.Stroke()
  98. Paint.End
  99.  
  100. End
  101.  
  102. Public Sub DrawingAreaTablero_MouseDown()
  103.  
  104. Dim largo As Integer
  105.  
  106. If main.pensando = True Then Return
  107. 'Print Int((Mouse.x) / d + 0.7)
  108.  
  109. col[0] = Int((Mouse.x) / d + 0.7)
  110. If col[0] > -1 Then
  111. ProducidoClick[0] = True
  112. Endif
  113.  
  114. End
  115.  
  116. Public Sub EmpezarJugar()
  117.  
  118. Dim jugador1 As Object
  119. Dim jugador2 As Object
  120. Dim jugadaganadora As Integer[]
  121. Dim g As Integer
  122. Dim gana As String
  123.  
  124. 'tablero = New ClassTablero
  125. 'inicio un tablero en blanco
  126. 'TextAreaJugadas.text = ""
  127. ' FormJugadores.texto = texto
  128. ' FormJugadores.jugadores = jugadores
  129.  
  130. jugador1 = jugadores[0]
  131. jugador2 = jugadores[1]
  132. jugador1.numero = -1 'jugador uno
  133. jugador2.numero = 1 'jugador dos
  134. textlabelPartida.text = texto[0]
  135. ' controlador.max_profundidad = profundidad[Val(ComboBoxDificultad.text) - 1]
  136.  
  137. While True
  138. dibujatablero(tablero.muestra())
  139. TextLabelMensajes.text = "Mensajes:"
  140. If Object.Type(jugador1) = "ClassJugadorHumano" Then
  141. TextLabelMensajes.text = "Mensajes:<br>" & gb.CrLf & "Jugador 1<br>Pulse en una de las columnas..<br>(amarillo)"
  142. Else
  143. TextLabelMensajes.text = "Mensajes:<br>" & gb.CrLf & " Pensando Ordenador..."
  144. Application.busy = 1
  145. Endif
  146. Wait 0.01
  147. tablero = jugador1.juega(tablero, ProducidoClick, col, TextLabelMensajes, TextAreaJugadas)
  148. Application.busy = 0
  149. ProducidoClick[0] = False
  150. If tablero.GameOver() Then Break
  151. dibujatablero(tablero.muestra())
  152. If Object.Type(jugador2) = "ClassJugadorHumano" Then
  153. TextLabelMensajes.text = "Mensajes:<br>" & gb.CrLf & "Jugador 2 <br>Pulse en una de las columnas..<br>(naranja)"
  154. Else
  155. TextLabelMensajes.text = "Mensajes:<br>" & gb.CrLf & " Pensando Ordenador..."
  156. Application.busy = 1
  157. Endif
  158. Wait 0.01
  159. tablero = jugador2.juega(tablero, ProducidoClick, col, TextLabelMensajes, TextAreaJugadas)
  160. Application.busy = 0
  161. dibujatablero(tablero.muestra())
  162.  
  163. If tablero.GameOver() Then Break
  164. ' Print main.sumacero, main.sumauno
  165. Wend
  166.  
  167. tablero.muestra
  168.  
  169. g = tablero.ganador()[0]
  170.  
  171. If g == 0 Then
  172. gana = "Tablas"
  173.  
  174. Else If g = -1 Then
  175. gana = "Jugador 1 (amarillo)"
  176. jugadaganadora = tablero.comprueba_linea_Cuatro(4, -1)[1]
  177. Else
  178. gana = "Jugador 2 (naranja)"
  179. jugadaganadora = tablero.comprueba_linea_Cuatro(4, 1)[1]
  180. Endif
  181.  
  182. ' Print "Ganador: " & gana
  183. TextLabelMensajes.text = "Ganador: " & Gana
  184.  
  185. dibujatablero(tablero.muestra())
  186.  
  187. If gana <> "Tablas" Then dibujatableroCuarteta(jugadaganadora)
  188.  
  189. End
  190.  
  191. Public Sub Timer1_Timer()
  192.  
  193. Timer1.enabled = False
  194. EmpezarJugar()
  195.  
  196. End
  197.  
  198. Public Sub ButtonGuardar_Click()
  199.  
  200. Dim contenido As String
  201. Dim a, b As Integer
  202.  
  203. Dialog.Filter = ["*.c4", "Conecta4"]
  204. If Dialog.SaveFile() Then
  205. 'no hacer nada
  206. Return
  207. Else
  208. contenido = "v1.00 Tablero" & gb.Cr
  209. For a = 0 To 6
  210. For b = 0 To 6
  211. contenido &= Str$(tablero.casillas[a, b]) & gb.Cr
  212.  
  213. Next
  214. Next
  215.  
  216. contenido &= Str$(jugadores[0].numero) & gb.Cr
  217. contenido &= Str$(jugadores[0].numero) & gb.Cr
  218. contenido &= Str$(jugadores[1].numero) & gb.Cr
  219. contenido &= Str$(jugadores[1].numero) & gb.Cr
  220. contenido &= "[Informacion Jugadores]" & gb.Cr
  221. contenido &= textlabelPartida.text & gb.Cr
  222. contenido &= "[Informacion partida]" & gb.Cr
  223. contenido &= TextAreaJugadas.text
  224. If File.Ext(Dialog.Path) = ".c4" Then
  225. Else
  226. Dialog.path &= ".c4"
  227. Endif
  228. File.Save(Dialog.path, contenido)
  229. Message.Info("partida guardada")
  230. Endif
  231.  
  232. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement