Eddited the Method createWordSalad, still UNFINISHED

This commit is contained in:
Tobias Grampp 2025-10-30 17:13:01 +01:00
parent 34e5f347ef
commit 125723f313

View File

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