Compare commits
No commits in common. "12464e4152988df33ddbf551d88d4605b871729e" and "7e8bbea8a8a79e6cb91d340e1b949ac413fd01f1" have entirely different histories.
12464e4152
...
7e8bbea8a8
@ -13,109 +13,11 @@
|
|||||||
// Creates the word salad by placing words randomly and filling empty spaces
|
// 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 createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
||||||
{
|
{
|
||||||
// wipe field
|
Printf("Hello World+1");
|
||||||
int placedWords = 0;
|
|
||||||
for (int i = 0; searchFieldLen < i; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; searchFieldLen < j; i++)
|
|
||||||
salad[i][j] = EMPTY_CHAR;
|
|
||||||
}
|
|
||||||
// place Words
|
|
||||||
for (int wordNumber = 0; wordNumber < wordCount; wordNumber++)
|
|
||||||
{
|
|
||||||
srand(time(NULL));
|
|
||||||
int wordlength = strlen(words[wordNumber]);
|
|
||||||
|
|
||||||
int placed = 0;
|
|
||||||
|
|
||||||
for (int try = 0; (try < MAX_RAND_TRIES_PER_WORD) && !placed; try++)
|
|
||||||
{
|
|
||||||
int horizontal = rand() % 2;
|
|
||||||
|
|
||||||
int x = rand() % searchFieldLen;
|
|
||||||
int y = rand() % searchFieldLen;
|
|
||||||
|
|
||||||
if (horizontal = 1)
|
|
||||||
{
|
|
||||||
if (x + wordlength > searchFieldLen) // word does not fit
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fits = 1;
|
|
||||||
|
|
||||||
for (int i = 0; i < wordlength; i++) // position already occupied by other word
|
|
||||||
{
|
|
||||||
if (salad[y][x + 1] != EMPTY_CHAR)
|
|
||||||
{
|
|
||||||
fits = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fits = 1)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < wordlength; i++)
|
|
||||||
{
|
|
||||||
salad[y][x + 1] = words[wordNumber][i];
|
|
||||||
}
|
|
||||||
placed = 1;
|
|
||||||
placedWords++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ((y + wordlength) > searchFieldLen)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fits = 1;
|
|
||||||
|
|
||||||
for (int i = 0; i < wordlength; i++) // position already occupied by other word
|
|
||||||
{
|
|
||||||
if (salad[y + 1][x] != EMPTY_CHAR)
|
|
||||||
;
|
|
||||||
{
|
|
||||||
fits = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fits = 1)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < wordlength; i++)
|
|
||||||
{
|
|
||||||
salad[y + 1][x] = words[wordNumber][i];
|
|
||||||
}
|
|
||||||
placed = 1;
|
|
||||||
placedWords++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// fill rest with random characters
|
|
||||||
|
|
||||||
for (int i = 0; i < searchFieldLen; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < searchFieldLen; j++)
|
|
||||||
{
|
|
||||||
if (salad[i][j] == EMPTY_CHAR)
|
|
||||||
{
|
|
||||||
salad[i][j] = (rand() % ((90 - 65) + 1)) + 65; // 90 ist Z in ASCII und A ist 65
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return placedWords;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the word salad to console
|
// Prints the word salad to console
|
||||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < searchFieldLen; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < searchFieldLen; j++)
|
|
||||||
{
|
|
||||||
printf("%c", salad[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Start_Windows/input.o
Normal file
BIN
Start_Windows/input.o
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user