generated from freudenreichan/info2Praktikum-Wortsalat
Erster Entwurf des Ausfbaus vom Salat
This commit is contained in:
parent
9503b1e6f0
commit
82fafb02fd
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.o
|
||||
*.exe
|
||||
@ -10,9 +10,65 @@
|
||||
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||
|
||||
//words und salad sind char arrays --> laengstes wort sind 100 zeichen
|
||||
|
||||
// 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)
|
||||
{
|
||||
srand(time(NULL));
|
||||
for(int i = 0; i < MAX_NUMBER_OF_WORDS; i++) //geht Wortliste durch und fuellt die Woerter erstmal in salad
|
||||
{
|
||||
if(word[i][0] == NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
int rand = rand() % (wordCount - (-wordCount) + 1) - wordCount;
|
||||
int value = (rand*rand) / rand;
|
||||
|
||||
if(rand < 0) //wenn rand eine negative Zahl ist, soll das Wort horizontal platziert werden
|
||||
{
|
||||
for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++) // geht salad durch
|
||||
{
|
||||
if(salad[j][i] == NULL) //sucht horizontal nach einer freien Zeile in salad
|
||||
{
|
||||
for(int h = 0; h < MAX_SEARCH_FIELD_LEN; h++) //kopiert die Zeichen in word in die Zeile in salad
|
||||
{
|
||||
salad[j][h] = word[value][h]; //value ist der Wert des zufaelligen Wortes, also der Platz im word Array
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else //vertikal platzieren
|
||||
{
|
||||
for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++) // geht salad durch
|
||||
{
|
||||
if(salad[i][j] == NULL) //sucht vertikal nach einer freien Zeile in salad
|
||||
{
|
||||
for(int h = 0; h < MAX_SEARCH_FIELD_LEN; h++) //kopiert die Zeichen in word in die Spalte in salad
|
||||
{
|
||||
salad[h][j] = word[value][h]; //value ist der Wert des zufaelligen Wortes, also der Platz im word Array
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//jetzt ist die Wortliste leer oder es wurden alle Worte in Salad geschrieben.
|
||||
|
||||
//Restliche Plaetze mit random Buchstaben fuellen:
|
||||
int num = rand()%(26 - 1 + 1) - 1;
|
||||
char letter = 64 + num;
|
||||
|
||||
for(int i = 0; i < MAX_SEARCH_FIELD_LEN; i++)
|
||||
{
|
||||
for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++)
|
||||
{
|
||||
if(salad[i][j] == NULL)
|
||||
{
|
||||
salad[i][j] = letter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user