Compare commits
No commits in common. "55e912ccf3dea0fc076360921dcd67c06de305df" and "7c06c399c6ab4632a100b9667cb9aacdcd9d141e" have entirely different histories.
55e912ccf3
...
7c06c399c6
@ -6,8 +6,6 @@
|
|||||||
#define MAX_RAND_TRIES_PER_WORD 10
|
#define MAX_RAND_TRIES_PER_WORD 10
|
||||||
#define EMPTY_CHAR 0
|
#define EMPTY_CHAR 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//TODO: Spiellogik implementieren:
|
//TODO: Spiellogik implementieren:
|
||||||
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||||
@ -15,100 +13,7 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
int direction = 0;
|
|
||||||
int step = 0;
|
|
||||||
int added = 0;
|
|
||||||
int addedWords = 0;
|
|
||||||
int positionX = 0;
|
|
||||||
int positionY = 0;
|
|
||||||
|
|
||||||
srand(time(NULL));
|
|
||||||
|
|
||||||
for(int i = 0; i < searchFieldLen; i++)
|
|
||||||
{
|
|
||||||
for(int j = 0; j < searchFieldLen; j++)
|
|
||||||
{
|
|
||||||
salad[i][j] = EMPTY_CHAR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while(step <= wordCount)
|
|
||||||
{
|
|
||||||
int tries = 0;
|
|
||||||
int wordLength = 0;
|
|
||||||
direction = rand() % 1;
|
|
||||||
|
|
||||||
for (int i = 0; i < MAX_WORD_LEN; i++)
|
|
||||||
{
|
|
||||||
if (words[step][i] == '\0')
|
|
||||||
break;
|
|
||||||
wordLength++;
|
|
||||||
}
|
|
||||||
if(direction == 0)
|
|
||||||
{
|
|
||||||
while(added <= 0 && tries < MAX_RAND_TRIES_PER_WORD){
|
|
||||||
positionY = rand() % searchFieldLen-1;
|
|
||||||
positionX = rand() % searchFieldLen-1;
|
|
||||||
if(searchFieldLen - positionX >= wordLength)
|
|
||||||
{
|
|
||||||
|
|
||||||
for(int i = 0; i < searchFieldLen; i++)
|
|
||||||
{
|
|
||||||
if(salad[positionY][positionX+i] != EMPTY_CHAR)
|
|
||||||
{
|
|
||||||
tries++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (int j = 0; j < searchFieldLen; j++)
|
|
||||||
{
|
|
||||||
salad[positionY][positionX+j] = words[step][j];
|
|
||||||
added = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tries++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
step++;
|
|
||||||
tries = 0;
|
|
||||||
added = 0;
|
|
||||||
}
|
|
||||||
if(direction == 1)
|
|
||||||
{
|
|
||||||
while(added <= 0 && tries < MAX_RAND_TRIES_PER_WORD){
|
|
||||||
positionY = rand() % searchFieldLen-1;
|
|
||||||
positionX = rand() % searchFieldLen-1;
|
|
||||||
if(searchFieldLen - positionY >= wordLength)
|
|
||||||
{
|
|
||||||
|
|
||||||
for(int i = 0; i < searchFieldLen; i++)
|
|
||||||
{
|
|
||||||
if(salad[positionY+i][positionX] != EMPTY_CHAR)
|
|
||||||
{
|
|
||||||
tries++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (int j = 0; j < searchFieldLen; j++)
|
|
||||||
{
|
|
||||||
salad[positionY+j][positionX] = words[step][j];
|
|
||||||
added = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tries++;
|
|
||||||
}
|
|
||||||
step++;
|
|
||||||
tries = 0;
|
|
||||||
added = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return addedWords;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the word salad to console
|
// Prints the word salad to console
|
||||||
|
|||||||
Binary file not shown.
@ -14,7 +14,7 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|||||||
char* token;
|
char* token;
|
||||||
while(fgets(zeile, MAX_LINE_LEN, file)!=NULL)
|
while(fgets(zeile, MAX_LINE_LEN, file)!=NULL)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_LINE_LEN; i++)
|
for (int i = 0; i < 1024; i++)
|
||||||
{
|
{
|
||||||
if (zeile[i] >= 'a'&&zeile[i] <= 'z')
|
if (zeile[i] >= 'a'&&zeile[i] <= 'z')
|
||||||
{
|
{
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user