Merge branch 'feature-game' of https://git.efi.th-nuernberg.de/gitea/hopfenu103561/Team_3 into feature-game
This commit is contained in:
commit
4586b2d089
1 file changed
+73
-1
@@ -3,7 +3,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define MAX_RAND_TRIES_PER_WORD 10
|
#define MAX_RAND_TRIES_PER_WORD 1000
|
||||||
#define EMPTY_CHAR 0
|
#define EMPTY_CHAR 0
|
||||||
|
|
||||||
//TODO: Spiellogik implementieren:
|
//TODO: Spiellogik implementieren:
|
||||||
@@ -13,5 +13,77 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
|
srand(time(NULL));
|
||||||
|
int i,j;
|
||||||
|
int Woertergesetzt = 0;
|
||||||
|
for (i=0 ; i<MAX_SEARCH_FIELD_LEN;i++)
|
||||||
|
{
|
||||||
|
for (j=0 ; j<MAX_SEARCH_FIELD_LEN;j++)
|
||||||
|
{
|
||||||
|
salad[i][j] = EMPTY_CHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (unsigned int k = 0 ; k < wordCount ; k++)
|
||||||
|
{
|
||||||
|
int richtigplatziert = 0;
|
||||||
|
unsigned int laenge = strlen(words[k]);
|
||||||
|
for (int f = 0 ; f < MAX_RAND_TRIES_PER_WORD && !richtigplatziert ; f++)
|
||||||
|
{
|
||||||
|
unsigned int ausrichtung, zeile, spalte;
|
||||||
|
ausrichtung = rand() % 2;
|
||||||
|
zeile = rand() % (searchFieldLen);
|
||||||
|
spalte = rand() % (searchFieldLen);
|
||||||
|
|
||||||
|
if (ausrichtung == 0) // horizontal
|
||||||
|
{
|
||||||
|
if (spalte + laenge <= searchFieldLen)
|
||||||
|
{
|
||||||
|
int moeglichePosition = 1;
|
||||||
|
for (unsigned int i1 = 0; i1 < laenge; i1++)
|
||||||
|
{
|
||||||
|
if (salad[zeile][spalte + i1] != EMPTY_CHAR)
|
||||||
|
moeglichePosition = 0;
|
||||||
|
}
|
||||||
|
if (moeglichePosition)
|
||||||
|
{
|
||||||
|
for (unsigned int i1 = 0; i1 < laenge; i1++)
|
||||||
|
salad[zeile][spalte + i1] = words[k][i1];
|
||||||
|
richtigplatziert = 1;
|
||||||
|
Woertergesetzt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // vertikal
|
||||||
|
{
|
||||||
|
if (zeile + laenge <= searchFieldLen)
|
||||||
|
{
|
||||||
|
int moeglichePosition = 1;
|
||||||
|
for (unsigned int i1 = 0; i1 < laenge; i1++)
|
||||||
|
{
|
||||||
|
if (salad[zeile + i1][spalte] != EMPTY_CHAR)
|
||||||
|
moeglichePosition = 0;
|
||||||
|
}
|
||||||
|
if (moeglichePosition)
|
||||||
|
{
|
||||||
|
for (unsigned int i1 = 0; i1 < laenge; i1++)
|
||||||
|
salad[zeile + i1][spalte] = words[k][i1];
|
||||||
|
richtigplatziert = 1;
|
||||||
|
Woertergesetzt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// restliche Felder mit zufaelligen Buchstaben fuellen
|
||||||
|
for (i = 0; i < (int)searchFieldLen; i++)
|
||||||
|
{
|
||||||
|
for (j = 0; j < (int)searchFieldLen; j++)
|
||||||
|
{
|
||||||
|
if (salad[i][j] == EMPTY_CHAR)
|
||||||
|
salad[i][j] = 'A' + rand() % 26;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Woertergesetzt;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user