Nieuw lid |
|
Hallo,
Voor een opdracht voor school moeten wij het spelletje boter kaas en eieren in vb maken. Ik loop echter tegen een vreselijk irritante bug aan, die volgens mij met de random te maken heeft.
Ik heb een twee dimensionale array aangemaakt van 3,3, hij is dus 4 lang en 4 breed. Iets te lang, maar ik gebruik de waarden met 0 niet. Als een spel begint klikt de speler op een picturebox, de bijbehorende array waarde (in het geval van picturebox 1 de array 1,1) veranderd van 0 naar 1. Vervolgens is de computer aan de beurt, waar ik de volgende code voor heb geschreven:
Sub ComputerBeurt()
While BlnCheck = False
IntRij = RndRandom1.Next(1, 4)
IntKolom = RndRandom2.Next(1, 4)
If IntArray(IntRij, IntKolom) = 0 Then
IntArray(IntRij, IntKolom) = 1
If IntRij = 1 And IntKolom = 1 Then
PictureBox1.Image = opdracht20.My.Resources.linux
BlnCheck = True
StrBeurtCheck = ("Computer")
ElseIf IntRij = 1 And IntKolom = 2 Then
PictureBox2.Image = opdracht20.My.Resources.linux
BlnCheck = True
StrBeurtCheck = ("Computer")
ElseIf IntRij = 1 And IntKolom = 3 Then
PictureBox3.Image = opdracht20.My.Resources.linux
BlnCheck = True
StrBeurtCheck = ("Computer")
ElseIf IntRij = 2 And IntKolom = 1 Then
PictureBox4.Image = opdracht20.My.Resources.linux
BlnCheck = True
StrBeurtCheck = ("Computer")
ElseIf IntRij = 2 And IntKolom = 2 Then
PictureBox5.Image = opdracht20.My.Resources.linux
BlnCheck = True
StrBeurtCheck = ("Computer")
ElseIf IntRij = 2 And IntKolom = 3 Then
PictureBox6.Image = opdracht20.My.Resources.linux
BlnCheck = True
StrBeurtCheck = ("Computer")
ElseIf IntRij = 3 And IntKolom = 1 Then
PictureBox7.Image = opdracht20.My.Resources.linux
BlnCheck = True
StrBeurtCheck = ("Computer")
ElseIf IntRij = 3 And IntKolom = 2 Then
PictureBox8.Image = opdracht20.My.Resources.linux
BlnCheck = True
StrBeurtCheck = ("Computer")
ElseIf IntRij = 3 And IntKolom = 3 Then
PictureBox9.Image = opdracht20.My.Resources.linux
BlnCheck = True
StrBeurtCheck = ("Computer")
End If
End If
End While
BlnCheck = False
End Sub
Sub ComputerBeurt() While BlnCheck = False IntRij = RndRandom1.Next(1, 4) IntKolom = RndRandom2.Next(1, 4) If IntArray(IntRij, IntKolom) = 0 Then IntArray(IntRij, IntKolom) = 1 If IntRij = 1 And IntKolom = 1 Then PictureBox1.Image = opdracht20.My.Resources.linux BlnCheck = True StrBeurtCheck = ("Computer") ElseIf IntRij = 1 And IntKolom = 2 Then PictureBox2.Image = opdracht20.My.Resources.linux BlnCheck = True StrBeurtCheck = ("Computer") ElseIf IntRij = 1 And IntKolom = 3 Then PictureBox3.Image = opdracht20.My.Resources.linux BlnCheck = True StrBeurtCheck = ("Computer") ElseIf IntRij = 2 And IntKolom = 1 Then PictureBox4.Image = opdracht20.My.Resources.linux BlnCheck = True StrBeurtCheck = ("Computer") ElseIf IntRij = 2 And IntKolom = 2 Then PictureBox5.Image = opdracht20.My.Resources.linux BlnCheck = True StrBeurtCheck = ("Computer") ElseIf IntRij = 2 And IntKolom = 3 Then PictureBox6.Image = opdracht20.My.Resources.linux BlnCheck = True StrBeurtCheck = ("Computer") ElseIf IntRij = 3 And IntKolom = 1 Then PictureBox7.Image = opdracht20.My.Resources.linux BlnCheck = True StrBeurtCheck = ("Computer") ElseIf IntRij = 3 And IntKolom = 2 Then PictureBox8.Image = opdracht20.My.Resources.linux BlnCheck = True StrBeurtCheck = ("Computer") ElseIf IntRij = 3 And IntKolom = 3 Then PictureBox9.Image = opdracht20.My.Resources.linux BlnCheck = True StrBeurtCheck = ("Computer") End If End If End While BlnCheck = False End Sub
Hier gaat het volgens mij fout, de random komt telkens weer met hetzelfde getal aan zetten volgens mij. Het gaat 2 beurten goed, en dan loopt ie vast zonder een error melding of wat dan ook.
Wij zijn trouwens nog niet erg ver met VB, dus we gebruiken alleen simpele commandos e.d.
Edit: Het probleem is ondertussen opgelost door gewoon een eendimensionale array met de waarde van 9 te gebruiken.
|