generated from freudenreichan/info2Praktikum-Wortsalat
final changes to game.c
This commit is contained in:
parent
8bff068cee
commit
195ce39698
@ -14,15 +14,19 @@
|
||||
|
||||
// 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) {
|
||||
|
||||
int addedWords = 0;
|
||||
int attempts = 0;
|
||||
int added = 0; // = 1 wäre Wort hinzugefügt
|
||||
int space = 0; // = 1 wäre Wort zu lang für diese Stelle
|
||||
unsigned long long wordLength = 0;
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
for (int i = 0; i < searchFieldLen; i++) {
|
||||
for (int j = 0; j < searchFieldLen; j++) {
|
||||
for (int i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for (int j = 0; j < searchFieldLen; j++)
|
||||
{
|
||||
salad[i][j] = '.'; //Füllen des gesamten Arrays mit '.'
|
||||
}
|
||||
}
|
||||
@ -31,7 +35,8 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
|
||||
wordLength = strlen(words[i]);
|
||||
|
||||
while (attempts <= MAX_RAND_TRIES_PER_WORD && added != 1) {
|
||||
while (attempts <= MAX_RAND_TRIES_PER_WORD && added != 1)
|
||||
{
|
||||
int direction = rand() % 2;// 0 = Horizontal, 1 = Vertikal
|
||||
if (direction == 0) //Horizontal
|
||||
{
|
||||
@ -97,7 +102,8 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
}
|
||||
for (int i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for (int j = 0; j < searchFieldLen; j++) {
|
||||
for (int j = 0; j < searchFieldLen; j++)
|
||||
{
|
||||
if (salad[i][j] == '.')
|
||||
{
|
||||
salad[i][j] = rand()%('Z'-'A'+1)+'A';//Zufällige Befüllung der noch nicht befüllten Felder
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user