diff --git a/Start_Windows/game.c b/Start_Windows/game.c index 63bc37f..307b6cb 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -17,11 +17,11 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi //1. Schritt: Alle Felder mit 0 befüllen int size_word; - int placed_words = 0; + int placedWords = 0; unsigned int succesfully_placed = 0; unsigned int tries = 0; unsigned int check_direction = 0, check_overlap = 0; - int zeile, spalte; + int zeile = 0, spalte = 0, len = 0; for(int m = 0; m < searchFieldLen; m++) //m Zeilen { @@ -34,7 +34,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi // 2. Schritt: Prüfen ob Wort in Array geschrieben darf for(int num_words = 0; num_words < wordCount && num_words < searchFieldLen; num_words++) //eingelesen Wörter zählen { - size_t len = strlen(words[num_words]); //Größe des Wortes ermitteln + len = strlen(words[num_words]); //Größe des Wortes ermitteln if (len < searchFieldLen) return -1; //ERROR, falls Wort größer als Größe des Feldes (unnötig, da bei worteingabe bereits überprüft) @@ -45,29 +45,18 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi int direction = rand() % 2; // 0 = VERTIKAL, 1 = HORIZONTAL // zufälliger Startpunkt, Startkoordinaten - for(int i = 0; i < wordCount; i++) + if (direction == 0) // 0 = VERTIKAL -> Spalte egal { - if (direction == 0) // 0 = VERTIKAL -> Spalte egal - { - for(int j = 0; j < len; j++) - { - zeile = rand() % (searchFieldLen - len); - spalte = rand() % (searchFieldLen); - salad[zeile][spalte] = words[j]; - check_direction = 1; - } - } + zeile = rand() % (searchFieldLen - len); + spalte = rand() % (searchFieldLen); + check_direction = 1; + } - if (direction == 1) // 1 = HORIZONTAL -> Zeile egal - { - for(int k = 0; k < len; k++) - { - int zeile = rand() % (searchFieldLen); - int spalte = rand() % (searchFieldLen - len); - salad[zeile][spalte] = words[k]; - check_direction = 1; - } - } + if (direction == 1) // 1 = HORIZONTAL -> Zeile egal + { + int zeile = rand() % (searchFieldLen); + int spalte = rand() % (searchFieldLen - len); + check_direction = 1; } //Prüfen auf Überlappung @@ -95,19 +84,19 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi if (direction == 0) // 0 = VERTIKAL { salad[zeile + i_set][spalte] = words[num_words][i_set]; - placed_words++; + placedWords++; } if (direction == 1) // 1 = HORIZONTAL { salad[zeile][spalte + i_set] = words[num_words][i_set]; - placed_words++; + placedWords++; } } } } - return placed_words; //platzierte Wörter zurückgeben } + return placedWords; //platzierte Wörter zurückgeben } // Prints the word salad to console diff --git a/Start_Windows/main.o b/Start_Windows/main.o index 599acbb..a3de5e1 100644 Binary files a/Start_Windows/main.o and b/Start_Windows/main.o differ