Timed memory tiles game. now works without timing

43 views Asked by At

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??

1

There are 1 answers

0
Mats Petersson On

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 this now. The elapsed time is elapsed_time = now - start_time;. Assuming time is in seconds, then if (elapsed_time >= 120) { ... end game ... } would do the trick.