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;
+41 -13
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.
// 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)
{
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
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);
while (token != NULL && count < maxWordCount) {
// Alles in Großbuchstaben umwandeln
for (int i = 0; token[i]; i++) {
token[i] = toupper(token[i]);
while (token != NULL && count < maxWordCount)
{
// Überspringe leere Tokens
if (token && strlen(token) > 0)
{
// Alles in Großbuchstaben umwandeln
for (int i = 0; token[i]; 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);
words[count][MAX_WORD_LEN - 1] = '\0';
count++;
}
strncpy(words[count], token, MAX_WORD_LEN - 1);
words[count][MAX_WORD_LEN - 1] = '\0'; // Nullterminierung
count++;
token = strtok(NULL, delimiters);
}
}
fclose(file);
return count;
return count; // Datei nicht schließen – gehört dem Aufrufer
}
+1
View File
@@ -7,5 +7,6 @@
#define MAX_LINE_LEN 1024
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount);
int isValidWord(const char *word);
#endif
+10 -5
View File
@@ -9,7 +9,8 @@
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] =
{
"TESTN",
@@ -22,10 +23,11 @@ int main(int argc, char *argv[])
"SEE",
};
int wordCount = 8;
createWordSalad(salad,5, words,wordCount);
showWordSalad(salad,5);
createWordSalad(salad,7, words,wordCount);
showWordSalad(salad,7);
*/
int exitCode = EXIT_SUCCESS;
// Check if the correct number of arguments is provided
@@ -60,7 +62,9 @@ int main(int argc, char *argv[])
if(placedWords == wordCount)
{
// 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
{
@@ -79,4 +83,5 @@ int main(int argc, char *argv[])
return exitCode;
}
}
+7 -3
View File
@@ -35,11 +35,15 @@ graphicalGame.o: graphicalGame.c
# --------------------------
TEST_BIN = runTests
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
#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
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:
# del /f *.o *.exe
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