diff --git a/Start_Windows/game.c b/Start_Windows/game.c index 7313aa3..8c0d46d 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -47,6 +47,34 @@ void initializeWordsalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], } +void sortWordList(char words[][MAX_WORD_LEN], unsigned int wordCount, char nullWord[MAX_WORD_LEN]) +{ + int i = 0; + int j = 0; + char wordBuffer[MAX_WORD_LEN]; + + + strcpy(wordBuffer, nullWord); + + for (j = wordCount - 1; j > 0; j--) + { + for (i = 0; i < j; i++) + { + if (strlen(words[i]) < strlen(words[j])) + { + strcpy(wordBuffer, words[j]); + strcpy(words[j], nullWord); + strcpy(words[j], words[i]); + strcpy(words[i], nullWord); + strcpy(words[i], wordBuffer); + strcpy(wordBuffer, nullWord); + } + } + } + +} + + // Choses a random Position for the current Word wordPosition choserandomPosition(unsigned int searchFieldLen, unsigned int wordLength) { @@ -156,7 +184,7 @@ void placeRandomLetters(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], // Creates the word salad by placing words randomly and filling empty spaces // returnes the number of sucessfully placed words -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 createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, unsigned int maxWordCount) { int i = 0; int j = 0; @@ -165,6 +193,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi int placedWords = 0; char nullWord[MAX_WORD_LEN]; char currentWord[MAX_WORD_LEN]; + char sortedWords[maxWordCount][MAX_WORD_LEN]; wordPosition currentWordPosition = {0,0,0}; @@ -172,16 +201,21 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi { nullWord[k] = '\0'; } - + for (k = 0; k < wordCount; k++) + { + strcpy(sortedWords[k], words[k]); + } + srand(time(NULL)); - initializeWordsalad(salad, searchFieldLen); + initializeWordsalad(salad, searchFieldLen); + sortWordList(sortedWords, wordCount, nullWord); for (i = 1; i <= wordCount; i++) { j = 0; strcpy(currentWord, nullWord); - strcpy(currentWord, words[i-1]); + strcpy(currentWord, sortedWords[i-1]); do { @@ -195,7 +229,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi placedWords += placeWord(salad, currentWordPosition, currentWord, strlen(currentWord), searchFieldLen); } } - + placeRandomLetters(salad, searchFieldLen); diff --git a/Start_Windows/game.h b/Start_Windows/game.h index 95346af..e099e3b 100644 --- a/Start_Windows/game.h +++ b/Start_Windows/game.h @@ -5,7 +5,7 @@ #define MAX_SEARCH_FIELD_LEN 100 -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 createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount, unsigned int maxWordCount); void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen); #endif diff --git a/Start_Windows/game.o b/Start_Windows/game.o index c25f5e3..d93be11 100644 Binary files a/Start_Windows/game.o and b/Start_Windows/game.o differ diff --git a/Start_Windows/input.c b/Start_Windows/input.c index f025d33..1b06ff0 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -63,7 +63,6 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) } } while (((currentChar != EOF) && (word <= maxWordCount))); - printf("wortzahl: %d\n", word); return word; } diff --git a/Start_Windows/input.o b/Start_Windows/input.o index b5b6765..06a1909 100644 Binary files a/Start_Windows/input.o and b/Start_Windows/input.o differ diff --git a/Start_Windows/main.c b/Start_Windows/main.c index 8a4809c..bb1b0d8 100644 --- a/Start_Windows/main.c +++ b/Start_Windows/main.c @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) fclose(file); // Create the word salad by placing words into grid - placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); + placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount, MAX_NUMBER_OF_WORDS); printf("placed Words: %d\n", placedWords); printf("wordCount = %d\n", wordCount); diff --git a/Start_Windows/main.o b/Start_Windows/main.o index f9bd0bc..8ae275c 100644 Binary files a/Start_Windows/main.o and b/Start_Windows/main.o differ diff --git a/Start_Windows/wordsalad.exe b/Start_Windows/wordsalad.exe index 8ec54fc..a94141a 100644 Binary files a/Start_Windows/wordsalad.exe and b/Start_Windows/wordsalad.exe differ