6 Commits
Author SHA1 Message Date
welschph103497 e0bd8b46ea Abfrage nach korrektem Platzieren aller Wörter eingefügt, Unity Tests bestanden 2026-10-26 21:22:12 +01:00
Mapama f8ca49c9c6 input.c fertiggestellt 2026-10-26 19:58:40 +01:00
welschph103497 689456bbba Pushversuch 2026-10-26 16:35:00 +01:00
welschph103497 01b1660858 game.c vervollständigt 2026-10-26 16:26:02 +01:00
welschph103497 0ee1c4e689 Game.c vervollständigt 2026-10-26 16:09:41 +01:00
kayaoglura103830 c93dd9a734 TODOS bei main
.gitignore verbessert
makefile vervollständigt
2026-10-26 13:48:53 +01:00
5 changed files with 102 additions and 8 deletions

No files matched your search

+2 -1
View File
@@ -35,9 +35,10 @@
*.i*86
*.x86_64
*.hex
Startcode/wordsalad_myversion
Startcode/wordsalad_initial
Startcode/wordsalad
test
runtest
# Debug files
*.dSYM/
+61 -5
View File
@@ -6,12 +6,68 @@
#define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0
//TODO: Spiellogik implementieren:
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
* restliche Felder mit zufälligen Buchstaben füllen */
// 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 row, col, word, startcol=0, startrow=0, placedWord=0;
srand(time(NULL));
for(row=0; row<MAX_SEARCH_FIELD_LEN; row++)
{
for(col=0; col<MAX_SEARCH_FIELD_LEN; col++)
{
salad[row][col] = EMPTY_CHAR;
}
}
for (word=0; word<wordCount; word++)
{
if (rand() % 2 == 0) //horizontal
{
startcol = rand() % (MAX_SEARCH_FIELD_LEN - strlen(words[word])+1);
startrow = rand() % MAX_SEARCH_FIELD_LEN;
for (int i=0; i<strlen(words[word]); i++)
{
salad[startrow][startcol+i] = words[word][i];
}
}
else //vertikal
{
startrow = rand() % (MAX_SEARCH_FIELD_LEN - strlen(words[word])+1);
startcol = rand() % MAX_SEARCH_FIELD_LEN;
for (int j=0; j<strlen(words[word]); j++)
{
salad[startrow+j][startcol] = words[word][j];
}
}
placedWord++;
if (rand()%26 !=0)
{
printf("%c",EMPTY_CHAR);
}
}
for (row=0; row<MAX_SEARCH_FIELD_LEN; row++)
{
for (col=0; col<MAX_SEARCH_FIELD_LEN; col++)
{
if (salad[row][col] == EMPTY_CHAR)
{
salad[row][col] = rand()%26+'A';
}
}
}
for (row=0; row<MAX_SEARCH_FIELD_LEN; row++)
{
for (col=0; col<MAX_SEARCH_FIELD_LEN; col++)
{
printf("%c", salad[row][col]);
}
printf("\n");
}
printf("\n\nPlatzierung abgeschlossen\n\n");
if(placedWord==word)
{
return placedWord;
} else return 0;
}
+21
View File
@@ -8,5 +8,26 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
if (file == NULL) {
return 0;
}
char line[MAX_LINE_LEN];
unsigned int count = 0;
while (fgets(line, sizeof(line), file) != NULL && count < maxWordCount) {
char *token = strtok(line, " ,;\n\r\t");
while (token != NULL & count < maxWordCount) {
if (strlen(token) > 0) {
strncpy(words[count], token, MAX_WORD_LEN - 1);
words[count][MAX_WORD_LEN - 1] = '\0';
for (int i= 0; words[count][i] != '\0'; i++) {
words[count][i] = toupper((unsigned char)words[count][i]);
}
count++;
}
token = strtok(NULL, " ,;\n\r\t");
}
}
return count;
}
+11 -2
View File
@@ -38,8 +38,17 @@ int main(int argc, char *argv[])
// TODO:
// Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed
if (placedWords == wordCount)
{
// Start the game if successful
startGame(wordSalad, SALAD_SIZE, words, wordCount, 600);
}
else
{
// error message if some words couldn't be placed
fprintf(stderr, "Fehler. Es konnten nicht alle Wörter Platziert werden.");
exitCode = EXIT_FAILURE;
}
}
else
+7
View File
@@ -22,6 +22,13 @@ codefolder = .
wordsalad_initial:
$(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
# Eigenes Target
wordsalad_myversion: main.o graphicalGame.o $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad_myversion main.o graphicalGame.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
# --------------------------
# Normales Spiel bauen
# --------------------------