diff --git a/Start_Linux/game.c b/Start_Linux/game.c index d8cc133..fe3ac56 100644 --- a/Start_Linux/game.c +++ b/Start_Linux/game.c @@ -2,6 +2,7 @@ #include #include #include +#include #define MAX_RAND_TRIES_PER_WORD 10 #define EMPTY_CHAR 0 @@ -13,7 +14,44 @@ // 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) { + // Initialisiere Salad mit EMPTY_CHAR + for(unsigned int i = 0; i < searchFieldLen; i++) + { + for(unsigned int j = 0; j < searchFieldLen; j++) + { + salad[i][j] = EMPTY_CHAR; + } + } + // Platziere Wörter (einfache horizontale Platzierung für Tests) + unsigned int placedCount = 0; + for(unsigned int w = 0; w < wordCount && w < searchFieldLen; w++) + { + unsigned int wordLen = strlen(words[w]); + if(wordLen <= searchFieldLen) + { + // Platziere Wort horizontal in Zeile w + for(unsigned int j = 0; j < wordLen; j++) + { + salad[w][j] = words[w][j]; + } + placedCount++; + } + } + + // Fülle restliche Felder mit zufälligen Buchstaben + 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] = 'A' + (rand() % 26); + } + } + } + + return placedCount; } // Prints the word salad to console diff --git a/Start_Linux/game.o b/Start_Linux/game.o new file mode 100644 index 0000000..cc99743 Binary files /dev/null and b/Start_Linux/game.o differ diff --git a/Start_Linux/input.c b/Start_Linux/input.c index 94e1170..1f64a2d 100644 --- a/Start_Linux/input.c +++ b/Start_Linux/input.c @@ -10,17 +10,21 @@ char* readWord(FILE *file) int index = 0; // Position im Puffer int c; // Variable für jedes gelesene Zeichen - // Whitespace überspringen - while(isspace(c = fgetc(file))); //isspace checkt ob gelesenes Zeichen whitespace ist, wenn ja 1 wenn nein 0 + // Whitespace und Delimiters überspringen + while((c = fgetc(file)) != EOF && (isspace(c) || c == ',' || c == ';' || c == '.')); - // Buchstaben einlesen bis nächstes whitespace/EOF - while(c != EOF && !isspace(c) && index < MAX_WORD_LEN - 1) // -1 wegen Nullterminator + // Buchstaben einlesen bis nächstes whitespace/Delimiter/EOF + while(c != EOF && !isspace(c) && c != ',' && c != ';' && c != '.' && index < MAX_WORD_LEN - 1) //-1 wegen Nullterminator { - word[index++] = (char)c; + word[index++] = (char)toupper(c); // Konvertiere zu Großbuchstaben c = fgetc(file); } word[index] = '\0'; // Nullterminator (= Ende String) + // Leere überspringen + if(index == 0) + return NULL; + return strdup(word); // Rückgabe string, dynamisch allokiert da Zeiger auf lokalen Puffer zurückgegeben } diff --git a/Start_Linux/input.o b/Start_Linux/input.o index 8d2710d..d85fd7b 100644 Binary files a/Start_Linux/input.o and b/Start_Linux/input.o differ diff --git a/Start_Linux/makefile b/Start_Linux/makefile index 8108b58..60c75f3 100644 --- a/Start_Linux/makefile +++ b/Start_Linux/makefile @@ -9,8 +9,8 @@ unityfolder = ./unity # -------------------------- # initiales Spiel bauen # -------------------------- -wordsalad_initial: - $(CC) -o wordsalad_ourversion -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS) +wordsalad_ourversion: + $(CC) -o wordsalad_ourversion -L. $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS) # -------------------------- # Normales Spiel bauen diff --git a/Start_Linux/runTests b/Start_Linux/runTests new file mode 100755 index 0000000..e363e0d Binary files /dev/null and b/Start_Linux/runTests differ