Compare commits
17
Commits
207d93b317
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6b98b53fc | ||
|
|
bd2e6f4e41 | ||
|
|
0a87d89da3 | ||
|
|
fe1cb95cc0 | ||
|
|
078e326e4d | ||
|
|
491a85debd | ||
|
|
b8a6308821 | ||
|
|
9d8a760f08 | ||
|
|
817ddc0e35 | ||
|
|
09039d961a | ||
|
|
0c086b9607 | ||
|
|
b88cf94072 | ||
|
|
5162e9890d | ||
|
|
fbef3806db | ||
|
|
8844495411 | ||
|
|
288693c76f | ||
|
|
b1d7cbc74b |
@@ -29,6 +29,8 @@ int checkforOverlap(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], shor
|
|||||||
// Creates the word salad by placing words randomly and filling empty spaces
|
// 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)
|
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
||||||
{
|
{
|
||||||
|
unsigned int placedCount = 0;
|
||||||
|
|
||||||
for(short i = 0; i < searchFieldLen; i++)
|
for(short i = 0; i < searchFieldLen; i++)
|
||||||
{
|
{
|
||||||
for(short j = 0; j < searchFieldLen; j++)
|
for(short j = 0; j < searchFieldLen; j++)
|
||||||
@@ -72,9 +74,22 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
salad[x+xoffset][y+yoffset]=words[i-1][k];
|
salad[x+xoffset][y+yoffset]=words[i-1][k];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
placedCount++;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+49
-14
@@ -6,24 +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)
|
||||||
{
|
{
|
||||||
//Erstellt Pointer auf textdokument
|
char line[1024]; // Puffer für eine Zeile
|
||||||
FILE *textdokument = fopen(file, "r");
|
|
||||||
if (textdokument == NULL) {
|
|
||||||
printf("Datei konnte nicht geoffnet werden");
|
|
||||||
}
|
|
||||||
// 2D char Array um wörter zu speichern
|
|
||||||
char word[MAX_WORD_LEN];
|
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
while (fscanf(textdokument, "%s", word) != EOF && count < maxWordCount) {
|
|
||||||
// Kopiere das gelesene Wort in das 2D-Array
|
// Alle gewünschten Trennzeichen
|
||||||
strncpy(words[count], word, MAX_WORD_LEN - 1);
|
const char *delimiters = " \t\n,.;:!?\"'()[]{}";
|
||||||
words[count][MAX_WORD_LEN - 1] = '\0'; // Sicherstellen, dass der String nullterminiert ist
|
|
||||||
|
// 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++;
|
count++;
|
||||||
}
|
}
|
||||||
fclose(textdokument);
|
token = strtok(NULL, delimiters);
|
||||||
return count;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count; // Datei nicht schließen – gehört dem Aufrufer
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
+18
-3
@@ -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
|
||||||
@@ -57,6 +59,18 @@ int main(int argc, char *argv[])
|
|||||||
// 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)
|
||||||
|
{
|
||||||
|
// Start the game with the created word salad
|
||||||
|
printf("Squares: %u, Words: %u\n", SALAD_SIZE, placedWords);
|
||||||
|
unsigned int windowWidth = 800;
|
||||||
|
startGame(wordSalad, SALAD_SIZE, words, wordCount, windowWidth);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Could not place all words into the word salad. Placed %u out of %u words.\n", placedWords, wordCount);
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -70,3 +84,4 @@ int main(int argc, char *argv[])
|
|||||||
return exitCode;
|
return exitCode;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user