\' Gambas class file
Public tablero As ClassTablero
Public d As Integer = 40
Public ProducidoClick As New Boolean[]
Public col As New Integer[]
Public jugadores As Variant[]
Public texto As New String[] \'\'resumiendo los jugadores elegidos..
Public Sub _new()
End
Public Sub Form_Open()
Timer1.Enabled = False
ProducidoClick.Add(False)
col.Add(0)
dibujatablero(tablero.muestra())
End
Public Sub form_Show()
textlabelPartida.text = texto[0]
Timer1.Enabled = True
End
Public Sub dibujatableroCuarteta(valores As Integer[])
Dim a, b As Integer
Dim x, y As Integer
Paint.Begin(DrawingAreaTablero)
For a = 0 To 3
Paint.Brush = Paint.Color(Color.green)
y = valores[a * 2]
x = valores[a * 2 + 1]
\' Print "y: ", y, "x: ", x
Paint.Ellipse((x) * d + (d - 5) / 2, (y) * d + (d - 5) / 2, (d - 5) / 2, (d - 5) / 2)
Paint.Fill(True)
Paint.Stroke()
Next
Paint.End()
\' Print "................"
End
Public Sub dibujatablero(texto As Integer[])
Dim a, b As Integer
dibujatableroInicial()
Paint.Begin(DrawingAreaTablero)
For a = 0 To 6
For b = 0 To 6
If texto[a, b] = 1 Then
Paint.Brush = Paint.Color(Color.orange)
Paint.Ellipse((b) * d + 10, (a) * d + 10, d - 5, d - 5)
Paint.Fill(True)
Paint.Stroke()
Else
If texto[a, b] = -1 Then
Paint.Brush = Paint.Color(Color.yellow)
Paint.Ellipse((b) * d + 10, (a) * d + 10, d - 5, d - 5)
Paint.Fill(True)
Paint.Stroke()
Endif
Endif
Next
Next
Paint.End
End
Public Sub dibujatableroInicial()
Dim a, b As Integer
DrawingAreaTablero.Cached = True
Paint.Begin(DrawingAreaTablero)
For a = 0 To 6
For b = 0 To 6
Paint.Ellipse(a * d + 10, b * d + 10, d - 5, d - 5)
Paint.Fill(True)
Next
Next
Paint.Stroke()
Paint.End
End
Public Sub DrawingAreaTablero_MouseDown()
Dim largo As Integer
If main.pensando = True Then Return
\'Print Int((Mouse.x) / d + 0.7)
col[0] = Int((Mouse.x) / d + 0.7)
If col[0] > -1 Then
ProducidoClick[0] = True
Endif
End
Public Sub EmpezarJugar()
Dim jugador1 As Object
Dim jugador2 As Object
Dim jugadaganadora As Integer[]
Dim g As Integer
Dim gana As String
\'tablero = New ClassTablero
\'inicio un tablero en blanco
\'TextAreaJugadas.text = ""
\' FormJugadores.texto = texto
\' FormJugadores.jugadores = jugadores
jugador1 = jugadores[0]
jugador2 = jugadores[1]
jugador1.numero = -1 \'jugador uno
jugador2.numero = 1 \'jugador dos
textlabelPartida.text = texto[0]
\' controlador.max_profundidad = profundidad[Val(ComboBoxDificultad.text) - 1]
While True
dibujatablero(tablero.muestra())
TextLabelMensajes.text = "Mensajes:"
If Object.Type(jugador1) = "ClassJugadorHumano" Then
TextLabelMensajes.text = "Mensajes:<br>" & gb.CrLf & "Jugador 1<br>Pulse en una de las columnas..<br>(amarillo)"
Else
TextLabelMensajes.text = "Mensajes:<br>" & gb.CrLf & " Pensando Ordenador..."
Application.busy = 1
Endif
Wait 0.01
tablero = jugador1.juega(tablero, ProducidoClick, col, TextLabelMensajes, TextAreaJugadas)
Application.busy = 0
ProducidoClick[0] = False
If tablero.GameOver() Then Break
dibujatablero(tablero.muestra())
If Object.Type(jugador2) = "ClassJugadorHumano" Then
TextLabelMensajes.text = "Mensajes:<br>" & gb.CrLf & "Jugador 2 <br>Pulse en una de las columnas..<br>(naranja)"
Else
TextLabelMensajes.text = "Mensajes:<br>" & gb.CrLf & " Pensando Ordenador..."
Application.busy = 1
Endif
Wait 0.01
tablero = jugador2.juega(tablero, ProducidoClick, col, TextLabelMensajes, TextAreaJugadas)
Application.busy = 0
dibujatablero(tablero.muestra())
If tablero.GameOver() Then Break
\' Print main.sumacero, main.sumauno
Wend
tablero.muestra
g = tablero.ganador()[0]
If g == 0 Then
gana = "Tablas"
Else If g = -1 Then
gana = "Jugador 1 (amarillo)"
jugadaganadora = tablero.comprueba_linea_Cuatro(4, -1)[1]
Else
gana = "Jugador 2 (naranja)"
jugadaganadora = tablero.comprueba_linea_Cuatro(4, 1)[1]
Endif
\' Print "Ganador: " & gana
TextLabelMensajes.text = "Ganador: " & Gana
dibujatablero(tablero.muestra())
If gana <> "Tablas" Then dibujatableroCuarteta(jugadaganadora)
End
Public Sub Timer1_Timer()
Timer1.enabled = False
EmpezarJugar()
End
Public Sub ButtonGuardar_Click()
Dim contenido As String
Dim a, b As Integer
Dialog.Filter = ["*.c4", "Conecta4"]
If Dialog.SaveFile() Then
\'no hacer nada
Return
Else
contenido = "v1.00 Tablero" & gb.Cr
For a = 0 To 6
For b = 0 To 6
contenido &= Str$(tablero.casillas[a, b]) & gb.Cr
Next
Next
contenido &= Str$(jugadores[0].numero) & gb.Cr
contenido &= Str$(jugadores[0].numero) & gb.Cr
contenido &= Str$(jugadores[1].numero) & gb.Cr
contenido &= Str$(jugadores[1].numero) & gb.Cr
contenido &= "[Informacion Jugadores]" & gb.Cr
contenido &= textlabelPartida.text & gb.Cr
contenido &= "[Informacion partida]" & gb.Cr
contenido &= TextAreaJugadas.text
If File.Ext(Dialog.Path) = ".c4" Then
Else
Dialog.path &= ".c4"
Endif
File.Save(Dialog.path, contenido)
Message.Info("partida guardada")
Endif
End