0

insertion of rounds by time

I am developing a game quiz, and I would like to put that the user has a time limit to answer, but I don't know with which command or library I could do this. I think of putting something like a 'timer' and 'if' the user does not send the answer in that time to take some action

9th Jun 2020, 5:49 PM
JoĆ£o Hoffman
JoĆ£o Hoffman - avatar
5 Answers
+ 1
#include <Windows.h> Sleep( int miliseconds ); edit: as more explanation, use that sleep() in the main loop with low delay like sleep(30) (maybe?), and then increase a float variable each time that loop repeats, so you can count the time elapsed without affecting the input system.
9th Jun 2020, 6:10 PM
Mustafa K.
Mustafa K. - avatar
0
But in this case, the command will stop to execute, how can I use sleep to create rounds
9th Jun 2020, 6:12 PM
JoĆ£o Hoffman
JoĆ£o Hoffman - avatar
0
Man, thank you, you explained it well. But I'm a beginner programmer and I didn't quite understand what to do, could you give me an example ?? Appreciate :)
9th Jun 2020, 6:18 PM
JoĆ£o Hoffman
JoĆ£o Hoffman - avatar
0
JoĆ£o Hoffman What you will do is like in most games, there will be a main loop which everything will happen in it, something like that, int main() { // some declarations float time = 0; // time elapsed since game started float cooldown = 5; // time in seconds for each question float f = 0; // bla bla bla while (!gameOver) { if (time > f + cooldown) // this means, did time cooldown amount of seconds elapsed or not? { f += time; // we add the current time in seconds // U failed the question // bla bla bla } // some codes // print, input things // bla bla Sleep(10); // 10ms delay so FPS is 100 time += 10.0f / 1000.0f; } } Something like this should work
9th Jun 2020, 6:27 PM
Mustafa K.
Mustafa K. - avatar
0
Oh Gosh, now I understand everything, thanks dude.
9th Jun 2020, 6:55 PM
JoĆ£o Hoffman
JoĆ£o Hoffman - avatar