20 Commits
Author SHA1 Message Date
Angelos c5837d86ad Spielfeld wieder größer gemacht 2026-10-22 17:00:56 +02:00
Angelos e2df312438 gametest file entfernt 2026-10-22 16:16:52 +02:00
Mihaela Creciun f8deef43e1 Worteinlesen mit strncpy angepasst 2026-10-21 13:55:13 +02:00
Mihaela Creciun a1a0b615a7 Implementierung der Worteinlesefunktion 2026-10-20 22:18:24 +02:00
Angelos 60bb394fb7 Spielfeld kleiner gemacht 2026-10-20 19:47:41 +02:00
Angelos d7c7fe76f3 um Grafikversion erweitert 2026-10-20 19:47:21 +02:00
Angelos 1725da2148 mehr wörter zum testen 2026-10-20 18:56:24 +02:00
Angelos bd830b2044 Logikfehler Z102 behoben und Enum für Richtungen hinzugefügt 2026-10-20 18:56:24 +02:00
perschkema103633 1d87ea69bc gametest.c geändert 2026-10-19 22:45:53 +02:00
perschkema103633 9b704552cc Spiellogik implementiert und mit gametest.c getestet 2026-10-19 22:32:49 +02:00
Angelos 3fc54ae264 wordsalad_myversion in gitignore aufgenommen 2026-10-18 18:19:18 +02:00
Angelos fa28bc4965 Testdateien entfernt 2026-10-18 18:02:35 +02:00
Angelos f825ee0131 makefile für wordsalad_myversion erstellt 2026-10-18 17:40:04 +02:00
Angelos 683b1cdf7e Spielinitialiserung in main.c 2026-10-18 17:38:47 +02:00
Angelos df82424793 Spielinitialiserung in main.c 2026-10-18 17:19:43 +02:00
Mihaela Creciun 572f312fa5 test.c Mihaela Creciun 2026-10-15 10:54:44 +02:00
Mihaela Creciun b4db35ec2a test Mihaela Creciun 2026-10-15 10:49:54 +02:00
tsingosan100564 2364d9f187 test2 angelos 2026-10-15 10:43:45 +02:00
perschkema103633 aed0be1dca testdatei Max 2026-10-15 10:39:45 +02:00
tsingosan100564 42a5d91205 testdatei angelos 2026-10-15 10:38:25 +02:00
6 changed files with 169 additions and 4 deletions

No files matched your search

+1
View File
@@ -37,6 +37,7 @@
*.hex
Startcode/wordsalad_initial
Startcode/wordsalad
Startcode/wordsalad_myversion
test
# Debug files
+108 -1
View File
@@ -6,7 +6,7 @@
#define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0
//TODO: Spiellogik implementieren:
//DONE: Spiellogik implementieren:
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
* restliche Felder mit zufälligen Buchstaben füllen */
@@ -14,4 +14,111 @@
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
{
srand((unsigned int)time(NULL));
typedef enum{
Horizontal,
Vertikal
} Direction;
for (unsigned int row = 0; row < searchFieldLen; row++)
{
for (unsigned int col = 0; col < searchFieldLen; col++)
{
salad[row][col] = EMPTY_CHAR; // Alle Felder leer setzen
}
}
unsigned int placedWords = 0;
// 2. Alle Wörter nacheinander platzieren
for (unsigned int i = 0; i < wordCount; i++)
{
unsigned int wordLen = strlen(words[i]);
int placed = 0;
// Wort darf nicht länger als das Spielfeld sein
if (wordLen == 0 || wordLen > searchFieldLen)
{
continue;
}
for (unsigned int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD && !placed; attempt++)
{
unsigned int startRow = 0;
unsigned int startCol = 0;
Direction direction = (Direction)(rand()%2);
if (direction == Horizontal)
{
startRow = rand() % searchFieldLen;
startCol = rand() % (searchFieldLen - wordLen + 1);
}
else // Vertikal
{
startRow = rand() % (searchFieldLen - wordLen + 1);
startCol = rand() % searchFieldLen;
}
// Überprüfen ob das Wort an der gewählten Position platziert werden kann
int canPlace = 1;
for (unsigned int j = 0; j < wordLen; j++)
{
if (direction == Horizontal)
{
if (salad[startRow][startCol + j] != EMPTY_CHAR && salad[startRow][startCol + j] != words[i][j])
{
canPlace = 0;
break;
}
}
else // Vertikal
{
if (salad[startRow + j][startCol] != EMPTY_CHAR && salad[startRow + j][startCol] != words[i][j])
{
canPlace = 0;
break;
}
}
}
if (canPlace)
{
// Wort platzieren
for (unsigned int j = 0; j < wordLen; j++)
{
if (direction == Horizontal)
{
salad[startRow][startCol + j] = words[i][j];
}
else // Vertikal
{
salad[startRow + j][startCol] = words[i][j];
}
}
placedWords++;
placed = 1; //Markiert als gesetzt
printf("Wort '%s' nach %u Versuchen platziert.\n", words[i], attempt + 1); //Ausgabe als Test
}
}
}
// 4. Restliche Felder mit zufälligen Buchstaben füllen
for (unsigned int row = 0; row < searchFieldLen; row++)
{
for (unsigned int col = 0; col < searchFieldLen; col++)
{
if (salad[row][col] == EMPTY_CHAR)
{
salad[row][col] = 'A' + (rand() % 26); // Zufälliger Buchstabe von A-Z
}
}
}
printf("Placed %u words out of %u\n", placedWords, wordCount);
return placedWords; // Gibt Anzahl gesetzter Wörter zurück
}
+43
View File
@@ -8,5 +8,48 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
if (file == NULL || words == NULL || maxWordCount == 0) {
return 0;
}
unsigned int count = 0;
char currentWord[MAX_WORD_LEN];
size_t length = 0;
int tooLong = 0;
int ch;
while (count < maxWordCount && (ch = fgetc(file)) != EOF) {
if (ch == ',' || ch == ';' || isspace((unsigned char)ch)) {
if (length > 0 && !tooLong) {
currentWord[length] = '\0';
strncpy(words[count], currentWord, MAX_WORD_LEN);
count++;
}
length = 0;
tooLong = 0;
}
else if (!tooLong) {
if (length < MAX_WORD_LEN - 1) {
currentWord[length] = (char)toupper((unsigned char)ch);
length++;
}
else {
tooLong = 1;
length = 0;
}
}
}
if (count < maxWordCount && length > 0 && !tooLong) {
currentWord[length] = '\0';
strncpy(words[count], currentWord, MAX_WORD_LEN);
count++;
}
return (int)count;
}
+10 -2
View File
@@ -35,9 +35,17 @@ int main(int argc, char *argv[])
// Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
if(placedWords==wordCount){ //checked if all words were succesfully placed
startGame(wordSalad, SALAD_SIZE, words, wordCount, 1000); // Starting the game
}
else{
printf("Fehler! Es konnten nicht alle Wörter plaziert werden\n"); //Error if some words couldnt be placed
}
// TODO:
// Check if all words were successfully placed
// DONE
// Check if all words were successfully placed3
// Start the game if successful
// error message if some words couldn't be placed
+6
View File
@@ -40,6 +40,12 @@ game.o: $(codefolder)/game.c
graphicalGame.o: $(codefolder)/graphicalGame.c
$(CC) -I$(raylibfolder) -c $(CFLAGS) $(codefolder)/graphicalGame.c
# --------------------------
# mein Spiel bauen
#---------------------------
wordsalad_myversion: main.o
$(CC) -o wordsalad_myversion main.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
# --------------------------
# Unit Tests
+1 -1
View File
@@ -27,7 +27,7 @@ void print_test_result(int result) {
printf(RED "FAILED\n" RESET);
}
}
// ---------- Tests für input.c ----------
void test_readWords_simple(void) {
FILE *f = fopen("testwords_simple.txt", "r");