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
5 Respostas
+ 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.
0
But in this case, the command will stop to execute, how can I use sleep to create rounds
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 :)
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
0
Oh Gosh, now I understand everything, thanks dude.