From 10af0980d3bb4a712867815f0e8c81f60f177fbe Mon Sep 17 00:00:00 2001 From: LukVal54 Date: Sat, 1 Nov 2025 19:31:43 +0100 Subject: [PATCH] =?UTF-8?q?fuelleSalatmitW=C3=B6rtern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Start_Linux/game.c | 48 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/Start_Linux/game.c b/Start_Linux/game.c index c704151..161a49f 100644 --- a/Start_Linux/game.c +++ b/Start_Linux/game.c @@ -98,14 +98,14 @@ int findPossiblePositions(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN] { positions[positionamount].x = k; positions[positionamount].y = i; - positions[positionamount].richt = RECHTS; + positions[positionamount].richtung = RECHTS; positionamount++; } if(untenfrei) { positions[positionamount].x = k; positions[positionamount].y = i; - positions[positionamount].richt = UNTEN; + positions[positionamount].richtung = UNTEN; positionamount++; } } @@ -114,4 +114,48 @@ int findPossiblePositions(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN] return positionamount; +} + +//Nun muss für jedes Wort per zufall ausgesucht werden Wo es beginnt und welche richtung aus +//den ganzen möglichen fällen und dann das wort ins grid gezeichnet werden. +int fuelleSalatMitWörtern(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], Position position[], unsigned int wordcount) +{ + srand(time(NULL)); + int gesetzteWörter = 0; + int positionsamount; + int positiongewählt; + char *word; + for(int i = 0; i < wordcount; i++) + { + positionsamount = findPossiblePositions(salad, searchFieldLen, words, i, position); + if(positionsamount > 0) + { + gesetzteWörter++; + positiongewählt = rand() % positionsamount; + if(position[positiongewählt].richtung == RECHTS) + { + word = words[i]; + int p = position[positiongewählt].x; + int t = 0; + for(int k = p; k < p + strlen(word); k++) + { + salad[position[positiongewählt].y][k] = word[t]; + t++; + } + } + if(position[positiongewählt].richtung == UNTEN) + { + word = words[i]; + int up = position[positiongewählt].y; + int ut = 0; + for(int uk = up; uk < up +strlen(word); uk++) + { + salad[uk][position[positiongewählt].x] = word[ut]; + ut++; + } + } + } + } + return gesetzteWörter; + } \ No newline at end of file