Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

Solo Me Quedan Unos Ultimos Pasos Para Acabar El Sudoku Me Podeis Ayudar ??

Estas en el tema de Solo Me Quedan Unos Ultimos Pasos Para Acabar El Sudoku Me Podeis Ayudar ?? en el foro de Visual Basic clásico en Foros del Web. Hola pues este es mi duda es que tengo que hacer un sudoku en visual basic 9x9 y cuando pulse el boton salga un sudoku ...
  #1 (permalink)  
Antiguo 16/02/2007, 11:37
mfc
 
Fecha de Ingreso: febrero-2007
Mensajes: 33
Antigüedad: 17 años, 2 meses
Puntos: 0
Mensaje Solo Me Quedan Unos Ultimos Pasos Para Acabar El Sudoku Me Podeis Ayudar ??

Hola pues este es mi duda es que tengo que hacer un sudoku en visual basic 9x9 y cuando pulse el boton salga un sudoku completo mi primer problema es que mi sudoku tiene dos botones uno para crear y el otro para solucionar y queria saber como hacer para juntar el boton solucionar en el boton crear de forma que cunado pulse el boton crear se coloquen de forma aleatoria todo completo sin tocar el boton solucionar alguien de aqui sabe como se hace?

CODIGO SUDOKU

Const Gris As Long = &HFFFFFF
Private SolutionShown As Boolean
Private SudokuGrid(81) As Integer
Private SudokuTemp(81) As String
Private SudokuSolution(81) As String
--------------------------
Private Sub cmdGenerar_Click()
While Not CreateSudokuGrid()
Wend
lblDone.Visible = False
cmdSolucion.Enabled = True
cmdSolucion.Caption = "Show Solution"
SolutionShown = False
End Sub
------------------------------
Private Function CreateSudokuGrid() As Boolean
Dim i, j, k As Integer
Dim numRand As Integer
Dim ValIsOK(9) As Boolean
Dim valsOK As Integer
valsOK = 0

lblConfiguring.Visible = True
For i = 1 To 81
Text1(i).Text = ""
Text1(i).BackColor = Gris
Text1(i).Visible = False
SudokuSolution(i) = ""

Next i
lblConfiguring.Visible = True
lblConfiguring.Refresh
For i = 1 To 81
If True Then

valsOK = GetValidVals(i, ValIsOK)
If valsOK <= 0 Then
CreateSudokuGrid = False
End If
numRand = Int(Rnd(valsOK)) + 1
k = 0
For j = 1 To 9
If ValIsOK(j) Then
k = k + 1
If k = numRand Then
Exit For
End If
End If
Next j
Text1(i).Text = CStr(j)
Text1(i).BackColor = Gris
End If
Next i
lblConfiguring.Visible = False
For i = 1 To 81
SudokuSolution(i) = Text1(i).Text
numRand = Rnd(CInt(spnDifficulty.Text) + 1) + 1
If numRand > 1 Then
Text1(i).Text = ""
Text1(i).BackColor = Gris
Text1(i).Enabled = True
Else
Text1(i).Enabled = False
End If
Text1(i).Visible = True
Next i
CreateSudokuGrid = True
End Function
---------------------------------------
Private Function GetValidVals(ByVal Location As Integer, ByRef ValidVals() As Boolean) As Integer

Dim i, j, k As Integer
Dim row, col As Integer
Dim numStr As String
Dim numOK As Boolean
Dim retVal As Integer

retVal = 0
For i = 1 To 9
numOK = True
numStr = CStr(i)
For j = 1 To 9
k = (Int((Location - 1) / 9) * 9) + j
If Text1(k).Text = numStr Then
numOK = False
Exit For
End If
Next j
If numOK Then
For j = 1 To 9
k = (((Location - 1) Mod 9) + 1) + ((j - 1) * 9)
If Text1(k).Text = numStr Then
numOK = False
Exit For
End If
Next j
End If
If numOK Then
row = Int(Int((Location - 1) / 9) / 3)
col = Int(((Location - 1) Mod 9) / 3)
For j = 1 To 9
k = (((row * 3) + Int((j - 1) / 3)) * 9) + (col * 3) + ((j - 1) Mod 3) + 1
If Text1(k).Text = numStr Then
numOK = False
Exit For
End If
Next j
End If
ValidVals(i) = numOK
If numOK Then
retVal = retVal + 1
End If
Next i
GetValidVals = retVal
End Function
----------------------------------------
Private Sub cmdSolucion_Click()
Dim i As Integer

If SolutionShown Then
For i = 1 To 81
Text1(i).Text = SudokuTemp(i)
Next i
cmdSolucion.Caption = "Show Solution"
Else
For i = 1 To 81
SudokuTemp(i) = Text1(i).Text
Text1(i).Text = SudokuSolution(i)
Next i
cmdSolucion.Caption = "Hide Solution"
End If
SolutionShown = Not SolutionShown
End Sub

Última edición por mfc; 17/02/2007 a las 04:15
  #2 (permalink)  
Antiguo 17/02/2007, 04:16
mfc
 
Fecha de Ingreso: febrero-2007
Mensajes: 33
Antigüedad: 17 años, 2 meses
Puntos: 0
Re: Solo Me Quedan Unos Ultimos Pasos Para Acabar El Sudoku Me Podeis Ayudar ??

nadie sabe como modificar el boton?
  #3 (permalink)  
Antiguo 20/02/2007, 09:31
mfc
 
Fecha de Ingreso: febrero-2007
Mensajes: 33
Antigüedad: 17 años, 2 meses
Puntos: 0
Mensaje Re: Solo Me Quedan Unos Ultimos Pasos Para Acabar El Sudoku Me Podeis Ayudar ??

alguien sabe como convertir el boton solucion para que se junte con el de crear y de esta manera cuando pulse el boton crear salgan lo sudokus completos porfavor urgente
  #4 (permalink)  
Antiguo 20/02/2007, 12:52
Avatar de culd  
Fecha de Ingreso: noviembre-2003
Mensajes: 959
Antigüedad: 20 años, 6 meses
Puntos: 19
Re: Solo Me Quedan Unos Ultimos Pasos Para Acabar El Sudoku Me Podeis Ayudar ??

If Boton.caption = "CREAR" then
TODA LA FUNCION PARA CREAR

Boton.caption = "SOLUCION"
else
TODA LA FUNCION PARA OLUCION

Boton.caption = "CREAR"
End if

PD: Esto va dentro del boton en el evento CLICK

Creo que eso es lo que necesitas, la idea es que tengas un boton con el CAPTION de "CREAR", y haga todo lo referente a crear, y que por ultimo cambie el caption a SOLUCION... Y viseversa cuando es solucion
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:28.