I am very new to c++ and I was given an assignment where I was asked to make a maze. I would like to add a countdown timer to my maze but I'm not sure how or where to add it in.
As you can see, I tried using a timer code I found online. But anytime I run the game the timer either clears the maze or doesn't allow the controls to work. Help?
You can't call main() all over the place like that: Change all of those to return statements:
1 2 3 4 5
main();return;
For the timer, use the alarm(2) and signal(2) commands
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* Declare your signal handling function: *.
void Gong( int signal )
{
game_running = false;
}
/* Gong() */
/* Set up your signal handler: */
signal( SIGALRM, Gong );
/* Set your alarm for 60 seconds: */
alarm( 60 );
The problem is that while the program is waiting for input from the user, it isn't counting down the timer, so you need to make this multi-threaded: one thread will run the timer and the other will run the game.
True, that would be the best way, but you can just put in the timer without the display with the method I suggested. I thought that would be a good starting place for the OP.
@dhayden
Multithreading isn't for beginners really..
I programmed for 5 ~ +/- months, and i learn it now, because i want to do socket programming, and i SHOULD learn that.
Anyways, here is a good book for it.
530 pages, enjoy reading :)