Oppure

Loading
23/01/10 11:14
fifiddu
sto facendo una specie di gioco a quiz, volevo sapere se utilizzando la funzione random, quest'ultima dovrebbe impedire che la stessa domanda si ripresenti, esiste un modo per evitare che in random esce sempre la stessa domanda?
vi posto il codice che sto realizzando alla quale vorrei capire come evitare il problema menzionato.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmddomanda.Click
TextBox1.Text = Int(Rnd() * 8)
Select Case TextBox1.Text
Case 0
TextBox1.Text = "Gesù era sposato?"
Case 2
TextBox1.Text = "Catania è il capoluogo della Sicilia?"
Case 3
TextBox1.Text = "Garibaldi sbarcò a Trapani?"
Case 4
TextBox1.Text = "Edison inventò la luce?"
Case 5
TextBox1.Text = "Il pianeta terra è uguale a marte?"
Case 6
TextBox1.Text = "I dinosauri sono Vegetareani?"
End Select
TextBox2.Text = ""
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsi.Click
If TextBox1.Text = "Gesù era sposato?" Then
TextBox2.Text = "Sbagliato"
Else

If TextBox1.Text = "il computer è intelligente?" Then
TextBox2.Text = "Sbagliato"

TextBox2.Text = "Sbagliato"
Else
If TextBox1.Text = "Catania è il capoluogo della Sicilia?" Then
TextBox2.Text = "Sbagliato"
Else
If TextBox1.Text = "Garibaldi sbarcò a Trapani?" Then
TextBox2.Text = "Sbagliato"
Else
If TextBox1.Text = "Edison inventò la luce?" Then
TextBox2.Text = "Sbagliato"
Else
If TextBox1.Text = "Il pianeta terra è uguale a marte?" Then
TextBox2.Text = "Sbagliato"
Else
If TextBox1.Text = "I dinosauri sono Vegetareani?" Then
TextBox2.Text = "Sbagliato"
End If
End If
End If
End If
End If
End If
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdno.Click
If TextBox1.Text = "Gesù era sposato?" Then
TextBox2.Text = "Esatto!!"
Else
If TextBox1.Text = "il computer è intelligente?" Then
TextBox2.Text = "Esatto!!"
Else
If TextBox1.Text = "Catania è il capoluogo della Sicilia?" Then
TextBox2.Text = "Esatto!!"
Else
If TextBox1.Text = "Garibaldi sbarcò a Trapani?" Then
TextBox2.Text = "Esatto!!"
Else
If TextBox1.Text = "Edison inventò la luce?" Then
TextBox2.Text = "Esatto!!"
Else
If TextBox1.Text = "Il pianeta terra è uguale a marte?" Then
TextBox2.Text = "Esatto!!"
Else
If TextBox1.Text = "I dinosauri sono Vegetareani?" Then
End If
End If
TextBox2.Text = "Esatto!!"
End If
End If
End If
End If
End If

End Sub
End Class
aaa
23/01/10 14:50
Alfonso
Guarda come si semplifica il tutto con degli array
Public Class Form1
    Dim Domande(5) As String
    Dim Risposte(5) As Boolean
    Dim DomandeGiaFatte(5) As Boolean
    Dim DomandaProposta As Integer
    Dim Fatte As Integer

 Private Sub Inizializza()

   Domande(0) = "Gesù era sposato?"
   Domande(1) = "Catania è il capoluogo della Sicilia?"
   Domande(2) = "Garibaldi sbarcò a Trapani?"
   Domande(3) = "Edison inventò la luce?"
   Domande(4) = "Il pianeta terra è uguale a marte?"
   Domande(5) = "I dinosauri sono Vegetariani?"

   Risposte(0) = False
   Risposte(1) = False
   Risposte(2) = False
   Risposte(3) = False
   Risposte(4) = False
   Risposte(5) = False

   DomandeGiaFatte(0) = False
   DomandeGiaFatte(1) = False
   DomandeGiaFatte(2) = False
   DomandeGiaFatte(3) = False
   DomandeGiaFatte(4) = False
   DomandeGiaFatte(5) = False

   Fatte = 0

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
Handles cmdDomanda.Click

    If Fatte = 6 Then TextBox1.Text = "Domande esaurite"
    Do While Fatte <= 5
       DomandaProposta = Rnd() * 5
       If DomandeGiaFatte(DomandaProposta) = False Then
          Fatte = Fatte + 1
          TextBox1.Text = Domande(DomandaProposta)
          DomandeGiaFatte(DomandaProposta) = True
          TextBox2.Text = ""
          Exit Do
       End If
    Loop

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
Handles cmdsi.Click
    If Risposte(DomandaProposta) = False Then
       TextBox2.Text = "Sbagliato"
    End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
Handles cmdno.Click
    If Risposte(DomandaProposta) = False Then
       TextBox2.Text = "Esatto!!"
    End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 

MyBase.Load
   Inizializza()
End Sub
End Class


Osserva che praticamente è già commentato.
aaa
23/01/10 15:18
fifiddu
si in effetti così e molto semplificto e funzionale, purtroppo sono alle prime armi quindi non conosco ancora molto sul linguaggio, ma volevo dirti....e se volemmo aggiungere un punteggio alle domande? per esempio un punteggio x per domanda con un visualizzatore totale dei punteggi.
aaa
23/01/10 15:27
fifiddu
tra l'altro il quiz dovrebbe permettere una sola risposta disabilitando a sua volta il pulsante successivo per non permettere una risposta successiva a quella sbagliata, nel sorgente invece si può rispondere a qualsiasi risposta generando l'esatta e la sbagliata.
aaa
23/01/10 17:03
Alfonso
Prima di tutto dovresti cambiare qualcosa.
Così com'è praticamente puoi fare solo domande sbagliate.
Per una Domanda(6) che invece fosse giusta per cui con Risposta(6)=true .... prova a modificare il codice.

Per il primo quesito:
Dichiari la variabile Punteggio come integer e
If Risposte(DomandaProposta) = False Then
   TextBox2.Text = "Sbagliato"
   Punteggio = Punteggio -1
End If

Vedi come fare per la risposta esatta.

Per il secondo quesito:
Quando premi uno dei due pulsanti Sì o No disabiliti l'altro e quando premi il pulsante domanda li abiliti entrambi.

Ragiona e prova.
Ciao
aaa
23/01/10 19:40
fifiddu
ok stasera e domani ho più tempo per ragionare csì spero di apprendere ualcosa di più, sei stato comunque gentile ciao grazie.
aaa