From 125723f3135f6eb8f3d5c30c037952eece0eb770 Mon Sep 17 00:00:00 2001 From: Tobias Grampp Date: Thu, 30 Oct 2025 17:13:01 +0100 Subject: [PATCH] Eddited the Method createWordSalad, still UNFINISHED --- Start_Windows/game.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Start_Windows/game.c b/Start_Windows/game.c index 6d2a2ce..086ccd6 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -10,8 +10,11 @@ #define RANDOMNUMBER(minimum, maximum) ((rand() % ((maximum)-(minimum)+1))+cd 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 --> Vorher eingabe festlegen! - * restliche Felder mit zufälligen Buchstaben füllen - erldeigt*/ +/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren - erledigt + * restliche Felder mit zufälligen Buchstaben füllen - erldeigt + * Rückgabewert ist Anzahl der platzierten Wörter - erledigt + * Es muss gecheckt werden, ob ein anderes platziertes Word fertig ist + * Wenn ein Wort nicht zufällig platziert werden kann, muss es systemtatisch platziert werden!*/ // 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) @@ -24,10 +27,29 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi salad[i][j] = 63; } } - + int wordamount = 0; for(int i = 0; i < wordCount; i++) { - + int wordlength = 0; + while(words[i][wordlength] != '0')//gets the length of the current word + wordlength++; + int startPosition1 = RANDOMNUMBER(0, MAX_SEARCH_FIELD_LEN - wordlength);//gets a random starting position for the word + int startPosition2 = RANDOMNUMBER(0, MAX_SEARCH_FIELD_LEN);//gest a second coordinate for the starting position + if(RANDOMNUMBER(0,1) < 1)//Flips a coin whether the number is vertical or horizontal + { + for(int j = 0; j < wordlength; j++) + { + salad[startPosition1 + j][startPosition2] = words[i][j] + } + } + else + { + for(int j = 0; j < wordlength; j++) + { + salad[startPosition2][startPosition1 + j] = words[i][j] + } + } + wordamount++; } for(int i = 0; i < searchFieldLen; i++)//Randomly fills the rest of the array @@ -40,6 +62,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi } } } + return wordamount; } // Prints the word salad to console