From e135756db54728a03557e9d5a4964532e5d0c36b Mon Sep 17 00:00:00 2001 From: Tobias Grampp Date: Thu, 30 Oct 2025 16:32:44 +0100 Subject: [PATCH] Added Method createWordSalad, but UNFINISHED --- Start_Windows/game.c | 27 +++++++++++++++++++++++++-- Start_Windows/input.c | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Start_Windows/game.c b/Start_Windows/game.c index 2772b71..5a3a56b 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -7,14 +7,37 @@ #define MAX_RAND_TRIES_PER_WORD 10 #define EMPTY_CHAR 0 +#define RANDOMNUMBER(minimum, maximum) rand() % (maximum – minimum + 1) + minimum //Macro to generate a Number between minimum and maximum (both are possibly rolled) + //TODO: Spiellogik implementieren: -/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren - * restliche Felder mit zufälligen Buchstaben füllen */ +/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren --> Vorher eingabe festlegen! + * restliche Felder mit zufälligen Buchstaben füllen - erldeigt*/ // 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) { + srand(time(NULL));//sets the seed of the random function to the current time in order to guarantee unique results + for(int i = 0; i < searchFieldLen; i++)//Clears the array to simplify the process of findings empty slots + { + for(int j = 0; j < searchFieldLen; j++) + { + salad[i][j] = 63; + } + } + for(int i = 0; i < wordCount; i++) + { + + } + + for(int i = 0; i < searchFieldLen; i++)//Randomly fills the rest of the array + { + for(int j = 0; j < searchFieldLen; j++) + { + if((salad[i][j] == 63)//checks if there is already a letter of a word placed in here + salad[i][j] = RANDOMNUMBER(65, 90);//fills "empty" chars in word salad with a random upper case letter + } + } } // Prints the word salad to console diff --git a/Start_Windows/input.c b/Start_Windows/input.c index ed77805..3f100f3 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -9,4 +9,4 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { -} \ No newline at end of file +}