diff --git a/Start_Windows/game.c b/Start_Windows/game.c index 1688bff..3f40b9b 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -31,12 +31,28 @@ typedef struct } wordPosition; +void initializeWordsalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) +{ + int i = 0; + int j = 0; + + + for (i = 0; i < searchFieldLen; i++) + { + for (j = 0; j < searchFieldLen; j++) + { + salad[i][j] = '='; + } + } +} + + // Choses a random Position for the current Word wordPosition choserandomPosition(unsigned int searchFieldLen, unsigned int wordLength) { wordPosition position = {0, 0, 0}; - srand(time(NULL)); + //srand(time(NULL)); position.alignment = rand()%(VERTIKAL - HORIZONTAL + 1) + HORIZONTAL; position.rowOrColumn = rand()%(searchFieldLen); position.startingCell = rand()%(searchFieldLen - wordLength); @@ -123,11 +139,9 @@ void placeRandomLetters(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], int j = 0; - srand(time(NULL)); - for (i = 0; i < searchFieldLen; i++) { - for (j = 0; i < searchFieldLen; j++) + for (j = 0; j < searchFieldLen; j++) { if ((salad[i][j] < 'A') || (salad[i][j] > 'z') || ((salad[i][j] < 'a') && (salad[i][j] > 'Z'))) { @@ -149,9 +163,12 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi char currentWord[MAX_WORD_LEN]; wordPosition currentWordPosition = {0,0,0}; + srand(time(NULL)); + initializeWordsalad(salad, searchFieldLen); for (i = 1; i <= wordCount; i++) { + j = 0; do { currentWordPosition = choserandomPosition(searchFieldLen, strlen(words[i])); @@ -165,7 +182,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi placedWords += placeWord(salad, currentWordPosition, currentWord, strlen(currentWord), searchFieldLen); } } - + showWordSalad(salad, searchFieldLen); placeRandomLetters(salad, searchFieldLen); @@ -182,7 +199,7 @@ void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], for (i = 0; i < searchFieldLen; i++) { - for (j = 0; i < searchFieldLen; j++) + for (j = 0; j < searchFieldLen; j++) { printf("%c", salad[i][j]); } diff --git a/Start_Windows/game.o b/Start_Windows/game.o index 06f91b3..1b664f5 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 ddb59b8..861ec35 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -29,7 +29,7 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) int wordChar = 0; char currentChar = 0; - + do { currentChar = fgetc(file); @@ -62,9 +62,9 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) currentlyInWord = 0; } - } while ((currentChar != EOF) && (word < 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 37206ff..b5b6765 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 41926b2..8a4809c 100644 --- a/Start_Windows/main.c +++ b/Start_Windows/main.c @@ -43,6 +43,8 @@ int main(int argc, char *argv[]) // Create the word salad by placing words into grid placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); + printf("placed Words: %d\n", placedWords); + printf("wordCount = %d\n", wordCount); // DONE: // Check if all words were successfully placed // Start the game if successful diff --git a/Start_Windows/main.o b/Start_Windows/main.o index e62d006..f9bd0bc 100644 Binary files a/Start_Windows/main.o and b/Start_Windows/main.o differ diff --git a/Start_Windows/wordsalad_myversion.exe b/Start_Windows/wordsalad_myversion.exe index 5069f8a..9bf18cc 100644 Binary files a/Start_Windows/wordsalad_myversion.exe and b/Start_Windows/wordsalad_myversion.exe differ