예제 #1
0
/**
 * Emit a signal to the main gui thread to show a question box.
 * @param question   the text of the question
 * @return   the code of the answer button @ref KMessageBox::ButtonCode
 */
int CodeImpThread::emitAskQuestion(const QString& question)
{
    int buttonCode = 0;
    //QMutexLocker locker(&m_mutex);
    emit askQuestion(question, buttonCode);
    //m_waitCondition.wait(&m_mutex);
    return buttonCode;
}
예제 #2
0
파일: main.c 프로젝트: jendter/2PlayerMath
int main(int argc, const char * argv[]) {
    // ask for player 1's name and player 2's name
    
    printf("Player 1's name? ");
    fgets(player1.name, 255, stdin);
    
    printf("Player 2's name? ");
    fgets(player2.name, 255, stdin);
    
    // initialize player 1 and player 2's lives (use function "setupNewGame")
    setupNewGame();
    
    
    
    // start game loop
    
    while (playingGame == true) {
        
        //askQuestion(playersTurn);
        
        if(askQuestion(playersTurn)) {
            // Question was answered correctly
            if (playersTurn == 1) {
                player1.score++;
            } else if (playersTurn == 2) {
                player2.score++;
            }
            printf("Right! \n");
        } else {
            // Question was answered incorrectly
            printf("Nope! \n");
            
            // Remove a life
            if (playersTurn == 1) {
                player1.lives--;
                printf("Player 1 Lives = %d \n", player1.lives);
            } else if (playersTurn == 2) {
                player2.lives--;
                printf("Player 2 Lives = %d \n", player2.lives);
            }
            
            printf("Player 1 Score = %d \nPlayer 2 Score = %d \n", player1.score, player2.score);
        }
        
        if (playersTurn == 1) {
            playersTurn++;
        } else {
            playersTurn = 1;
        }
        
        if (player1.lives == 0 || player2.lives == 0) {
            endGame();
        }
        
    }
    
    return 0;
}
예제 #3
0
bool cli::framework::YesNoPrompt::prompt(const std::string &message) const
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	std::string question = buildQuestion(message);
	askQuestion(question);
	std::string answer = getAnswer();
	return isAnswerCorrect(answer);
}
예제 #4
0
int Environment::askTimedQuestion(char *fTitle, char *fText, int fTimeout, int fDefault)
{
  Element *fQuestionBackground;
  Element *fQuestionText;
  Element *fQuestionTitle;
  Element *fQuestionTimer;

  char buf[255];
  char *fTimerText;

  FontResource *tFont;

  if (fDefault == -1 || fTimeout <= 0) {
    return askQuestion(fTitle, fText);
  }

  fQuestionBackground = mElements->getElementByContent(CONTENT_QUESTIONBACKGROUND, mMenu->getSkinID());
  fQuestionText = mElements->getElementByContent(CONTENT_QUESTIONTEXT, mMenu->getSkinID());
  fQuestionTitle = mElements->getElementByContent(CONTENT_QUESTIONTITLE, mMenu->getSkinID());
  fQuestionTimer = mElements->getElementByContent(CONTENT_QUESTIONTIMER, mMenu->getSkinID());

  fTimerText = mDialog->getValue("TimerText");


  mController->setState(Ctrl_A, Button_Released);
  mController->setState(Ctrl_B, Button_Released);
  mController->setState(Ctrl_Y, Button_Released);

  SDL_Event event;
#ifdef ENABLE_XBOX
  int start = XGetTickCount();
#else
  int start = SDL_GetTicks();
#endif
  int now;

  while (mController->getState(Ctrl_A) == Button_Released &&
      mController->getState(Ctrl_B) == Button_Released &&
      mController->getState(Ctrl_Y) == Button_Released) {
#ifdef WINDOWS
    while (SDL_PollEvent(&event)) {
      mController->update(&event);
    }
#endif

#ifdef ENABLE_XBOX    
    now = XGetTickCount();
#else
    now = SDL_GetTicks();
#endif

    if (now - start > (fTimeout*1000)) {
      return fDefault;
    }

    renderScreen();

    if (fQuestionBackground) {
      fQuestionBackground->drawImage(mScreen);
    }

    if (fQuestionTitle) {
      fQuestionTitle->drawText(fTitle, mScreen);
    }

    if (fQuestionText) {
      fQuestionText->drawText(fText, mScreen);
    }

    if (fQuestionTimer && fTimerText) {
      sprintf(buf, fTimerText, fTimeout - ((int) (now - start) / 1000));
      fQuestionTimer->drawText(buf, mScreen);
    }

    SDL_Flip(mScreen);

#ifdef ENABLE_XBOX
    XSleep(30);
#else       
    SDL_Delay(30);
#endif
  }
  if (mController->getState(Ctrl_A) == Button_Pressed) {
    return 1;
  } else {
    return 0;
  }

}