Hi
I'm making a small game and I need a way to give the player 1 second to press 'g' (and maybe 'enter' afterwards).
/*I use Borland 2006 and I code in a mix of C and C++*/
/*I'm compiling it to be a simple .exe file*/
Here's what I've done:
I found 2 fonction to give me time.
wait();
or
sleep();
I can use them correctly.
I've tried many different variations of the same concept:
/*not actual code*/
1 2 3 4 5 6 7
|
cout<<"g"; //to let the user know I want the caracter 'g'
wait(1 second);
cin>>x;
if x == what I want
A();
else
B();
|
The problem is that whether I use cin, getchar, or scanf the computer always waits for the input.
My idea was to wait, then if x = g do A if not, do B. But I want to force the user to input g while the program is waiting.
Is there a function that gives you a certain amount of time to input a value?
Or a way to time out a function like getchar?
A maybe a way to count the time it takes to input 'g',then comparing the time to a value to decide if it was fast enough?
Or anything else ?
Thanks