Monday, July 27, 2009

How do i put a timer in a loop in c language?

how do i put a timer in a loop in c language?I want to make a chess game that has timer the game is in a loop for it to move but how can i make the timer move even if the loop doesnt move or if i dont make a move?

How do i put a timer in a loop in c language?
If you're programming on the Windows platform, then you can have the game thread enter a sleep-wait using the Sleep Windows API, passing a minimum sleep time in milliseconds.





The problem with that approach is that if you try to move in the meantime your now sleeping thread won't notice (until it wakes up). Ideally, you'd have the game logic running on a different thread than the process thread and have the game thread waiting on an event while it waits for you to make a move. The process thread could then signal the game thread to wake up if/when you make a move.





Good luck.
Reply:Use the DOS INT 1C timer tick interrupt. It ticks every 18.2mS.
Reply:Use Delay function..,.. delay(); Go to help page of delay function to know more about it to make it use with suitable parameters...


No comments:

Post a Comment