Compare commits

...
12 Commits
Author SHA1 Message Date
Bastian b6b98b53fc Makefile angepasst 2025-11-02 20:15:43 +01:00
Björn bd2e6f4e41 input richtig gestellt 2025-11-02 19:41:46 +01:00
Björn 0a87d89da3 header input verbessert 2025-11-02 19:21:56 +01:00
Bastian fe1cb95cc0 Deklarierung der Fehlerhaften funktion aus der deklaration einer anderen funkton gezogen 2025-11-02 16:43:01 +01:00
Bjoern 078e326e4d Umlautfunktion verbessert 2025-10-28 15:07:54 +01:00
Bjoern 491a85debd Umlauffunktion einfügen 2025-10-28 14:46:44 +01:00
Björn b8a6308821 Fehlerausgabe bei ungültigen Zeichen 2025-10-27 14:06:32 +01:00
Björn 9d8a760f08 input und anzeige überarbeitet 2025-10-27 13:24:06 +01:00
Bastian 817ddc0e35 Alle übrigen Felder werden mt zufälligen Buchstaben befüllt 2025-10-27 12:32:22 +01:00
Björn 09039d961a weg mit Test 2025-10-27 12:00:12 +01:00
Björn 0c086b9607 input verbessert 2025-10-26 18:41:44 +01:00
Björn b88cf94072 miau 2025-10-26 18:30:29 +01:00
5 changed files with 79 additions and 23 deletions
+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;
+51 -15
View File
@@ -6,23 +6,59 @@
// 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)
{ {
if (file == NULL) { char line[1024]; // Puffer für eine Zeile
printf("Datei konnte nicht geoffnet werden");
return 0;
}
// 2D char Array um wörter zu speichern
char word[MAX_WORD_LEN];
unsigned int count = 0; unsigned int count = 0;
while (fscanf(file, "%s", word) != EOF && count < maxWordCount) {
// Kopiere das gelesene Wort in das 2D-Array
strncpy(words[count], word, MAX_WORD_LEN - 1);
words[count][MAX_WORD_LEN - 1] = '\0'; // Sicherstellen, dass der String nullterminiert ist
count++;
}
fclose(file);
return count;
// Alle gewünschten Trennzeichen
const char *delimiters = " \t\n,.;:!?\"'()[]{}";
// 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)
{
// Ü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++;
}
token = strtok(NULL, delimiters);
}
}
return count; // Datei nicht schließen – gehört dem Aufrufer
} }
+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
+10 -5
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
{ {
@@ -79,4 +83,5 @@ 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