diff --git a/Startcode/game.c b/Startcode/game.c index ad55190..fd2ecd7 100644 --- a/Startcode/game.c +++ b/Startcode/game.c @@ -15,6 +15,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi //salad = Array das als Tabelle dient; searchFieldLEN = tatsächliche Länge des Spielfelds; words = Liste der möglichen Suchwörter; wordCount = Anzahl der Wörter in words { //1. Spielfeld salad leeren; (Leeres Feld erstellen) + srand(time(NULL)); for (unsigned int breite = 0; breite < searchFieldLen; breite++) { for (unsigned int hoehe = 0; hoehe < searchFieldLen; hoehe++) @@ -23,6 +24,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi } } //2. Wortliste word durchgehen; (Wortlängen bestimmen) + int plaziert = 0; //Wort plaziert?; for (unsigned i = 0; i < wordCount; i++) { unsigned int wortlaenge = strlen(words[i]); //Strlen gibt die länge der Zeichenkette an @@ -30,19 +32,17 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi { continue; } - if (wortlaenge > searchFieldLen); //Falls die Wörter zu lange sind gibt es eine Fehlermeldung + if (wortlaenge > searchFieldLen) //Falls das Wort zu lange ist Überspringe { - return 0; + continue;; } //3. Startpunkt für Wörter festlegen (Platzierung der Wörter) - int plaziert = 0; //Wort plaziert?; 1 = fail - srand(time(NULL)); for (unsigned int versuch = 0; versuch < MAX_RAND_TRIES_PER_WORD; versuch++) { - unsigned int x_position = srand() % searchFieldLen; //Startpunkt in x Richtung wählen - unsigned int y_position = srand() % searchFieldLen; //Startpunkt in y Richtung wählen - int richtung = srand() % 2; //Richtung festlegen; 0 = waagerecht; 1 = senkrecht + unsigned int x_position = rand() % searchFieldLen; //Startpunkt in x Richtung wählen + unsigned int y_position = rand() % searchFieldLen; //Startpunkt in y Richtung wählen + int richtung = rand() % 2; //Richtung festlegen; 0 = waagerecht; 1 = senkrecht if (richtung == 0 && wortlaenge > searchFieldLen - x_position) //Waagerecht Platz prüfen { continue; @@ -71,7 +71,8 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi } } //4. Eingabe der Wörter; (Wörter eintragen) - if (check) + printf("Test\n"); + if (!check) { for (unsigned int j = 0; j < wortlaenge; j++) { @@ -83,27 +84,24 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi { salad[y_position + j][x_position] = words[i][j]; } - plaziert = 1; - break; - } - } - if(!plaziert) - { - return 0; - } - } - //5. Freie Felder mit Zufallsbuchstaben befüllen; (leere Felder Füllen) - for (unsigned int x_position = 0; x_position < searchFieldLen; x_position++) - { - for (unsigned int y_position = 0; y_position < searchFieldLen; y_position++) - { - if (salad[y_position][x_position] == EMPTY_CHAR) - { - salad[y_position][x_position] = 'A' + srand() % 26; } - } + printf("Wort %d plaziert.\n", plaziert); + plaziert++; + break; + } } + } + //5. Freie Felder mit Zufallsbuchstaben befüllen; (leere Felder Füllen) + for (unsigned int x_position = 0; x_position < searchFieldLen; x_position++) + { + for (unsigned int y_position = 0; y_position < searchFieldLen; y_position++) + { + if (salad[y_position][x_position] == EMPTY_CHAR) + { + salad[y_position][x_position] = 'A' + rand() % 26; + } + } } //6. Endergebnis zurückgeben; (Rückgabewert) - return 1; + return plaziert; } diff --git a/Startcode/main.c b/Startcode/main.c index 3cfef84..e50f714 100644 --- a/Startcode/main.c +++ b/Startcode/main.c @@ -38,7 +38,7 @@ int main(int argc, char *argv[]) if (wordCount == placedWords) { - startGame(wordSalad, SALAD_SIZE, words, wordCount, 1000); + startGame(wordSalad, SALAD_SIZE, words, wordCount, 800); } else {