示例#1
0
/* get the nth letter for the current round */
static void get_letter(int n) {
  char *line;
  int i;

  while(1) {
    printf("vowel or consonant? [vc] ");
    line = get_line();

    if(tolower(*line) == 'v') {
      letter[n] = get_vowel();
      break;
    } else if(tolower(*line) == 'c') {
      letter[n] = get_consonant();
      break;
    }

    /* TODO: limitations on amounts of vowels and consonants */
  }

  if(nocolour) printf("| ");
  else printf("%s ", letter_colour);

  for(i = 0; i < num_letters; i++) {
    printf("%c ", (i <= n ? letter[i] : ' '));
  }

  if(nocolour) printf("|\n");
  else printf("%s\n", colour_off);
}
示例#2
0
char* generate_word(const unsigned max_word_length)
{
  unsigned i,
           word_length = rand() % max_word_length + MIN_WORD_LENGHT,
           is_consonant = dice_roll(2);
  char* word = calloc(word_length + 2, sizeof(char)); // 2 = space + null

  for (i = 0; i < word_length; ++i)
  {
    if ((!is_consonant && dice_roll(5)) || is_consonant || 1 == word_length)
    {
      word[i] = get_vowel();
      is_consonant = 0;
      continue;
    }

    word[i] = get_consonant();
    is_consonant = 1;
  }

  word[word_length] = ' ';
  return word;
}