I have done a memory tiles program but i want it to be timed, i.e, the user shoud be able to play the game only for 2 mins. what do i do?
Also in linux sleep() does not work, what should we use for a delay??
I have done a memory tiles program but i want it to be timed, i.e, the user shoud be able to play the game only for 2 mins. what do i do?
Also in linux sleep() does not work, what should we use for a delay??
I presume the game has a "main loop" somewhere.
At the beginning of the main loop (before the actual loop), take the current time, call this
start_time
. Then in each iteration of the loop, take the current time again, call thisnow
. The elapsed time iselapsed_time = now - start_time;
. Assuming time is in seconds, thenif (elapsed_time >= 120) { ... end game ... }
would do the trick.