Compare commits

...
10 Commits
7 changed files with 74 additions and 22 deletions
Binary file not shown.
+10
View File
@@ -78,6 +78,16 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
} }
for(short i = 0; i < searchFieldLen; i++)
{
for(short j = 0; j < searchFieldLen; j++)
{
if(salad[i][j] == '#')
{
salad[i][j]='A' + (rand()%26);
}
}
}
return placedCount; return placedCount;
+36 -8
View File
@@ -6,6 +6,17 @@
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt. // 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 // Read words from file and store in 'words' array
int isValidWord(const char *word)
{
for (int i = 0;word[i]; i++)
{
if (!('A' <= word[i] && word[i] <= 'Z'))
{
return 0;
}
}
return 1;
}
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{ {
char line[1024]; // Puffer für eine Zeile char line[1024]; // Puffer für eine Zeile
@@ -14,23 +25,40 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
// Alle gewünschten Trennzeichen // Alle gewünschten Trennzeichen
const char *delimiters = " \t\n,.;:!?\"'()[]{}"; const char *delimiters = " \t\n,.;:!?\"'()[]{}";
while (fgets(line, sizeof(line), file) && count < maxWordCount) { // Zeile für Zeile lesen
while (fgets(line, sizeof(line), file) != NULL && count < maxWordCount) {
// Tokenize Zeile nach Trennzeichen
char *token = strtok(line, delimiters); char *token = strtok(line, delimiters);
while (token != NULL && count < maxWordCount) {
while (token != NULL && count < maxWordCount)
{
// Überspringe leere Tokens
if (token && strlen(token) > 0)
{
// Alles in Großbuchstaben umwandeln // Alles in Großbuchstaben umwandeln
for (int i = 0; token[i]; i++) { for (int i = 0; token[i]; i++)
{
token[i] = toupper(token[i]); token[i] = toupper(token[i]);
} }
// Prüfen, ob das Wort nur A-Z enthält
if (!isValidWord(token))
{
fprintf(stderr, "Ungültiges Wort gefunden: '%s'. Nur Buchstaben A-Z erlaubt.\n", token);
token = strtok(NULL, delimiters);
continue; // Wort ignorieren
}
// Wort ins Array kopieren
strncpy(words[count], token, MAX_WORD_LEN - 1); strncpy(words[count], token, MAX_WORD_LEN - 1);
words[count][MAX_WORD_LEN - 1] = '\0'; // Nullterminierung words[count][MAX_WORD_LEN - 1] = '\0';
count++; count++;
}
token = strtok(NULL, delimiters); token = strtok(NULL, delimiters);
} }
} }
fclose(file); return count; // Datei nicht schließen – gehört dem Aufrufer
return count;
} }
+1
View File
@@ -7,5 +7,6 @@
#define MAX_LINE_LEN 1024 #define MAX_LINE_LEN 1024
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount); int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount);
int isValidWord(const char *word);
#endif #endif
+9 -4
View File
@@ -9,7 +9,8 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
/*char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; /*
char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
char words[MAX_NUMBER_OF_WORDS][100] = char words[MAX_NUMBER_OF_WORDS][100] =
{ {
"TESTN", "TESTN",
@@ -22,10 +23,11 @@ int main(int argc, char *argv[])
"SEE", "SEE",
}; };
int wordCount = 8; int wordCount = 8;
createWordSalad(salad,5, words,wordCount); createWordSalad(salad,7, words,wordCount);
showWordSalad(salad,5); showWordSalad(salad,7);
*/ */
int exitCode = EXIT_SUCCESS; int exitCode = EXIT_SUCCESS;
// Check if the correct number of arguments is provided // Check if the correct number of arguments is provided
@@ -60,7 +62,9 @@ int main(int argc, char *argv[])
if(placedWords == wordCount) if(placedWords == wordCount)
{ {
// Start the game with the created word salad // Start the game with the created word salad
startGame(wordSalad, SALAD_SIZE, words, wordCount, placedWords); printf("Squares: %u, Words: %u\n", SALAD_SIZE, placedWords);
unsigned int windowWidth = 800;
startGame(wordSalad, SALAD_SIZE, words, wordCount, windowWidth);
} }
else else
{ {
@@ -80,3 +84,4 @@ int main(int argc, char *argv[])
return exitCode; return exitCode;
} }
+7 -3
View File
@@ -35,11 +35,15 @@ graphicalGame.o: graphicalGame.c
# -------------------------- # --------------------------
TEST_BIN = runTests TEST_BIN = runTests
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
test: input.o game.o unit_tests.c $(unityfolder)/unity.c
$(CC) $(CFLAGS) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(unityfolder)/unity.c
# -------------------------- # --------------------------
# Clean # Clean
# -------------------------- # --------------------------
#clean:
# del /f *.o *.exe
clean: clean:
del /f *.o *.exe rm -f *.o *.exe
+5 -1
View File
@@ -1 +1,5 @@
test Yeti,Nessie Werwolf; Vampir
Monster
Hydra;Frankenstein
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
Gespenst, Oger