From 3ab8b26e05e8727fd291e1b80109243da44f386f Mon Sep 17 00:00:00 2001 From: Lukas Dunkel Date: Wed, 28 Oct 2026 09:13:17 +0100 Subject: [PATCH 1/2] Input C. --- Startcode/input.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Startcode/input.c b/Startcode/input.c index 5c15491..7cf0a8a 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -8,5 +8,40 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + int c = 0; + int count = 0; + int letterCount = 0; + while (count < maxWordCount) + { + while ((c = fgetc(file)) != EOF) //Leerzeichen prüfen + { + if (isspace(c) || !isalpha(c)) { + if (letterCount > 0) { + break; //Wort fertig eingelesen + } + + continue; // mehrere Leerzeichen oder Sonderzeichen überspringen + } + + if (letterCount < MAX_WORD_LEN - 1) //wörter Buchstabenweise einlesen + { + words[count][letterCount] = (char)toupper(c); + letterCount++; + } + } + + if (letterCount == 0) { + break; //kein weiteres Wort gefunden + } + + words[count][letterCount] = '\0'; + letterCount = 0; + count++; + + if (c == EOF) { + break; + } + } + return count; +} -}dhckhdkfhdjf \ No newline at end of file From bfef59e0a65066d3896d55be53698bf52f5daad9 Mon Sep 17 00:00:00 2001 From: Markus Schreiber Date: Wed, 28 Oct 2026 10:24:13 +0100 Subject: [PATCH 2/2] Implementierung von game.c --- Startcode/game.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/Startcode/game.c b/Startcode/game.c index 803301f..414d094 100644 --- a/Startcode/game.c +++ b/Startcode/game.c @@ -11,7 +11,57 @@ * restliche Felder mit zufälligen Buchstaben füllen */ // 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) +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 placedWords = 0; -} + // 1. Spielfeld leeren + for (unsigned int i = 0; i < searchFieldLen; i++) { + for (unsigned int j = 0; j < searchFieldLen; j++) { + salad[i][j] = EMPTY_CHAR; + } + } + + // 2. Alle Wörter durchlaufen + for (unsigned int i = 0; i < wordCount; i++) { + + size_t wordLen = strlen(words[i]); + + // Leere oder zu lange Wörter überspringen + if (wordLen == 0 || wordLen > searchFieldLen) { + continue; + } + + // 3. Platzierungsversuche + for (int attempt = 0; + attempt < MAX_RAND_TRIES_PER_WORD; + attempt++) { + unsigned int row = rand() % searchFieldLen; + unsigned int col = rand() % searchFieldLen; + int direction = rand() % 2; + int canPlace = 1; + + // 4. Horizontale Platzierung prüfen + if (direction == 0) { + + if (col + wordLen > searchFieldLen) { + continue; + } + + for (size_t j = 0; j < wordLen; j++) { + + if (salad[row][col + j] != EMPTY_CHAR && + salad[row][col + j] != words[i][j]) { + + canPlace = 0; + break; + } + } + } + + + // 5. Vertikale Platzierung prüfen