From f81b98bc1cd638edbda862ffbb4ad38b796b7c76 Mon Sep 17 00:00:00 2001 From: Jonas Hruschka Date: Wed, 28 Oct 2026 17:10:44 +0100 Subject: [PATCH] finished Programm --- Startcode/game.c | 16 ++++++++-------- Startcode/main.c | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Startcode/game.c b/Startcode/game.c index f55b805..41544ad 100644 --- a/Startcode/game.c +++ b/Startcode/game.c @@ -19,12 +19,12 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi //befüllen des Arrays mit '\0' for(unsigned int i = 0; i < searchFieldLen; i++) { - for(unsigned int j = 0; j < searchFieldLen; i++) + for(unsigned int j = 0; j < searchFieldLen; j++) { salad[i][j] = '\0'; } } - + //erstellen von Richtungsvektoren int dx[] = {1, 0}; int dy[] = {0, 1}; @@ -37,7 +37,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi { return FEHLER_LAENGE_WORT; } - + int placed = 0; int attempts = 0; @@ -48,8 +48,8 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi int zeile = rand() % searchFieldLen; int spalte = rand() % searchFieldLen; - if(dir == 0 && (zeile + laenge > searchFieldLen)) - if(dir == 1 && (spalte + laenge > searchFieldLen)) + if ((dir == 0 && (zeile + laenge > searchFieldLen)) || + (dir == 1 && (spalte + laenge > searchFieldLen))) { continue; } @@ -77,7 +77,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi placed = 1; } } - + if(!placed) //überprüft ob das Wort gesetzt wurde, wenn nicht Fehlerausgabe { return FEHLER_SETZEN; @@ -89,12 +89,12 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi { for(unsigned int j = 0; j < searchFieldLen; j++) { - if(salad[i][j] == '\n') + if(salad[i][j] == '\0') { salad[i][j] = 'A' + rand() % 26; } } } - return ERFOLG; + return (int)wordCount; } diff --git a/Startcode/main.c b/Startcode/main.c index 065b5a4..7a57881 100644 --- a/Startcode/main.c +++ b/Startcode/main.c @@ -2,6 +2,7 @@ #include #include "input.h" #include "game.h" +#include #include "graphicalGame.h" #define MAX_NUMBER_OF_WORDS 100 @@ -38,10 +39,19 @@ int main(int argc, char *argv[]) // Create the word salad by placing words into grid placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); - // TODO: - // Check if all words were successfully placed - // Start the game if successful - // error message if some words couldn't be placed + if (placedWords == (int)wordCount) + { + // Alle Wörter wurden erfolgreich platziert + startGame(wordSalad, SALAD_SIZE, words, wordCount, 800); + } + else + { + // Fehler beim Erstellen des Wortsalats + fprintf(stderr, + "Fehler beim Erstellen des Wortsalats. Rueckgabewert: %d\n", + (int)placedWords); + exitCode = EXIT_FAILURE; + } } else