From c6664be88c1381d18a79955b8fe78bf84b9ba1a9 Mon Sep 17 00:00:00 2001 From: pvtrx Date: Wed, 5 Nov 2025 14:28:38 +0100 Subject: [PATCH] deleted testing lines -- tried to build main but had issues with graphicalGame.c --- Start_Windows/.vscode/launch.json | 9 ++--- Start_Windows/.vscode/settings.json | 3 +- Start_Windows/.vscode/tasks.json | 18 +++++++++- Start_Windows/input.c | 48 ++++++++++++++++++++++++- Start_Windows/input.h | 1 + Start_Windows/main.c | 16 ++++----- Start_Windows/makefile | 25 ++++++++----- {Start_Windows => TestFiles}/Test123.c | 0 {Start_Windows => TestFiles}/TestMain.c | 0 {Start_Windows => TestFiles}/test.c | 0 10 files changed, 97 insertions(+), 23 deletions(-) rename {Start_Windows => TestFiles}/Test123.c (100%) rename {Start_Windows => TestFiles}/TestMain.c (100%) rename {Start_Windows => TestFiles}/test.c (100%) diff --git a/Start_Windows/.vscode/launch.json b/Start_Windows/.vscode/launch.json index 45a2b40..0dd8a04 100644 --- a/Start_Windows/.vscode/launch.json +++ b/Start_Windows/.vscode/launch.json @@ -2,17 +2,18 @@ "version": "0.2.0", "configurations": [ { - "name": "Debug current C file", + "name": "Debug Word Salad", "type": "cppdbg", "request": "launch", - "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", - "args": [], + "program": "${fileDirname}\\word-salad.exe", + "args": ["${fileDirname}/words.txt"], + "cwd": "${fileDirname}", "stopAtEntry": false, "cwd": "${fileDirname}", "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "C:/msys64/mingw64/bin/gdb.exe", - "preLaunchTask": "C/C++: gcc.exe build active file" + "preLaunchTask": "make" } ] } diff --git a/Start_Windows/.vscode/settings.json b/Start_Windows/.vscode/settings.json index d4a224b..a0eac81 100644 --- a/Start_Windows/.vscode/settings.json +++ b/Start_Windows/.vscode/settings.json @@ -1,5 +1,6 @@ { "files.associations": { - "ctype.h": "c" + "ctype.h": "c", + "input.h": "c" } } \ No newline at end of file diff --git a/Start_Windows/.vscode/tasks.json b/Start_Windows/.vscode/tasks.json index 52ad522..e5282d1 100644 --- a/Start_Windows/.vscode/tasks.json +++ b/Start_Windows/.vscode/tasks.json @@ -2,6 +2,22 @@ { "version": "2.0.0", "tasks": [ + { + "label": "make", + "type": "shell", + "command": "C:/msys64/usr/bin/make.exe", + "options": { + "cwd": "${fileDirname}", + "env": { "PATH": "C:/msys64/mingw64/bin;${env:PATH}" }, + }, + "problemMatcher": ["$gcc"], + "group": { + "kind": "build", + "isDefault": true + }, + }, + + { "label": "build C file", "type": "shell", @@ -42,7 +58,7 @@ ], "group": { "kind": "build", - "isDefault": true + "isDefault": false }, "detail": "Task generated by Debugger." } diff --git a/Start_Windows/input.c b/Start_Windows/input.c index 6135675..6113b9f 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -6,5 +6,51 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { - //TODO: Implement function to read words from file words.txt and store them in the words array. See, that in the file words are not seperated only by , ; or space but also by new lines. + int zeilen = 0; + + if(file == 0) + { + printf("Fehler beim oeffnen der Woerter \n"); + return -1; + } + while(fgets(words[zeilen], MAX_WORD_LEN, file) != 0) //auslesen der Zeilen + { + size_t laenge = strlen(words[zeilen]); // Datentyp size_t wird verwendet bei strlen + if(laenge > 0 && words[zeilen][laenge - 1] == '\n') //austauschen des Leerzeichens mit einem Nullzeichen falls nötig + { + words[zeilen][laenge - 1] = '\0'; + laenge--; // Länge nach austauschen 1 kleiner weil nullzeichen nicht mitzählt + } + zeilen++; + } + + int alt_zeilen = zeilen; + zeilen = 0; + char *teiler = " .,;\n\t\r"; + char *woerter; + char aufgeteilt[MAX_NUMBER_OF_WORDS][MAX_LINE_LEN]; //zwischenspeicher fürs aufteilen der Wörter + for(int i = 0; i < alt_zeilen; i++) // Jede Zeile einzeln betrachten + { + woerter = strtok(words[i], teiler); + while(woerter != 0) + { + strncpy(aufgeteilt[zeilen], woerter, MAX_WORD_LEN); // Kopieren der aufgeteilten Wörter in den Zwischenspeicher + zeilen++; + woerter = strtok(NULL, teiler); // NULL sagt das man weiterhin in der selben Zeile bleibt und dort aufteilt + + } + } + + for(int i = 0; i < zeilen; i++) + { + strncpy(words[i], aufgeteilt[i], MAX_WORD_LEN); // überschreiben der Wörter zurück ins alte Array + size_t len = strlen(words[i]); + for(int j = 0; j < len; j++) + { + words[i][j] = toupper(words[i][j]); // groß schreiben + + } + } + + return zeilen; } \ No newline at end of file diff --git a/Start_Windows/input.h b/Start_Windows/input.h index 032ec28..e15fc8d 100644 --- a/Start_Windows/input.h +++ b/Start_Windows/input.h @@ -5,6 +5,7 @@ #define MAX_WORD_LEN 100 #define MAX_LINE_LEN 1024 +#define MAX_NUMBER_OF_WORDS 100 int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount); diff --git a/Start_Windows/main.c b/Start_Windows/main.c index 94a69d9..c5ddb4d 100644 --- a/Start_Windows/main.c +++ b/Start_Windows/main.c @@ -33,14 +33,14 @@ int main(int argc, char *argv[]) wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS); fclose(file); - // Create the word salad by placing words into grid - placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); - - // Start game if all valid words were placed - if (placedWords == wordCount) { - startGame(wordSalad, SALAD_SIZE, words, wordCount); - } else { - printf("Could not place all valid words. Placed %d out of %d words.\n", placedWords, wordCount); + // Create the word salad by placing words into grid + placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); + + // Start game if all valid words were placed + if (placedWords == wordCount) { + startGame(wordSalad, SALAD_SIZE, words, wordCount, MAX_SEARCH_FIELD_LEN); + } else { + printf("Could not place all valid words. Placed %d out of %d words.\n", placedWords, wordCount); } } diff --git a/Start_Windows/makefile b/Start_Windows/makefile index 72cccb7..fd47566 100644 --- a/Start_Windows/makefile +++ b/Start_Windows/makefile @@ -1,10 +1,20 @@ -CC = gcc -CFLAGS = -g -Wall -LDFLAGS = -lopengl32 -lgdi32 -lwinmm -BINARIES = ./windows +CC = C:/msys64/mingw64/bin/gcc.exe +CFLAGS = -g -Wall -I. -IC:/msys64/mingw64/include +LDFLAGS = -LC:/msys64/mingw64/lib -lraylib -lopengl32 -lgdi32 -lwinmm -raylibfolder = ./raylib -unityfolder = ./unity +SRC = main.c input.c game.c graphicalGame.c +OBJ = $(SRC:.c=.o) +EXE = word-salad.exe + +all: $(EXE) +$(EXE): $(OBJ) + $(CC) -o $@ $(OBJ) $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f *.o *.exe # -------------------------- # initiales Spiel bauen @@ -41,5 +51,4 @@ test: input.o game.o unit_tests.c # -------------------------- # Clean # -------------------------- -clean: - del /f *.o *.exe + diff --git a/Start_Windows/Test123.c b/TestFiles/Test123.c similarity index 100% rename from Start_Windows/Test123.c rename to TestFiles/Test123.c diff --git a/Start_Windows/TestMain.c b/TestFiles/TestMain.c similarity index 100% rename from Start_Windows/TestMain.c rename to TestFiles/TestMain.c diff --git a/Start_Windows/test.c b/TestFiles/test.c similarity index 100% rename from Start_Windows/test.c rename to TestFiles/test.c