Public N, Volte As Integer
Const Oss = "Osserva attentamente le lettere", Dig = "Digita le lettere appena osservate nello stesso ordine in cui sono state presentate", Err1 = "Errore! Le lettere erano:", Err2 = "Sono state digitate:", Giusto = "Giusto:" & vbCrLf & "Tutte le lettere sono nell' ordine corretto", Titolo = "Test di memoria..."
Private Sub ERRORE()
Guida.Caption = Err1
Guida2.Caption = Err2
lbl1.Visible = True
lbl2.Visible = True
Ritenta.Visible = True
Ritenta.Default = True
For i = 0 To N
Sorg(i).Visible = True
Next i
End Sub
Private Sub Azzera()
Dim Risposta As VbMsgBoxResult
Volte = 0
Guida.Caption = Oss
Guida2.Caption = ""
lbl1.Visible = False
lbl2.Visible = False
N = N + 1
Me.Caption = "Livello" & N + 1 & " - " & Titolo
TM.Enabled = True
For i = 0 To 9
Mem(i).Visible = False
Mem(i).Text = ""
Sorg(i).Visible = False
Sorg(i).Caption = ""
Next i
If N = 10 Then
sbagliato = False
For i = 0 To N - 1
If Sorg(i).Caption <> Mem(i).Text Then sbagliato = True
Next i
If sbagliato = False Then
Me.Caption = Titolo
Risposta = MsgBox(String(86, "*") & vbCrLf & "Complimenti, sei riuscito a superare tutti i 10 livelli di difficoltà" & vbCrLf & "Vuoi riprovare?" & vbCrLf + Chr(10) & String(86, "*"), vbRetryCancel + vbDefaultButton1 + vbQuestion, "GAME OVER")
If Risposta = vbRetry Then cmdInizia_Click
If Risposta = vbCancel Then End
Else: ERRORE
End If
End If
End Sub
Private Sub Continua_Click()
Azzera
Continua.Visible = False
Continua.Default = False
End Sub
Private Sub cmdInizia_Click()
Randomize
N = -1
Azzera
Me.Caption = "Livello" & N + 1 & " - " & Titolo
TM.Enabled = True
cmdInizia.Visible = False
End Sub
Private Sub Mem_Change(Index As Integer)
On Error Resume Next
Dim Sbaglio As Boolean
Sbaglio = False
Mem(Index).Text = UCase(Mem(Index).Text)
If Index < N And Mem(Index).Text <> "" Then Mem(Index + 1).SetFocus
If Index = N Then
For i = 0 To N
If Mem(i).Text <> Sorg(i).Caption Then Sbaglio = True
Next i
End If
If Sbaglio = True Then ERRORE
If Index = N And Sbaglio = False Then
Guida.Caption = Giusto
Continua.Visible = True
Continua.Default = True
Guida2.Caption = ""
End If
End Sub
Private Sub Ritenta_Click()
Azzera
N = N - 1
Ritenta.Visible = False
Ritenta.Default = False
End Sub
Private Sub TM_Timer()
If N < 10 Then
If Volte <= N Then
Sorg(Volte).Caption = Chr(Int(Rnd * 25) + 65)
Sorg(Volte).Visible = True
End If
If Volte <= N + 1 Then Volte = Volte + 1
If Volte = N + 2 Then
For i = 0 To N
Sorg(i).Visible = False
Mem(i).Visible = True
Next i
Mem(0).SetFocus
Guida.Caption = ""
Guida2.Caption = Dig
TM.Enabled = False
End If
End If
End Sub