Compare commits

..

26 Commits
selina ... main

Author SHA1 Message Date
maxgrf
e551a025be main updated 2025-11-10 12:39:33 +01:00
maxgrf
b427e8e547 update 2 2025-11-10 11:57:39 +01:00
maxgrf
5f567fa968 update game.c 2025-11-10 11:55:24 +01:00
maxgrf
36bfbcb156 update makefile 2025-11-10 11:53:21 +01:00
maxgrf
a78c1e2ea2 testphrases deleted + all test for input passed 2025-11-07 17:25:34 +01:00
maxgrf
c18b6a4529 test12! 2025-11-07 17:17:54 +01:00
maxgrf
013eba7b3d test13 2025-11-06 16:44:13 +01:00
maxgrf
cd3dd0a4d6 test12 2025-11-06 16:43:06 +01:00
maxgrf
b9138e2097 test11 2025-11-06 16:41:45 +01:00
maxgrf
28a2aa1ea1 test10 2025-11-06 16:35:30 +01:00
maxgrf
cddbfb3029 test9 2025-11-06 16:23:36 +01:00
maxgrf
5c1aea7a88 test8 2025-11-06 16:18:53 +01:00
maxgrf
f47f3aef7c test7 2025-11-06 16:17:55 +01:00
maxgrf
b34074233d test5 2025-11-06 16:15:25 +01:00
maxgrf
bbad6afd45 test4 2025-11-06 16:12:26 +01:00
maxgrf
9e172b664f update 2025-11-06 15:59:21 +01:00
maxgrf
c26a55f965 endloschleife2 2025-11-06 15:50:21 +01:00
maxgrf
16b0b9a450 endlosschleife behoben 2025-11-06 15:43:10 +01:00
maxgrf
85a79e9235 test2 2025-11-06 15:35:37 +01:00
maxgrf
506c091bf6 test1 2025-11-06 15:31:01 +01:00
maxgrf
4fea2c9f7b input 2025-11-06 11:30:49 +01:00
maxgrf
817f35a154 input bugfix 2025-11-06 11:26:13 +01:00
maxgrf
19787739a7 input fix strtok 2025-11-04 22:25:36 +01:00
maxgrf
3657ee5ff7 input filled with logic 2025-11-03 22:24:46 +01:00
maxgrf
099243b5e2 makefile reload 2025-11-03 21:44:04 +01:00
maxgrf
1db2042e38 Makefile fertig 2025-10-30 16:13:26 +01:00
13 changed files with 33 additions and 204 deletions

View File

@ -121,4 +121,4 @@ void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
} }
printf("\n"); printf("\n");
} }
} }

Binary file not shown.

View File

@ -8,132 +8,28 @@
// Read words from file and store in 'words' array // Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{ {
// MAX_WORD_LEN 100 char puffer[MAX_LINE_LEN]; //Array für eingelesene Zeile
// MAX_LINE_LEN 1024 int counter = 0; //Zähler für Anzahl eingelesener Wörter
// *file ist Datei int i;
// words ist Array
// MAX_WORD_LEN ist maximale Wortlänge
// maxWordCount ist maximale Anzahl an Wörtern
char puffer[MAX_LINE_LEN];
int counter = 0;
while(fgets(puffer, MAX_LINE_LEN-1, file) != NULL && counter < maxWordCount) while(fgets(puffer, MAX_LINE_LEN-1, file) != NULL && counter < maxWordCount)
{ {
char *parts = strtok(puffer, ",;\n\t/. "); char *word_parts = strtok(puffer, ",;\n\t/. "); //Wörter aufteilen
while(parts != NULL && counter < maxWordCount) while(word_parts != NULL && counter < maxWordCount)
{ {
//strncpy(words[counter][MAX_WORD_LEN], puffer, MAX_LINE_LEN-1); // Kopiere das Wort in words-Array
//words[counter][MAX_WORD_LEN-1] = "\0"; strncpy(words[counter], word_parts, MAX_WORD_LEN - 1);
//Großbuchstaben words[counter][MAX_WORD_LEN - 1] = '\0';
for(int i = 0; i < MAX_WORD_LEN -1 && parts[i] != '\0'; i++)
{ // Alles in Großbuchstaben umwandeln
words[counter][i] = toupper(parts[i]); for(i = 0; words[counter][i] != '\0'; i++)
words[counter][i] = '\0'; {
} words[counter][i] = toupper(words[counter][i]);
}
counter++; // Wort eingelesen, Wortzähler erhöhen
word_parts = strtok(NULL, ",;\n\t/. "); //NULL für Zeiger angeben
} }
counter++; // Wort eingelesen -> Wortzähler erhöhen
parts = strtok(NULL, ",;\n\t/. ");
} }
return counter; return counter;
} }
/* #include "input.h"
#include <string.h>
#include <ctype.h>
#define MAX_NUMBER_OF_WORDS 100
#define MAX_WORD_LEN 100
// 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 line [MAX_WORD_LEN];
printf("H");
int j = 0;
int count = 0;
char single_word[MAX_WORD_LEN];
while(fgets(line, MAX_WORD_LEN, file) != NULL ){
printf("A");
for(int i = 0; line[i] != '\0'; i++){
printf("L");
//prüft, ob das gesammelte Zeichen ein Zeichen ist, schiebt es dann Großgeschrieben in das Array word
if (isalpha(line[i]) != 0){
single_word[j++] = toupper(line[i]);
}
// wenn das Wort fertig ist, dann wird dem Wort eine 0 angefügt um das Ende des Strings zu signalisieren, dann wird es in das Array words kopiert
else{
single_word[j] = '\0';
strncpy(words[count], single_word, MAX_WORD_LEN);
count++;
j = 0;
}
}
}
for(int n = 0; n < count ; n++)
{
printf("%s \n", words[n]);
printf("O");
}
return count;
}
int main(){
int wordCount = 0;
FILE *file = fopen("word.txt", "r");
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN];
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
fclose(file);
return wordCount;
}
/* 1. Versuch
while(fgets(line, maxWordCount, file) != NULL ){
int i = 0;
int count = 0;
char line [MAX_WORD_LEN];
while(line[i] != '\0' && line[i+1] != '\0'){
char single_word[MAX_WORD_LEN];
//prüft, ob das gesammelte Zeichen ein Zeichen ist, schiebt es dann Großgeschrieben in das Array word
if (isalpha(line[i]) != 0){
single_word[i++] = toupper(line[i]);
}
// wenn das Wort fertig ist, dann wird dem Wort eine 0 angefügt um das Ende des Strings zu signalisieren, dann wird es in das Array words kopiert
else{
single_word[i++] = '\0';
strncpy(single_word, words, i)
words[i][0] = '\0';
}
i++;
}
*/

Binary file not shown.

View File

@ -36,19 +36,19 @@ int main(int argc, char *argv[])
// Create the word salad by placing words into grid // Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// TODO: (if Schleife implementieren, die das prüft) // TODO:
// Check if all words were successfully placed // Check if all words were successfully placed
// Start the game if successful // Start the game if successful
// error message if some words couldn't be placed // error message if some words couldn't be placed
if (placedWords == wordCount){ if (placedWords == wordCount){
showWordSalad(wordSalad, placedWords); startGame(wordSalad,SALAD_SIZE,words, wordCount,750);
} }
else{ else
{
printf("Error. The words couldn't be placed.\n"); printf("Error. The words couldn't be placed.\n");
return -1; return -1;
} }
} }
else else
{ {
@ -59,6 +59,4 @@ int main(int argc, char *argv[])
} }
return exitCode; return exitCode;
} }
//

View File

@ -33,9 +33,9 @@ graphicalGame.o: graphicalGame.c
# -------------------------- # --------------------------
# Unit Tests # Unit Tests
# -------------------------- # --------------------------
TEST_BIN = runTests TEST_BIN = runTests2
test: input.o game.o unit_tests.c test: input.o game.o unit_tests.c
$(CC) $(CFLAGS) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a $(CC) $(CFLAGS) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a
# -------------------------- # --------------------------
@ -43,6 +43,7 @@ test: input.o game.o unit_tests.c
# -------------------------- # --------------------------
clean: clean:
del /f *.o *.exe del /f *.o *.exe
#hier eigene wordsalad kopieren, library rauslassen
wordsalad_myversion: main.o input.o game.o graphicalGame.o $(BINARIES)/libwordsalad.a wordsalad_myversion: main.o input.o game.o graphicalGame.o
$(CC) $(CFLAGS) -o wordsalad_myversion main.o input.o game.o graphicalGame.o $(BINARIES)/libwordsalad.a $(LDFLAGS) $(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)

BIN
Start_Windows/runTests2.exe Normal file

Binary file not shown.

View File

@ -1,70 +0,0 @@
#include "input.h"
#include <string.h>
#include <ctype.h>
// launch
#define MAX_NUMBER_OF_WORDS 100
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
char line [MAX_WORD_LEN];
int i = 0;
int j = 0;
int count = 0;
file = fopen("words.txt", "r");
char single_word[MAX_WORD_LEN];
while(fgets(line, maxWordCount, file) != NULL ){
while(line[i] != '\0' && line[i+1] != '\0'){
//prüft, ob das gesammelte Zeichen ein Zeichen ist, schiebt es dann Großgeschrieben in das Array word
if (isalpha(line[i]) != 0){
single_word[j++] = toupper(line[i]);
}
// wenn das Wort fertig ist, dann wird dem Wort eine 0 angefügt um das Ende des Strings zu signalisieren, dann wird es in das Array words kopiert
else{
single_word[j++] = '\0';
strncpy(words[count], single_word, i);
i = 0;
count++;
int j = 0;
}
i++;
}
}
for(int n = 0; n < count ; n++)
{
printf("%s \n", words[n]);
}
}
int main()
{
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN];
FILE*file;
unsigned int wordCount = 0;
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
}

View File

@ -0,0 +1 @@
Hund,Katze; Maus

View File

View File

@ -0,0 +1,3 @@
Apfel
Banane
Kiwi

Binary file not shown.

Binary file not shown.