generated from freudenreichan/info2Praktikum-Wortsalat
Rueckgabewert von createWordSalad fuer Debugging geandert
This commit is contained in:
parent
b88fa9dcef
commit
5cea6d7c4d
@ -15,16 +15,27 @@
|
||||
// Creates the word salad by placing words randomly and filling empty spaces
|
||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
||||
{
|
||||
int placedChar = 0;
|
||||
srand(time(NULL));
|
||||
|
||||
int usedWords[MAX_NUMBERS_OF_WORDS];
|
||||
for(int i=0; i< MAX_NUMBERS_OF_WORDS; i++){
|
||||
int usedWords[MAX_NUMBER_OF_WORDS];
|
||||
for(int i=0; i< MAX_NUMBER_OF_WORDS; i++){
|
||||
usedWords[i] = -1;
|
||||
}
|
||||
|
||||
fillSalad(salad, searchFieldLen, words, wordCount, usedWords);
|
||||
showWordSalad(salad, searchFieldLen);
|
||||
return 1;
|
||||
for(int i= 0; i < MAX_SEARCH_FIELD_LEN; i++)
|
||||
{
|
||||
for(int j=0; j < MAX_SEARCH_FIELD_LEN; j++)
|
||||
{
|
||||
if(salad[i][j] != '\0')
|
||||
{
|
||||
placedChar++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return placedChar;
|
||||
}
|
||||
|
||||
// Prints the word salad to console
|
||||
@ -52,7 +63,7 @@ int printHorizontal(unsigned int wordCount)
|
||||
// returns 1, when empty spaces are left
|
||||
int emptyPlaces(unsigned int wordCount)
|
||||
{
|
||||
if(wordCount < MAX_NUMBERS_OF_WORDS)
|
||||
if(wordCount < MAX_NUMBER_OF_WORDS)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@ -61,7 +72,7 @@ int emptyPlaces(unsigned int wordCount)
|
||||
|
||||
|
||||
// fills salad array with max. words from word array either horizontally or vertically
|
||||
void fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBERS_OF_WORDS])
|
||||
void fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBER_OF_WORDS])
|
||||
{
|
||||
// empties salad
|
||||
for(int i = 0; i < searchFieldLen; i++) {
|
||||
@ -133,7 +144,7 @@ void fillSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned
|
||||
}
|
||||
|
||||
|
||||
int whichWord(const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBERS_OF_WORDS])
|
||||
int whichWord(const char words[][MAX_WORD_LEN], unsigned int wordCount, int usedWords[MAX_NUMBER_OF_WORDS])
|
||||
{
|
||||
int tries = 0;
|
||||
|
||||
@ -141,7 +152,7 @@ int whichWord(const char words[][MAX_WORD_LEN], unsigned int wordCount, int used
|
||||
int numWord = rand() % wordCount; // 0..wordCount-1
|
||||
|
||||
int alreadyUsed = 0;
|
||||
for(int f = 0; f < MAX_NUMBERS_OF_WORDS; f++){
|
||||
for(int f = 0; f < MAX_NUMBER_OF_WORDS; f++){
|
||||
if(usedWords[f] == numWord){
|
||||
alreadyUsed = 1;
|
||||
break; // word already used
|
||||
@ -150,7 +161,7 @@ int whichWord(const char words[][MAX_WORD_LEN], unsigned int wordCount, int used
|
||||
|
||||
if(!alreadyUsed){
|
||||
// Eintragen in usedWords
|
||||
for(int f = 0; f < MAX_NUMBERS_OF_WORDS; f++){
|
||||
for(int f = 0; f < MAX_NUMBER_OF_WORDS; f++){
|
||||
if(usedWords[f] == -1){ // unused
|
||||
usedWords[f] = numWord;
|
||||
break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user