From 82fafb02fdefc597426c37220880bb44708866c8 Mon Sep 17 00:00:00 2001 From: silvana884 Date: Fri, 31 Oct 2025 09:28:41 +0100 Subject: [PATCH] Erster Entwurf des Ausfbaus vom Salat --- .gitignore | 2 ++ Start_Windows/game.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..25a7384 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +*.exe diff --git a/Start_Windows/game.c b/Start_Windows/game.c index d8cc133..820fa3a 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -10,9 +10,65 @@ /* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren * restliche Felder mit zufälligen Buchstaben füllen */ +//words und salad sind char arrays --> laengstes wort sind 100 zeichen + // 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) { + srand(time(NULL)); + for(int i = 0; i < MAX_NUMBER_OF_WORDS; i++) //geht Wortliste durch und fuellt die Woerter erstmal in salad + { + if(word[i][0] == NULL) + { + break; + } + + int rand = rand() % (wordCount - (-wordCount) + 1) - wordCount; + int value = (rand*rand) / rand; + + if(rand < 0) //wenn rand eine negative Zahl ist, soll das Wort horizontal platziert werden + { + for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++) // geht salad durch + { + if(salad[j][i] == NULL) //sucht horizontal nach einer freien Zeile in salad + { + for(int h = 0; h < MAX_SEARCH_FIELD_LEN; h++) //kopiert die Zeichen in word in die Zeile in salad + { + salad[j][h] = word[value][h]; //value ist der Wert des zufaelligen Wortes, also der Platz im word Array + } + } + } + } + else //vertikal platzieren + { + for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++) // geht salad durch + { + if(salad[i][j] == NULL) //sucht vertikal nach einer freien Zeile in salad + { + for(int h = 0; h < MAX_SEARCH_FIELD_LEN; h++) //kopiert die Zeichen in word in die Spalte in salad + { + salad[h][j] = word[value][h]; //value ist der Wert des zufaelligen Wortes, also der Platz im word Array + } + } + } + } + } + //jetzt ist die Wortliste leer oder es wurden alle Worte in Salad geschrieben. + + //Restliche Plaetze mit random Buchstaben fuellen: + int num = rand()%(26 - 1 + 1) - 1; + char letter = 64 + num; + + for(int i = 0; i < MAX_SEARCH_FIELD_LEN; i++) + { + for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++) + { + if(salad[i][j] == NULL) + { + salad[i][j] = letter; + } + } + } }