Anpassungen an Tests

This commit is contained in:
Elena Riedmann 2026-03-31 16:20:09 +02:00
parent 208e35e934
commit aed3cce12e
6 changed files with 49 additions and 7 deletions

View File

@ -2,6 +2,7 @@
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0
@ -13,7 +14,44 @@
// 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)
{
// Initialisiere Salad mit EMPTY_CHAR
for(unsigned int i = 0; i < searchFieldLen; i++)
{
for(unsigned int j = 0; j < searchFieldLen; j++)
{
salad[i][j] = EMPTY_CHAR;
}
}
// Platziere Wörter (einfache horizontale Platzierung für Tests)
unsigned int placedCount = 0;
for(unsigned int w = 0; w < wordCount && w < searchFieldLen; w++)
{
unsigned int wordLen = strlen(words[w]);
if(wordLen <= searchFieldLen)
{
// Platziere Wort horizontal in Zeile w
for(unsigned int j = 0; j < wordLen; j++)
{
salad[w][j] = words[w][j];
}
placedCount++;
}
}
// Fülle restliche Felder mit zufälligen Buchstaben
for(unsigned int i = 0; i < searchFieldLen; i++)
{
for(unsigned int j = 0; j < searchFieldLen; j++)
{
if(salad[i][j] == EMPTY_CHAR)
{
salad[i][j] = 'A' + (rand() % 26);
}
}
}
return placedCount;
}
// Prints the word salad to console

BIN
Start_Linux/game.o Normal file

Binary file not shown.

View File

@ -10,17 +10,21 @@ char* readWord(FILE *file)
int index = 0; // Position im Puffer
int c; // Variable für jedes gelesene Zeichen
// Whitespace überspringen
while(isspace(c = fgetc(file))); //isspace checkt ob gelesenes Zeichen whitespace ist, wenn ja 1 wenn nein 0
// Whitespace und Delimiters überspringen
while((c = fgetc(file)) != EOF && (isspace(c) || c == ',' || c == ';' || c == '.'));
// Buchstaben einlesen bis nächstes whitespace/EOF
while(c != EOF && !isspace(c) && index < MAX_WORD_LEN - 1) // -1 wegen Nullterminator
// Buchstaben einlesen bis nächstes whitespace/Delimiter/EOF
while(c != EOF && !isspace(c) && c != ',' && c != ';' && c != '.' && index < MAX_WORD_LEN - 1) //-1 wegen Nullterminator
{
word[index++] = (char)c;
word[index++] = (char)toupper(c); // Konvertiere zu Großbuchstaben
c = fgetc(file);
}
word[index] = '\0'; // Nullterminator (= Ende String)
// Leere überspringen
if(index == 0)
return NULL;
return strdup(word); // Rückgabe string, dynamisch allokiert da Zeiger auf lokalen Puffer zurückgegeben
}

Binary file not shown.

View File

@ -9,8 +9,8 @@ unityfolder = ./unity
# --------------------------
# initiales Spiel bauen
# --------------------------
wordsalad_initial:
$(CC) -o wordsalad_ourversion -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
wordsalad_ourversion:
$(CC) -o wordsalad_ourversion -L. $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
# --------------------------
# Normales Spiel bauen

BIN
Start_Linux/runTests Executable file

Binary file not shown.