From f77c450c0fac042739280a22963712fb56f49852 Mon Sep 17 00:00:00 2001 From: wehnerla99053 Date: Mon, 20 Oct 2025 15:00:45 +0200 Subject: [PATCH] =?UTF-8?q?Fehlerbehebung=20klein=20und=20gro=C3=9Fbuchsta?= =?UTF-8?q?ben=20behoben!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/Informatik_2_Praktikum.iml | 8 +------- .idea/vcs.xml | 2 +- Start_Windows/game.c | 19 ++++++++++--------- Start_Windows/input.c | 12 ++++++++++++ Start_Windows/main.c | 2 -- Start_Windows/makefile | 10 ++++++---- Start_Windows/wordsalad_initial.exe | Bin 1431096 -> 1431096 bytes 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/.idea/Informatik_2_Praktikum.iml b/.idea/Informatik_2_Praktikum.iml index bc2cd87..4c94235 100644 --- a/.idea/Informatik_2_Praktikum.iml +++ b/.idea/Informatik_2_Praktikum.iml @@ -1,8 +1,2 @@ - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/Start_Windows/game.c b/Start_Windows/game.c index fcece2a..c2b9505 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -12,22 +12,23 @@ // 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) -{ +{// Länge der searchFieldLen wird in Main unter Salad size festgelegt (20) srand((unsigned int)time(NULL)); // Seed für Zufallsgenerator + // Initialisiere das Spielfeld mit EMPTY_CHAR for (unsigned int i = 0; i < searchFieldLen; ++i) { for (unsigned int j = 0; j < searchFieldLen; ++j) { - salad[i][j] = EMPTY_CHAR; + salad[i][j] = ' '; } } unsigned int placedWords = 0; - for (unsigned int w = 0; w < wordCount; ++w) + for (unsigned int word = 0; word < wordCount; ++word) { int placed = 0; for (int tries = 0; tries < MAX_RAND_TRIES_PER_WORD && !placed; ++tries) @@ -35,15 +36,15 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi int direction = rand() % 2; // 1 = horizontal, 0 = vertical int row = rand() % searchFieldLen; int col = rand() % searchFieldLen; - int len = (int)strlen(words[w]); + int len = (int)strlen(words[word]); - if (direction == 1 && col + len <= searchFieldLen) // horizontal + if (direction == 1 && col + len <= searchFieldLen) // prüft ob das Wort horizontal in die Tabelle passt { int canPlace = 1; for (int i = 0; i < len; ++i) { - if (salad[row][col + i] != EMPTY_CHAR && salad[row][col + i] != words[w][i]) + if (salad[row][col + i] != EMPTY_CHAR && salad[row][col + i] != words[word][i]) { canPlace = 0; break; @@ -52,7 +53,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi if (canPlace) { for (int i = 0; i < len; ++i) - salad[row][col + i] = words[w][i]; + salad[row][col + i] = words[word][i]; placed = 1; } } @@ -61,7 +62,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi int canPlace = 1; for (int i = 0; i < len; ++i) { - if (salad[row + i][col] != EMPTY_CHAR && salad[row + i][col] != words[w][i]) + if (salad[row + i][col] != EMPTY_CHAR && salad[row + i][col] != words[word][i]) { canPlace = 0; @@ -71,7 +72,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi if (canPlace) { for (int i = 0; i < len; ++i) - salad[row + i][col] = words[w][i]; + salad[row + i][col] = words[word][i]; placed = 1; } } diff --git a/Start_Windows/input.c b/Start_Windows/input.c index a487317..c8aca43 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -2,14 +2,24 @@ #include #include + +void capitalletters(char *str){ + while (*str) { + *str = toupper((unsigned char) *str); + str++; + } + +} // Liest Wörter aus Datei und speichert sie sicher im Array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { char buffer[MAX_WORD_LEN]; unsigned int count_word = 0; + while (count_word < maxWordCount && fgets(buffer, sizeof(buffer), file) != NULL) { + // Zeilenumbruch manuell entfernen for (int i = 0; i < MAX_WORD_LEN; i++) { @@ -20,6 +30,8 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) } } + capitalletters(buffer); + // Sicheres Kopieren in das Zielarray strncpy(words[count_word], buffer, MAX_WORD_LEN - 1); words[count_word][MAX_WORD_LEN - 1] = '\0'; // Nullterminierung sicherstellen diff --git a/Start_Windows/main.c b/Start_Windows/main.c index 7fc0ef5..5b1aa74 100644 --- a/Start_Windows/main.c +++ b/Start_Windows/main.c @@ -57,8 +57,6 @@ int main(int argc, char *argv[]) } - - } else { diff --git a/Start_Windows/makefile b/Start_Windows/makefile index 146a8c6..b7e3603 100644 --- a/Start_Windows/makefile +++ b/Start_Windows/makefile @@ -1,10 +1,12 @@ +raylib_folder = ./raylib +unityfolder = ./unity + CC = gcc -CFLAGS = -g -Wall -I$(raylibfolder) +CFLAGS = -g -Wall -I$(raylib_folder) LDFLAGS = -lopengl32 -lgdi32 -lwinmm BINARIES = ./windows -raylib_folder = ./raylib -unityfolder = ./unity + # -------------------------- # initiales Spiel bauen @@ -23,7 +25,7 @@ main.o: main.c $(CC) -c $(CFLAGS) main.c input.o: input.c - $(CC) -c $(CFLAGS)input.c + $(CC) -c $(CFLAGS) input.c game.o: game.c $(CC) -c $(CFLAGS) game.c diff --git a/Start_Windows/wordsalad_initial.exe b/Start_Windows/wordsalad_initial.exe index 84577f6de90496c9f6a1354bda859266d452d444..1992bbaa66c87d5475c573c164634f9762e2da5e 100644 GIT binary patch delta 85 zcmV~$xebB<06@`jsNliv46qC}9lKEcgv0{egHjU~vH62o^WMG<`!=j|^y&WZS066z iBnB8_gfX7*j2BEW#Vg+Mjt|T*#{x^Nu*T-=bNn6TS}64Z delta 85 zcmV~$yA6T>06@V2q97ta9g7MQIvXajcnO3?_nfhAU0V}p;M&)0qc