Compare commits

..

No commits in common. "249298afc631a3ede8f76bffcdd0e8c2d0ea851d" and "20465e1dc2bc8469b3b50c02a475fec03a4863b4" have entirely different histories.

8 changed files with 30 additions and 45 deletions

View File

@ -17,13 +17,12 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
int addedWords = 0; int addedWords = 0;
int attempts = 0; //Anzahl an Versuchen ein Wort hinzuzufügen int attempts = 0; //Anzahl an Versuchen ein Wort hinzuzufügen
int added = 0; //0 Wort nicht hinzugefügt , 1 Wort hinzugefügt int added = 0; //0 Wort nicht hinzugefügt , 1 Wort hinzugefügt
int space = 0; // 1 = Wort zu lang für diese Stelle int space = 1; // 0 Wort zu lang, 1 Wort passt an diese Stelle
unsigned long long wordLength = 0; unsigned long long wordLength = 0;
srand(time(NULL));
for (int i = 0; i < searchFieldLen; i++) { for (int i = 0; i < searchFieldLen; i++) {
for (int j = 0; j < searchFieldLen; j++) { for (int j = 0; j < searchFieldLen; j++) {
salad[i][j] = '.'; //Füllen des gesamten Arrays mit Nullen salad[i][j] = EMPTY_CHAR; //Füllen des gesamten Arrays mit Nullen
} }
} }
for (int i=0; i < wordCount; i++) { for (int i=0; i < wordCount; i++) {
@ -33,53 +32,33 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
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 int direction = rand() % 2;// 0 Horizontal, 1 Vertikal
if (direction == 0) { if (direction == 0) {
int spalte = rand() % searchFieldLen; int collumn = rand() % searchFieldLen;
int reihe = rand() % searchFieldLen; int row = rand() % searchFieldLen;
for (int j = 0; j < wordLength; j++) for (int j = 0; j < wordLength; j++)
{ {
if (salad[reihe][spalte+j] != '.') //Prüfen ob das Wort ein bereits vorhandenes Wort überspeichern würde if (salad[row][collumn+j] != EMPTY_CHAR) {space = 0; break;}
{ //Prüfen ob das Wort ein bereits vorhandenes Wort überspeichern würde
space = 1;
break;
}
} }
if ((spalte + wordLength >= searchFieldLen-1) || (space == 1)) if ((collumn + wordLength >= searchFieldLen-1) || (space == 0)) {attempts++;}
{
attempts++;
}
//Prüfen ob Wort an der Stelle (Zeile, Spalte) in das Array passt //Prüfen ob Wort an der Stelle (Zeile, Spalte) in das Array passt
else else {for (int j = 0; j < wordLength; j++)
{ {
for (int j = 0; j < wordLength; j++) salad[row][collumn+j] = words[i][j]; //Einfügen des Wortes Buchstabe für Buchstabe
{ }
salad[reihe][spalte+j] = words[i][j]; //Einfügen des Wortes Buchstabe für Buchstabe
}
added=1; added=1;
addedWords++; addedWords++;
}
} }
else if (direction == 1) // Vertikal }
{ else if (direction == 1) {// Vertikal funktioniert analog zu horizontal
int spalte = rand() % searchFieldLen; int collumn = rand() % searchFieldLen;
int reihe = rand() % searchFieldLen; int row = rand() % searchFieldLen;
for (int j = 0; j < wordLength; j++) for (int j = 0; j < wordLength; j++)
{ {
if (salad[reihe+j][spalte] != '.') if (salad[row+j][collumn] != EMPTY_CHAR) {space = 0; break;}
{
space = 1;
break;
}
} }
if ((reihe + wordLength >= searchFieldLen-1) || (space == 1)) if ((row + wordLength >= searchFieldLen-1) || (space == 0)) {attempts++;}
{ else {
attempts++;
}
else
{
for (int j = 0; j < wordLength; j++) for (int j = 0; j < wordLength; j++)
{ {
salad[row+j][collumn] = words[i][j]; salad[row+j][collumn] = words[i][j];
@ -87,19 +66,21 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
added=1; added=1;
addedWords++; addedWords++;
} }
} }
space = 0; space = 1;
} }
attempts = 0; attempts = 0;
added = 0; added = 0;
} }
for (int i = 0; i < searchFieldLen; i++) 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] == '.') if (salad[i][j] == EMPTY_CHAR)
{ {
salad[i][j] = rand()%('Z'-'A'+1)+'A';//Alle Felder, die noch nicht befüllt sind, werden zufällig befüllt salad[i][j] = rand()%('Z'-'A'+1)+'A';//Alle Felder, die noch nicht befüllt sind, werden zufällig befüllt
} }
} }
} }
return addedWords; return addedWords;

Binary file not shown.

Binary file not shown.

View File

@ -46,7 +46,7 @@ int main(int argc, char *argv[])
else else
{ {
exitCode = EXIT_FAILURE; exitCode = EXIT_FAILURE;
printf("Error. The words couldn't be placed.\n"); printf("Bei der Platzierung ist etwas falsch gelaufen!");
} }
// Start the game if successful // Start the game if successful
// error message if some words couldn't be placed // error message if some words couldn't be placed

Binary file not shown.

View File

@ -0,0 +1 @@
Hund,Katze; Maus

View File

View File

@ -0,0 +1,3 @@
Apfel
Banane
Kiwi