Hi guys
I have a problem with programming a small game. The idea is that a question pops up, a timer starts to run randomly from one to a given number (that number I take from a database, every question has a different allowed time to "think"), when the timer ends, a random computer opponent between 1 and 2 answers the question randomly correct or incorrect. If the user presses a button, the timer stops, lets the user answer correct or incorrect.
If it's correct, a new question pops up. If incorrect, the timer resets but the player that made an incorrect answer is no longer allowed to participate for that question.
Now, with the following code I seem to end up in an endless loop (I only put down the relevant code):
Code for the timer:
Code for the game:
I have a problem with programming a small game. The idea is that a question pops up, a timer starts to run randomly from one to a given number (that number I take from a database, every question has a different allowed time to "think"), when the timer ends, a random computer opponent between 1 and 2 answers the question randomly correct or incorrect. If the user presses a button, the timer stops, lets the user answer correct or incorrect.
If it's correct, a new question pops up. If incorrect, the timer resets but the player that made an incorrect answer is no longer allowed to participate for that question.
Now, with the following code I seem to end up in an endless loop (I only put down the relevant code):
Code for the timer:
Code:
Private Sub Form_Timer() Static intCounter As Integer intCounter = intCounter + 1 If intStop = 3 Then 'so when the user presses the button (the code for pressing the button is simply intStop = 3 on click) Me.TimerInterval = 0 intCounter = 0 End If If intCounter = intSeconden Then 'when the timer hits the max allowed seconds for the user to hit his button Me.TimerInterval = 0 intCounter = 0 intStop = Int((2 - 1 + 1) * Rnd + 1) 'randomizes which computer will answer End If
Code:
Set rsVragen = db.OpenRecordset("SELECT VraagNr, Vraag, Seconden, Categoriecode, Randomizer(VraagNr) FROM tblVragen WHERE categoriecode = '" & strCategorie & "' ORDER BY Randomizer(VraagNr)") 'Selects the questions out of a database intSeconden = Int((rsVragen.Fields(2) - 1 + 1) * Rnd + 1) 'randomizes the time given before the computer answers. Me.TimerInterval = 1000 'sets the timer to tick every second. Do Until intStop = 1 or intStop = 2 Or intstop = 3 Loop 'Probably where the mistake is, I try to make the game "wait" until the timer reached the end or the user pressed the button Select Case intStop Case 1 intGoedSlecht = Int((2 - 1 + 1) * Rnd + 1) 'randomizes whether the first computer's answer is right or wrong Case 2 same thing here for comp 2 Case 3 here I have a working program to determine of the user's answer is correct or false End select
Comment