Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Simple sudoku - Form1.frm

Form1.frm

Caricato da: Albertking82
Scarica il programma completo

  1. Dim i As Integer, j As Integer, num As Integer, c As Integer, f As Boolean, err As Integer
  2. Const val = 3
  3. Dim m(0 To val - 1, 0 To val - 1) As Integer, pc As Integer, r As Integer
  4.  
  5. Private Sub cmddel_Click()
  6. For i = 0 To 8
  7. If i <> pc Then
  8. Text1(i).Text = ""
  9. End If
  10. Next i
  11. Text1(0).SetFocus
  12. End Sub
  13.  
  14. Private Sub Cmdver_Click()
  15. For i = 0 To 8
  16.  If Text1(i).Text = "" Then
  17.     f = True
  18.     Exit For
  19.     Else
  20.     f = False
  21.  End If
  22. Next i
  23.  If f Then
  24.   MsgBox "Il sudoku non è completo!!!", vbCritical, "Non completo"
  25.   Text1(0).SetFocus
  26.   Exit Sub
  27.  End If
  28. For i = 0 To 8
  29.   row = Int(i / val)
  30.   col = i Mod val
  31.   m(row, col) = Text1(i).Text
  32.  Next i
  33.  For i = 0 To val - 1
  34.   For j = 1 To val - 2
  35.    If m(i, j) = m(i, j + 1) Then
  36.     f = False
  37.     err = err + 1
  38.     End If
  39.   Next j
  40. Next i
  41.  f = True
  42.  For j = 1 To val - 1
  43.   For i = 0 To val - 2
  44.    If m(i, j) = m(i + 1, j) Then
  45.     f = False
  46.     err = err + 1
  47.     End If
  48.   Next i
  49. Next j
  50. If f Then
  51.  MsgBox "Complimenti hai risolto correttamente il sudoku!!!", vbInformation, "Corretto"
  52.  r = MsgBox("Vuoi giocare ancora?", vbQuestion + vbYesNoCancel, "Vuoi giocare?")
  53.  If r = vbYes Then
  54.  pc = 10
  55.  Call cmddel_Click
  56.  Call Form_Load
  57.  Else
  58.  End
  59.  End If
  60.  Else
  61.  MsgBox "Il sudoku non è risolto correttamente hai commesso " & err & " errori!!!", vbInformation, "Errato"
  62. End If
  63. f = False
  64. err = 0
  65. End Sub
  66.  
  67. Private Sub Form_Load()
  68. f = False
  69. err = 0
  70. Randomize
  71.  num = Int((Rnd * val) + 1)
  72.  num2 = Int((Rnd * 8) + 1)
  73. Text1(num2).Text = num
  74. pc = num2
  75. End Sub
  76.  
  77. Private Sub Form_Unload(Cancel As Integer)
  78. Frmmain.WindowState = 0
  79. End Sub
  80.  
  81. Private Sub Text1_Change(Index As Integer)
  82. Dim n As Integer
  83. If Text1(Index).Text <> "" Then
  84. If Not IsNumeric(Text1(Index).Text) Then
  85.  Text1(Index).Text = ""
  86. Else
  87.  n = Int(Text1(Index).Text)
  88.  End If
  89.  If n > val Then
  90.   Text1(Index).Text = ""
  91.  End If
  92. End If
  93.  
  94. End Sub