diff --git a/Startcode/input.c b/Startcode/input.c index cb76f11..e15db33 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -1,30 +1,41 @@ #include "input.h" #include #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) { - char puffer[MAX_WORD_LEN]; - char *teiler = " ,;\n"; + char puffer[MAX_LINE_NUMBER][MAX_LINE_LEN]; + char *teiler = "\n ,;"; char *token; - unsigned int wordCount = 0; + int i = 0; + unsigned int wordCount = 0; - fgets(puffer, MAX_LINE_LEN, file); + while(fgets(puffer[i], MAX_LINE_LEN, file) != NULL) + { + i++; + } - token = strtok(puffer, teiler); + i = 0; + + token = strtok(puffer[i], teiler); while(token != NULL && wordCount < maxWordCount) { strncpy(words[wordCount], token, MAX_WORD_LEN -1); - words[wordCount][MAX_WORD_LEN - 1] = '\0'; + //words[wordCount][MAX_WORD_LEN - 1] = '\0'; wordCount++; - token =strtok(NULL, teiler); + token = strtok(NULL, teiler); + + if(token == NULL && i < MAX_LINE_NUMBER) + { + token = strtok(puffer[i+1], teiler); + } } diff --git a/Startcode/input.h b/Startcode/input.h index 6c58ddf..182cc1e 100644 --- a/Startcode/input.h +++ b/Startcode/input.h @@ -5,6 +5,7 @@ #define MAX_WORD_LEN 100 #define MAX_LINE_LEN 1024 +#define MAX_LINE_NUMBER 100 //Selbst hinzugefügt int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount); diff --git a/Startcode/main.c b/Startcode/main.c index 03da755..7931401 100644 --- a/Startcode/main.c +++ b/Startcode/main.c @@ -36,10 +36,11 @@ 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 == wordCount) + { + startGame(wordSalad, SALAD_SIZE, words, wordCount, 800); + } } else diff --git a/Startcode/makefile b/Startcode/makefile index bc64e9f..d1d6985 100644 --- a/Startcode/makefile +++ b/Startcode/makefile @@ -25,8 +25,9 @@ wordsalad_initial: # -------------------------- # Normales Spiel bauen # -------------------------- -my_wordsalad: main. o input.o $(BINARIES)/libwordsalad_complete.a - $(CC) $(CFLAGS) -o my_wordsalad main.o input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS) + +wordsalad_myversion: input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a + $(CC) $(CFLAGS) -o wordsalad_myversion input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS) 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)