fuelleSalatmitWörtern

This commit is contained in:
LukVal54 2025-11-01 19:31:43 +01:00
parent cf577e2a37
commit 10af0980d3

View File

@ -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;
}