From c95c264a3ac2513871d134feac435abae0544094 Mon Sep 17 00:00:00 2001 From: Simon Wiesend Date: Fri, 31 Oct 2025 12:42:54 +0100 Subject: [PATCH 1/4] don't exit if some words couldn't be placed --- Start_Linux/main.c | 14 +++++++++----- Start_Windows/main.c | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Start_Linux/main.c b/Start_Linux/main.c index cbfdaf5..c42c079 100644 --- a/Start_Linux/main.c +++ b/Start_Linux/main.c @@ -37,17 +37,21 @@ int main(int argc, char *argv[]) placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); // Check if all words were successfully placed - // Start the game if successful // error message if some words couldn't be placed - if (placedWords < wordCount) { - fprintf(stderr, "some words couldn't be placed\n"); - exitCode = EXIT_FAILURE; + int notPlacedNum = wordCount - placedWords; + fprintf(stderr, "%d word(s) couldn't be placed\n", notPlacedNum); } // TODO: - // Start the game if successful + // correct parameters for startGame + + // Start the game if at least 1 word has been successfully placed + else if (placedWords >= 1) + { + startGame(wordSalad, 80, words, placedWords, 800); + } } else { diff --git a/Start_Windows/main.c b/Start_Windows/main.c index cbfdaf5..c42c079 100644 --- a/Start_Windows/main.c +++ b/Start_Windows/main.c @@ -37,17 +37,21 @@ int main(int argc, char *argv[]) placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); // Check if all words were successfully placed - // Start the game if successful // error message if some words couldn't be placed - if (placedWords < wordCount) { - fprintf(stderr, "some words couldn't be placed\n"); - exitCode = EXIT_FAILURE; + int notPlacedNum = wordCount - placedWords; + fprintf(stderr, "%d word(s) couldn't be placed\n", notPlacedNum); } // TODO: - // Start the game if successful + // correct parameters for startGame + + // Start the game if at least 1 word has been successfully placed + else if (placedWords >= 1) + { + startGame(wordSalad, 80, words, placedWords, 800); + } } else { From 0ee04e2b9e0bec99a27820a5f5125aae71bc2b80 Mon Sep 17 00:00:00 2001 From: Simon Wiesend Date: Fri, 31 Oct 2025 12:55:00 +0100 Subject: [PATCH 2/4] update .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b7aac8b..d5031e8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ main.o graphicalGame.o wordsalad wordsalad_initial.exe -runTests.exe \ No newline at end of file +runTests.exe +.vscode \ No newline at end of file From cbf806ae1b1e6d2f8ebd92f932e89d7b2e48c029 Mon Sep 17 00:00:00 2001 From: Simon Wiesend Date: Mon, 3 Nov 2025 19:59:25 +0100 Subject: [PATCH 3/4] sync linux folder Co-authored-by: Fabrice --- Start_Linux/game.c | 85 +++++++++++++++++++++++++++++++++------------- Start_Linux/main.c | 4 +++ 2 files changed, 66 insertions(+), 23 deletions(-) diff --git a/Start_Linux/game.c b/Start_Linux/game.c index fdd03ca..a71fcca 100644 --- a/Start_Linux/game.c +++ b/Start_Linux/game.c @@ -13,47 +13,86 @@ // 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) { - // set seed for random number generator - srand(time(NULL)); - - int r, c; + int row, col, placedWords=0; //Gesamtes Feld auf 0 setzen - for (r=0; r < searchFieldLen; r++) { - for (c=0; c < searchFieldLen; c++) { - salad [r][c] = EMPTY_CHAR; + for (row=0; row < searchFieldLen; row++) { + for (col=0; col < searchFieldLen; col++) { + salad [row][col] = EMPTY_CHAR; } } - //Wörter zufällig horizontal oder vertikal platzieren - enum Richtung {HORIZONTAL,VERTIKAL}; //0;1 - enum Richtung dir; - dir = (rand() % 2 == 0) ? HORIZONTAL : VERTIKAL; - //Schleife, die das Setzen für alle Wörter durchführt, Zufällig horizontal(0) oder vertikal(1), an zufällige Stelle - //Prüfen, ob das Wort von der Länge her ins Feld passt + //Wortlänge wird für jedes Wort erfasst + for (int w=0; w< wordCount; w++) { + const char *word = words[w]; + int wordLen = strlen(word); + if (wordLen == 0 || wordLen > searchFieldLen) { + continue; + } + int placed = 0; + + for (int tries = 0; tries < MAX_RAND_TRIES_PER_WORD && !placed; tries++) { + int dir = (rand() % 2); // 0 oder 1 zur Festlegung von vertikal oder horizontal - //Felder, in denen keine Wörter stehen, werden mit zufälligen Buchstaben befüllt - for (r=0; r < searchFieldLen; r++) { - for (c=0; c < searchFieldLen; c++) { - if (salad[r][c] == EMPTY_CHAR) { - salad [r][c] = 'A' + (rand()% 26); + row = 0; + col = 0; + + if (dir == 0) { //horizontal //Startpunkt so festlegen, dass Wort nicht aus Feld raus ragt + row = rand () % searchFieldLen; + col = rand () % (searchFieldLen - wordLen + 1); + } else { //vertikal + row = rand () % (searchFieldLen - wordLen + 1); + col = rand () % searchFieldLen; } + + int placeable = 1; + for (int i = 0; i < wordLen; i++) { //Felder ab Startpunkt werden durchgegangen und gecheckt, ob Felder auf Null sind: + // JA =>Wort wird im nächsten Schritt platziert, NEIN => Abbruch, Neuer Startpunkt wird festgelegt + if ((dir == 0 && salad[row][col + i] != EMPTY_CHAR) || (dir == 1 && salad[row + i][col] != EMPTY_CHAR)) { + placeable = 0; + break; + } + + } + + if (placeable) { //wenn es keine Überschneidungen gibt, wird Wort platziert + for (int i=0; i Date: Mon, 3 Nov 2025 20:12:14 +0100 Subject: [PATCH 4/4] set up graphical game --- Start_Linux/main.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Start_Linux/main.c b/Start_Linux/main.c index 1db8b7c..78c6363 100644 --- a/Start_Linux/main.c +++ b/Start_Linux/main.c @@ -38,23 +38,17 @@ int main(int argc, char *argv[]) // Check if all words were successfully placed // error message if some words couldn't be placed - - printf("placed words: %d\n", placedWords); - printf("word count: %d\n", wordCount); - if (placedWords < wordCount) { int notPlacedNum = wordCount - placedWords; fprintf(stderr, "%d word(s) couldn't be placed\n", notPlacedNum); + exitCode = EXIT_FAILURE; } - // TODO: - // correct parameters for startGame - - // Start the game if at least 1 word has been successfully placed - else if (placedWords >= 1) + // Start the game if all words were successfully placed + else { - startGame(wordSalad, 80, words, placedWords, 800); + startGame(wordSalad, SALAD_SIZE, words, wordCount, 800); } } else