From e20fe389419dfb03f748496c341eb2d7b14b4063 Mon Sep 17 00:00:00 2001 From: Jana Hulwa Date: Tue, 13 Oct 2026 15:21:18 +0200 Subject: [PATCH 1/3] Hannes statt Zombie --- Startcode/words.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Startcode/words.txt b/Startcode/words.txt index 58398d0..49dee1f 100644 --- a/Startcode/words.txt +++ b/Startcode/words.txt @@ -2,4 +2,4 @@ Yeti,Nessie Werwolf; Vampir Monster Hydra;Frankenstein Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist -Gespenst, Oger, Zombie \ No newline at end of file +Gespenst, Oger, Hannes \ No newline at end of file From ae6116e58315da9c5d68a35de6db8cadaafeae4a Mon Sep 17 00:00:00 2001 From: Johannes Sandner Date: Mon, 26 Oct 2026 09:56:21 +0100 Subject: [PATCH 2/3] Input file erstellt --- Startcode/input.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Startcode/input.c b/Startcode/input.c index ed77805..06c7639 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -8,5 +8,51 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + int c; + unsigned int i = 0; // Wort + unsigned int j = 0; // Zeichen im Wort + while ((c = fgetc(file)) != EOF) + { + if (c == ',' || c == ';' || c == '\n' || c == ' ') + { + if (j > 0) + { + words[i][j] = '\0'; + i++; + j = 0; + + if (i >= maxWordCount) + { + break; + } + } + } + else + { + // Auf Pufferüberlauf im Wort achten + if (j < MAX_WORD_LEN - 1) + { + words[i][j] = (char)toupper(c); + j++; + } + } + } + + // Ans Ende \0 hinzufügen + if (j > 0 && i < maxWordCount) + { + words[i][j] = '\0'; + i++; + } + + // MIT CHAT GEMACHT ZUR KONTROLLE: Konsolenausgabe zur Kontrolle der eingelesenen Wörter + printf("Eingelesene Wörter (%u Stück):\n", i); + for (unsigned int idx = 0; idx < i; idx++) + { + printf("%u. Entry: %s\n", idx + 1, words[idx]); + } + + + return i; } \ No newline at end of file From 271803f9eceed096ed2070dd54e12f6b33aeb6e2 Mon Sep 17 00:00:00 2001 From: Jana Hulwa Date: Mon, 26 Oct 2026 12:23:52 +0100 Subject: [PATCH 3/3] game.c komplett fertig --- Startcode/game.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 2 deletions(-) diff --git a/Startcode/game.c b/Startcode/game.c index 803301f..80b98d2 100644 --- a/Startcode/game.c +++ b/Startcode/game.c @@ -2,16 +2,148 @@ #include #include #include +#include //für toupper #define MAX_RAND_TRIES_PER_WORD 10 #define EMPTY_CHAR 0 -//TODO: Spiellogik implementieren: +// TODO: Spiellogik implementieren: /* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren - * restliche Felder mit zufälligen Buchstaben füllen */ + * restliche Felder mit zufälligen Buchstaben füllen */ // Creates the word salad by placing words randomly and filling empty spaces + +void fillArrayEmpty(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen); +void generateCoordinates(unsigned int searchFieldLen, int *platzierung, int *xKoord, int *yKoord); +int placeWords(unsigned int searchFieldLen, const char *wort, int platzierung, int xKoord, int yKoord, char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]); +void fillRandLetters(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen); + int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount) { + fillArrayEmpty(salad, searchFieldLen); + + srand((unsigned int)time(NULL)); + int numberWords = 0; + for (unsigned int i = 0; i < wordCount; i++) + { + + const char *wort = 0; + wort = words[i]; + + for (int k = 0; k < MAX_RAND_TRIES_PER_WORD; k++) + { + int platzierung = 0; + int xKoord = 0; + int yKoord = 0; + int success = 0; + + generateCoordinates(searchFieldLen, &platzierung, &xKoord, &yKoord); + success = placeWords(searchFieldLen, wort, platzierung, xKoord, yKoord, salad); + + if (success != 0) + { + numberWords++; + break; + } + } + } + + fillRandLetters(salad, searchFieldLen); + + return numberWords; +} + +void fillArrayEmpty(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) +{ + for (unsigned int i = 0; i < searchFieldLen; i++) + { + for (unsigned int j = 0; j < searchFieldLen; j++) + { + salad[i][j] = EMPTY_CHAR; + } + } +} + +void generateCoordinates(unsigned int searchFieldLen, int *platzierung, int *xKoord, int *yKoord) +{ + *platzierung = (unsigned int)rand() % 2; // 0=Horizont.; 1=Vertik. + *xKoord = (unsigned int)rand() % searchFieldLen; + *yKoord = (unsigned int)rand() % searchFieldLen; +} + +int placeWords(unsigned int searchFieldLen, const char *wort, int platzierung, int xKoord, int yKoord, char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]) +{ + + if (platzierung == 0) // Horizontal + { + size_t len = strnlen(wort, MAX_WORD_LEN); + + if ((size_t)xKoord + len > searchFieldLen) //Addition da unsigned int + { + return 0; + } + + for (size_t j = 0; j < len; j++) + { + char c = salad[yKoord][xKoord + j]; + char w = (char)toupper((unsigned char)wort[j]); //Umwandlung in Großbuchstaben + if (c != EMPTY_CHAR && c != w) + { + return 0; + } + } + + for (size_t j = 0; j < len; j++) + { + salad[yKoord][xKoord + j] = (char)toupper((unsigned char)wort[j]); //Umwandlung in Großbuchstaben + } + + return 1; + } + + else if (platzierung == 1) // Vertikal (analog zu Horizontal) + { + size_t len = strnlen(wort, MAX_WORD_LEN); + + if ((size_t)yKoord + len > searchFieldLen) + { + return 0; + } + + for (size_t j = 0; j < len; j++) + { + char c = salad[yKoord + j][xKoord]; + char w = (char)toupper((unsigned char)wort[j]); + if (c != EMPTY_CHAR && c != w) + { + return 0; + } + } + + for (size_t j = 0; j < len; j++) + { + salad[yKoord + j][xKoord] = (char)toupper((unsigned char)wort[j]); + } + + return 1; + } + else + { + return 0; + } +} + +void fillRandLetters(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) +{ + for (unsigned int i = 0; i < searchFieldLen; i++) + { + for (unsigned int j = 0; j < searchFieldLen; j++) + { + if (salad[i][j] == EMPTY_CHAR) + { + salad[i][j] = (unsigned int)rand() % 26 + 'A'; // Assci A=65='A', Z=90 + } + } + } }