diff --git a/Start_Linux/.vscode/settings.json b/Start_Linux/.vscode/settings.json new file mode 100644 index 0000000..c2550fb --- /dev/null +++ b/Start_Linux/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "input.h": "c" + } +} \ No newline at end of file diff --git a/Start_Linux/game.c b/Start_Linux/game.c index cc9839e..f7faa22 100644 --- a/Start_Linux/game.c +++ b/Start_Linux/game.c @@ -17,11 +17,11 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi { srand(time(NULL)); Position position[(2 * MAX_SEARCH_FIELD_LEN * (MAX_SEARCH_FIELD_LEN - MIN_WORD_LEN + 1))]; //Positionsarray Größe: Formel max. nötige Größe (für minimal großes wort) - int gesetzteWörter = 0; + int gesetzteWoerter = 0; clearWordSalad(salad, searchFieldLen); - gesetzteWörter = fuelleSalatMitWörtern(salad, searchFieldLen, words, position, wordCount); + gesetzteWoerter = fuelleSalatMitWoertern(salad, searchFieldLen, words, position, wordCount); fillWordsaladRand(salad, searchFieldLen); - return gesetzteWörter; + return gesetzteWoerter; } // Prints the word salad to console @@ -140,43 +140,43 @@ int findPossiblePositions(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN] //Nun muss für jedes Wort per zufall ausgesucht werden Wo es beginnt und welche richtung aus //den ganzen möglichen fällen und dann das wort ins grid gezeichnet werden. -int fuelleSalatMitWörtern(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], Position position[], unsigned int wordcount) +int fuelleSalatMitWoertern(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], Position position[], unsigned int wordcount) { - int gesetzteWörter = 0; + int gesetzteWoerter = 0; int positionsamount; - int positiongewählt; + int positiongewaehlt; const char *word; for(int i = 0; i < wordcount; i++) //jedes Wort. { positionsamount = findPossiblePositions(salad, searchFieldLen, words, i, position); //für dieses Wort werden die Positionen gefunden if(positionsamount > 0)//es gibt Positionen { - gesetzteWörter++; - positiongewählt = rand() % positionsamount; //die wie vielte Position des Positionsarrays für dieses Wort wir nehmen - if(position[positiongewählt].richtung == RECHTS) + gesetzteWoerter++; + positiongewaehlt = rand() % positionsamount; //die wie vielte Position des Positionsarrays für dieses Wort wir nehmen + if(position[positiongewaehlt].richtung == RECHTS) { word = words[i]; - int p = position[positiongewählt].x; + int p = position[positiongewaehlt].x; int t = 0; for(int k = p; k < p + strlen(word); k++) { - salad[position[positiongewählt].y][k] = word[t]; + salad[position[positiongewaehlt].y][k] = word[t]; t++; } } - if(position[positiongewählt].richtung == UNTEN) + if(position[positiongewaehlt].richtung == UNTEN) { word = words[i]; - int up = position[positiongewählt].y; + int up = position[positiongewaehlt].y; int ut = 0; for(int uk = up; uk < up +strlen(word); uk++) { - salad[uk][position[positiongewählt].x] = word[ut]; + salad[uk][position[positiongewaehlt].x] = word[ut]; ut++; } } } } - return gesetzteWörter; + return gesetzteWoerter; } \ No newline at end of file diff --git a/Start_Linux/game.h b/Start_Linux/game.h index 531c24b..62d6ead 100644 --- a/Start_Linux/game.h +++ b/Start_Linux/game.h @@ -20,7 +20,7 @@ void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], void clearWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen); void fillWordsaladRand(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen); int findPossiblePositions(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], int wordidx, Position positions[]); -int fuelleSalatMitWörtern(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], Position position[], unsigned int wordcount); +int fuelleSalatMitWoertern(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], Position position[], unsigned int wordcount); #endif diff --git a/Start_Linux/game.o b/Start_Linux/game.o new file mode 100644 index 0000000..d2755cf Binary files /dev/null and b/Start_Linux/game.o differ diff --git a/Start_Linux/goofywords.txt b/Start_Linux/goofywords.txt new file mode 100644 index 0000000..d4e2e13 --- /dev/null +++ b/Start_Linux/goofywords.txt @@ -0,0 +1,2 @@ +dartgoblin, haughrida, royal_knight, larry, +larry_king, heheheha, huhui, schere, grrrrrr diff --git a/Start_Linux/graphicalGame.o b/Start_Linux/graphicalGame.o new file mode 100644 index 0000000..aee2b7b Binary files /dev/null and b/Start_Linux/graphicalGame.o differ diff --git a/Start_Linux/input.c b/Start_Linux/input.c index ed77805..4b9b6df 100644 --- a/Start_Linux/input.c +++ b/Start_Linux/input.c @@ -1,12 +1,45 @@ + +//erstellt von Harun Faizi am 01.11.2025 #include "input.h" #include -#include +#include // Wichtig für toupper() +#include -// TODO: -// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt. - -// Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + if (file == NULL) + return 0; // Sicherheitsprüfung, also wurde ein File gefunden + char line[MAX_LINE_LEN]; // Puffer für eine Zeile aus Datei + unsigned int wordCount = 0; // zählt die gefundenen Wörter + + // Lese Datei Zeile für Zeile + while(fgets(line, sizeof(line), file) != NULL) + { + // Zerlege die Zeile in Wörter anhand der Trennzeichen + char *token = strtok(line, ".,; \t\n"); + + while (token != NULL && wordCount < maxWordCount) + { + // Kopiere das aktuelle Token ins Array und sichere Nullterminierung + strncpy(words[wordCount], token, MAX_WORD_LEN - 1); + words[wordCount][MAX_WORD_LEN - 1] = '\0'; + + // --- HINZUGEFÜGT --- + // Wandle das gesamte Wort in Großbuchstaben um + for(int i = 0; words[wordCount][i] != '\0'; i++) + { + words[wordCount][i] = toupper(words[wordCount][i]); + } + // --- ENDE HINZUGEFÜGT --- + + wordCount++; + token = strtok(NULL, ".,; \t\n"); // nächstes Token + } + + if (wordCount >= maxWordCount) + break; + } + + return wordCount; } \ No newline at end of file diff --git a/Start_Linux/input.o b/Start_Linux/input.o new file mode 100644 index 0000000..c6ffce1 Binary files /dev/null and b/Start_Linux/input.o differ diff --git a/Start_Linux/main.c b/Start_Linux/main.c index 2a2ea2b..394ea30 100644 --- a/Start_Linux/main.c +++ b/Start_Linux/main.c @@ -38,8 +38,7 @@ int main(int argc, char *argv[]) if(placedWords == wordCount) //Checks if all words were placed { - startGame(wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], SALAD_SIZE, words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN], placedWords, 800); - } + startGame(wordSalad, SALAD_SIZE, words, placedWords, 800); } else { printf("Error. Out of %d words just %d words could be placed.\n", wordCount, placedWords); diff --git a/Start_Linux/main.o b/Start_Linux/main.o new file mode 100644 index 0000000..37c2337 Binary files /dev/null and b/Start_Linux/main.o differ diff --git a/Start_Linux/makefile b/Start_Linux/makefile index b6a19ba..b328836 100644 --- a/Start_Linux/makefile +++ b/Start_Linux/makefile @@ -1,17 +1,17 @@ -CC = gcc # Compiler-Variable: welcher C-Compiler genutzt wird (hier gcc) -CFLAGS = -g -Wall -I$(raylibfolder) # -Wall -> alle wichtigen Warnungen aktivieren, -I : suche dort (raylibfolder) nach datei. -LDFLAGS = -lGL -lX11 -lm # Linker-Flags: Bibliotheken, die an das Linker-Kommando übergeben werden +CC = gcc +CFLAGS = -g -Wall -I$(raylib_folder) # <- KORRIGIERT +LDFLAGS = -lGL -lX11 -lm BINARIES = ./linux -raylib_folder = ./raylib #Pfade zu raylib_folder und unityfolder +raylib_folder = ./raylib unityfolder = ./unity # -------------------------- # initiales Spiel bauen # -------------------------- -wordsalad_initial: #hier kommen normalerweise Abhängikeiten hin. Z.b die Datei game.o muss vorhanden sein. +wordsalad_initial: $(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS) -#wordsalad_initial linkt nur bibliotheken. Deshalb hat es keine Abhängigkeiten. + # -------------------------- # Normales Spiel bauen # -------------------------- @@ -19,29 +19,36 @@ wordsalad: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS) main.o: main.c - $(CC) $(CFLAGS) -c main.c + $(CC) $(CFLAGS) -c $< -o $@ # <- KORRIGIERT -input.o: input.c - $(CC) $(CFLAGS) -c input.c +input.o: input.c input.h + $(CC) $(CFLAGS) -c $< -o $@ # <- KORRIGIERT (Zeile 25/26) game.o: game.c - $(CC) $(CFLAGS) -c game.c + $(CC) $(CFLAGS) -c $< -o $@ # <- KORRIGIERT graphicalGame.o: graphicalGame.c - $(CC) $(CFLAGS) -c graphicalGame.c + $(CC) $(CFLAGS) -c $< -o $@ # <- KORRIGIERT # -------------------------- # Unit Tests # -------------------------- TEST_BIN = runTests -test: input.o game.o unit_tests.c - $(CC) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a +# KORRIGIERTE Test-Regel (umbenannt von neuer_test) +test: input.o game.o unit_tests.o + $(CC) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.o $(BINARIES)/libunity.a + +# KORRIGIERTE unit_tests.o Regel +unit_tests.o: unit_tests.c input.h game.h + $(CC) $(CFLAGS) -I$(unityfolder) -c $< -o $@ # -------------------------- # Clean # -------------------------- -wordsalad_myversion: main.o $(BINARIES)/libwordsalad.a #eigenes Programm erstellen. +wordsalad_myversion: main.o $(BINARIES)/libwordsalad.a $(CC) -o wordsalad_myversion main.o $(BINARIES)/libwordsalad.a + clean: rm -f *.o wordsalad $(TEST_BIN) +# Tests starten mit ./runTests \ No newline at end of file diff --git a/Start_Linux/wordsalad b/Start_Linux/wordsalad new file mode 100755 index 0000000..3961d29 Binary files /dev/null and b/Start_Linux/wordsalad differ