Verifique si el usuario ingresa el valor dentro de X tiempo usando C ++

I'm making a game and I want to have a timer that runs in the background. If the user does not enter anything within the provided time limit then they lose.

I already have the timer and separate threads working properly, however, I am unsure as to how I can have the program check if the user provided a value for the input. If the user did not enter anything then the timer should continue to countdown until the time runs out, at which point the program exits.

I envision the pseudo-code something like this:

do
{
    CheckIfUserInputs;

    //skip this if there is no input
    if(UserInput == WinningPhrase)
    {
        cout<< "You win\n";
        PlayerWon = true;
    }
}while((time > 0) && (PlayerWon != true));

preguntado el 04 de julio de 12 a las 03:07

You haven't specified a lot: 1) Platform?, 2) Console or GUI?, 3) What libraries are you using? Please be more concrete. -

1 Respuestas

Creo que quieres cin.eof(). Should return -1 if there isn't anything.

Respondido 04 Jul 12, 04:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.