4 Commits
Author SHA1 Message Date
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
3 changed files with 31 additions and 15 deletions

No files matched your search

+16 -11
View File
@@ -6,7 +6,7 @@
#define MAX_RAND_TRIES_PER_WORD 10 #define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0 #define EMPTY_CHAR 0
//TODO: Spiellogik implementieren: //DONE: Spiellogik implementieren:
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren /* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
* restliche Felder mit zufälligen Buchstaben füllen */ * restliche Felder mit zufälligen Buchstaben füllen */
@@ -16,16 +16,21 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
srand((unsigned int)time(NULL)); srand((unsigned int)time(NULL));
typedef enum{
Horizontal,
Vertikal
} Direction;
for (unsigned int row = 0; row < searchFieldLen; row++) for (unsigned int row = 0; row < searchFieldLen; row++)
{ {
for (unsigned int col = 0; col < searchFieldLen; col++) for (unsigned int col = 0; col < searchFieldLen; col++)
{ {
salad[row][col] = EMPTY_CHAR; // Initialize all cells to empty salad[row][col] = EMPTY_CHAR; // Alle Felder leer setzen
} }
} }
unsigned int placedWords = 0; unsigned int placedWords = 0;
// 2. Alle Wörter nacheinander platzieren // 2. Alle Wörter nacheinander platzieren
for (unsigned int i = 0; i < wordCount; i++) for (unsigned int i = 0; i < wordCount; i++)
@@ -43,9 +48,9 @@ for (unsigned int row = 0; row < searchFieldLen; row++)
unsigned int startRow = 0; unsigned int startRow = 0;
unsigned int startCol = 0; unsigned int startCol = 0;
unsigned int direction = rand() % 2; Direction direction = (Direction)(rand()%2);
if (direction == 0) // Horizontal if (direction == Horizontal)
{ {
startRow = rand() % searchFieldLen; startRow = rand() % searchFieldLen;
startCol = rand() % (searchFieldLen - wordLen + 1); startCol = rand() % (searchFieldLen - wordLen + 1);
@@ -56,12 +61,12 @@ for (unsigned int row = 0; row < searchFieldLen; row++)
startCol = rand() % searchFieldLen; startCol = rand() % searchFieldLen;
} }
// 3. Überprüfen, ob das Wort an der gewählten Position platziert werden kann // Überprüfen ob das Wort an der gewählten Position platziert werden kann
int canPlace = 1; int canPlace = 1;
for (unsigned int j = 0; j < wordLen; j++) for (unsigned int j = 0; j < wordLen; j++)
{ {
if (direction == 0) // Horizontal if (direction == Horizontal)
{ {
if (salad[startRow][startCol + j] != EMPTY_CHAR && salad[startRow][startCol + j] != words[i][j]) if (salad[startRow][startCol + j] != EMPTY_CHAR && salad[startRow][startCol + j] != words[i][j])
{ {
@@ -84,7 +89,7 @@ for (unsigned int row = 0; row < searchFieldLen; row++)
// Wort platzieren // Wort platzieren
for (unsigned int j = 0; j < wordLen; j++) for (unsigned int j = 0; j < wordLen; j++)
{ {
if (direction == 0) // Horizontal if (direction == Horizontal)
{ {
salad[startRow][startCol + j] = words[i][j]; salad[startRow][startCol + j] = words[i][j];
} }
@@ -94,9 +99,9 @@ for (unsigned int row = 0; row < searchFieldLen; row++)
} }
} }
placedWords++; placedWords++;
placed = 1; //Markiert als gesetzt
printf("Wort '%s' nach %u Versuchen platziert.\n", words[i], attempt + 1); //Ausgabe als Test
} }
placed = 1; // Mark as placed to exit the attempt loop
} }
} }
@@ -115,5 +120,5 @@ for (unsigned int row = 0; row < searchFieldLen; row++)
printf("Placed %u words out of %u\n", placedWords, wordCount); printf("Placed %u words out of %u\n", placedWords, wordCount);
return placedWords; // Return the number of successfully placed words return placedWords; // Gibt Anzahl gesetzter Wörter zurück
} }
+1 -1
View File
@@ -3,7 +3,7 @@
#include "input.h" #include "input.h"
#define MAX_SEARCH_FIELD_LEN 100 #define MAX_SEARCH_FIELD_LEN 20
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);
+14 -3
View File
@@ -1,21 +1,32 @@
#include <stdio.h> #include <stdio.h>
#include "graphicalGame.h"
#include "game.h" #include "game.h"
int main(void) int main(void)
{ {
char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
const char words[][MAX_WORD_LEN] = { char words[][MAX_WORD_LEN] = {
"HALLO", "HALLO",
"WELT", "WELT",
"AUTO" "AUTO",
"BIRNE",
"APFEL",
"BANANE",
"LANGESWORT",
"REITSPORT",
"APFELBAUM",
"DRACULA",
"LAPTOP",
"BILDSCHRIM",
"HAUS"
}; };
unsigned int wordCount = sizeof(words) / sizeof(words[0]); unsigned int wordCount = sizeof(words) / sizeof(words[0]);
int placedWords = createWordSalad(salad, MAX_SEARCH_FIELD_LEN, words, wordCount); int placedWords = createWordSalad(salad, MAX_SEARCH_FIELD_LEN, words, wordCount);
startGame(salad, MAX_SEARCH_FIELD_LEN, words, wordCount, 1000);
printf("Placed words: %d\n", placedWords); printf("Placed words: %d\n", placedWords);
return 0; return 0;