Exemple #1
0
int CheckArgs(int type, int color, int arg0, int arg1, int arg2,
 int numArgs)
{
   if (numArgs < MIN_ARGS) {
      printf("Bad formatting in first %d args.\n", MIN_ARGS);
      return 0;
   }
   
   if (!IsGoodColor(color)) {
      printf("Bad color.\n");
      return 0;
   }
   
   if (type == 'R')
      return CheckRectangle(arg0, arg1, numArgs);
   else if (type == 'E')
      return CheckEllipse(arg2, numArgs);
   else if (type == 'C')
      return CheckCircle(arg0, numArgs);
   else if (type == '!')
      return CheckExclaim(arg0, arg1, numArgs);
   else if (type == 'H' || type == 'L')
      return CheckLetter(type, arg0, arg1, arg2, numArgs);
   else {
      printf("Bad shape %c.\n", type);
      return 0;
   }
   
   return 1;
}
Exemple #2
0
main ()
{
  char input;
  int valid;
  int fails = FAILS_ALLOWED;
  unsigned int discovered = 0;
  unsigned int n;

  // Select a key.
  srand ( time (NULL) );            // Initialize random number generator
  int value = rand()%N_KEYS;        // Get random between 0 and NKEYS-1
  strcpy (key,possiblekeys[value]); // Copy key

  // Set outstring to '-' characters plus terminating null-character
  for (n=0; n<strlen(key); n++) outstring[n]='-';
  outstring[n]='\0';

  do {
	// Prompt user
    cout << "\nDiscover the secret key: " << outstring << "\n";
    cout << "Enter a letter (You may fail " << fails << " times): ";
    cin >> input; cin.ignore (100,'\n');

	// check if letter is valid
    valid = CheckLetter (input);

	// it it is valid, increase dicovered letters counter.
	// if not, decrease allowed fails
	if (valid!=0) discovered+=valid;
	else fails--;

  } while (discovered < strlen(key) && fails>0);
  // The loop ends if key is discovered or fails are exhausted.

  // Display CORRECT! only if key was discovered.
  if (discoverd == strlen(key)) cout << "CORRECT! ";

  cout "Key was '" << key <<"'.\n";
  return 0;
}
Exemple #3
0
Game(){
int i = 1, startGame = 0, wordSize, wordCounter;
startGame = InitDictionary();
char *wordChosen = ChooseRandomWord(startGame);
char *displayWord = wordChosen ,letter, *gameWord;
wordSize = ChangeWord(displayWord,gameWord);

printf("The word now looks like this: %s\n", displayWord);
printf("You have %d guesses left.\n", NumberOfTries);

while(i <= NumberOfTries){
printf("Guess a letter: ");
scanf("%c\n",&letter);
CheckLetter(gameWord,displayWord,letter,wordSize,&wordCounter);
if (wordCounter==wordSize){
printf("You guessed the word: %s\n",displayWord);
printf("You win\n");
}else{
printf("You have %d guesses left.\n", (NumberOfTries - i));
}
i++;
}
}