Пример #1
0
// ----------------------------------------------------------------------------
// takeGuess(string guessInput)
//
// Creates new guess from provided input string and then determines if guess
// was a letter or word and runs corresponding guest function.
// If guess was correct and solves puzzle returns 1, if guess was correct and
// puzzle is not solved returns 0, if guess was incorrect updates pieces of
// man and returns 0.
// ----------------------------------------------------------------------------
bool Game::takeGuess(string guessInput)
{
	// Create new guess from input
	Guess guess(guessInput);
	// Store guess in players guess list
	player.addGuess(guess);

	// Flag for any correct letters guessed
	int correct = 0;

	// If input guess length was equal to 1
	if (guess.getGuess().length() == 1)
		// Attempt to guess a letter
	if (guessLetter(guess))
		// Flag if guess was correct
		++correct;

	// If input guess length was greater than 1
	if (guess.getGuess().length() > 1)
		// Attempt to guess answer with input
	if (guessWord(guess))
		return 1;

	// If player.partialAnswerString now equals answer return 1
	if (guessWord(player.getPartialAnswerString()))
		return 1;

	// Add a piece to man if guess was incorrect
	if (!correct)
		man.addPiece();

	return 0;

}
Пример #2
0
/****************************************************************************
* Function main() is the entry point for the program.
****************************************************************************/
int main(void)
{
   char word[MAX_WORD_LEN + 1];
   unsigned wrongGuesses = 0;
   int guessedLetters[ALPHABET_SIZE] = {
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   };
   
   time_t t;
   srand((unsigned) time(&t));

   init(word);
   do
   {
      displayWord(word, guessedLetters);
      if(guessLetter(word, guessedLetters) == BAD_GUESS)
      {
         wrongGuesses +=1;
      }
      displayHangman(wrongGuesses);

   }while(isGameOver(word, guessedLetters, wrongGuesses) == GAME_CONTINUE);

   printf("\n%s%s\n", "The word was: ", word);

   return EXIT_SUCCESS;
}