From 96ecac9e4ce393e02ae67e926b70b8b113e621bc Mon Sep 17 00:00:00 2001 From: ScheuerleinNico Date: Thu, 29 Oct 2026 15:59:08 +0100 Subject: [PATCH] =?UTF-8?q?Pr=C3=BCfe=20in=20main.c=20die=20input.c=20und?= =?UTF-8?q?=20game.c,=20Target=20in=20Makefile=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Startcode/main.c | 71 ++++++++++++++++------------------------------ Startcode/makefile | 13 ++++++++- 2 files changed, 37 insertions(+), 47 deletions(-) diff --git a/Startcode/main.c b/Startcode/main.c index 892fa61..b3b305f 100644 --- a/Startcode/main.c +++ b/Startcode/main.c @@ -1,6 +1,5 @@ #include #include -#include #include "input.h" #include "game.h" #include "graphicalGame.h" @@ -8,42 +7,6 @@ #define MAX_NUMBER_OF_WORDS 100 #define SALAD_SIZE 20 -int checkSalad(char words[][MAX_WORD_LEN], char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], int placedWords, int wordCount){ - //Iteriere über alle verfügbaren Wörter - int foundWords = 0; - - //suche horizontal - for(int i = 0; i < wordCount; i++){ - for(int h = 0; h < MAX_SEARCH_FIELD_LEN; h++){ - if(strstr(wordSalad[h], words[i]) != NULL){ - foundWords++; - break; - } - } - } - - //flip Board - char copySalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; - for (int i = 0; i< MAX_SEARCH_FIELD_LEN; i++){ - for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++){ - copySalad[i][j] = wordSalad[j][i]; - } - } - - // sucher vertikal - for(int i = 0; i < wordCount; i++){ - for(int h = 0; h < MAX_SEARCH_FIELD_LEN; h++){ - if(strstr(copySalad[h], words[i]) != NULL){ - foundWords++; - break; - } - } - } - - if(foundWords == placedWords) return 0; - return -1; -} - int main(int argc, char *argv[]) { int exitCode = EXIT_SUCCESS; @@ -54,10 +17,11 @@ int main(int argc, char *argv[]) fprintf(stderr, "Usage: %s \n", argv[0]); exitCode = EXIT_FAILURE; } + else { char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game - unsigned int wordCount = 0; + int wordCount = 0; FILE *file = fopen(argv[1], "r"); @@ -76,17 +40,32 @@ int main(int argc, char *argv[]) // TODO: // Check if all words were successfully placed // Start the game if successful - // error message if some words couldn't be placed + // error message if some words couldn't be placed (return input.c / game.c <=0) - int check = checkSalad(words, wordSalad, placedWords, wordCount); - //Fehlerfall - if(check != 0){ - fprintf(stderr, "Not all words could be placed!\n"); + // Prüfen, ob input.c (readWords) einen Fehler oder 0 Wörter zurückgegeben hat + if (wordCount <= 0) + { + fprintf(stderr, "Fehler: Es konnten keine Wörter eingelesen werden (input.c Rückgabewert <= 0).\n"); exitCode = EXIT_FAILURE; } - //keine Ahnung wiegroß pixelSize sein soll - startGame(wordSalad, MAX_SEARCH_FIELD_LEN, words, placedWords, MAX_SEARCH_FIELD_LEN * SALAD_SIZE); + + // Prüfen, ob game.c (createWordSalad) einen Fehler zurückgegeben hat (<= 0) oder ob nicht alle eingelesenen Wörter platziert werden konnten + else if (placedWords <= 0 || placedWords < wordCount) + { + fprintf(stderr, "Fehler: Nicht alle Wörter konnten im Wortsalat platziert werden (game.c Rückgabewert <= 0).\n"); + exitCode = EXIT_FAILURE; + } + + // Wenn alles erfolgreich war, wird das Spiel gestartet. + else + { + printf("Alle Wörter erfolgreich platziert! Starte das Spiel...\n"); + + // Übergabe an graphicalGame.c via startGame: + startGame(wordSalad, MAX_SEARCH_FIELD_LEN, words, placedWords, 400); // Parameter: (wordSalad, searchFieldSize, words, numberOfWords, windowSize) + } } + else { // Print error message if file couldn't be opened @@ -96,4 +75,4 @@ int main(int argc, char *argv[]) } return exitCode; -} \ No newline at end of file +} diff --git a/Startcode/makefile b/Startcode/makefile index 7cf1d4c..e1dca04 100644 --- a/Startcode/makefile +++ b/Startcode/makefile @@ -16,12 +16,14 @@ raylibfolder = ./raylib unityfolder = ./unity codefolder = . + # -------------------------- # initiales Spiel bauen # -------------------------- wordsalad_initial: $(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS) + # -------------------------- # Normales Spiel bauen # -------------------------- @@ -48,6 +50,8 @@ TEST_BIN = runTests test: input.o game.o $(codefolder)/unit_tests.c $(unityfolder)/unity.c $(CC) -Wall -I$(unityfolder) -o $(TEST_BIN) input.o game.o $(codefolder)/unit_tests.c $(unityfolder)/unity.c + + # -------------------------- # Clean # -------------------------- @@ -56,4 +60,11 @@ ifeq ($(OS),Windows_NT) del /f *.o *.exe else rm -f *.o wordsalad $(TEST_BIN) -endif \ No newline at end of file +endif + + +# -------------------------- +# Eigene Version bauen (Deine main.c + libwordsalad.a) +# -------------------------- +wordsalad_TMN: main.o graphicalGame.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a + $(CC) $(CFLAGS) -o wordsalad_TMN main.o graphicalGame.o -L$(BINARIES) -lwordsalad $(BINARIES)/libraylib.a $(LDFLAGS)