generated from freudenreichan/info2Praktikum-Wortsalat
Compare commits
No commits in common. "249298afc631a3ede8f76bffcdd0e8c2d0ea851d" and "20465e1dc2bc8469b3b50c02a475fec03a4863b4" have entirely different histories.
249298afc6
...
20465e1dc2
@ -17,13 +17,12 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
int addedWords = 0;
|
||||
int attempts = 0; //Anzahl an Versuchen ein Wort hinzuzufügen
|
||||
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;
|
||||
srand(time(NULL));
|
||||
|
||||
for (int i = 0; i < searchFieldLen; i++) {
|
||||
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++) {
|
||||
@ -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) {
|
||||
int direction = rand() % 2;// 0 Horizontal, 1 Vertikal
|
||||
if (direction == 0) {
|
||||
int spalte = rand() % searchFieldLen;
|
||||
int reihe = rand() % searchFieldLen;
|
||||
int collumn = rand() % searchFieldLen;
|
||||
int row = rand() % searchFieldLen;
|
||||
for (int j = 0; j < wordLength; j++)
|
||||
{
|
||||
if (salad[reihe][spalte+j] != '.') //Prüfen ob das Wort ein bereits vorhandenes Wort überspeichern würde
|
||||
{
|
||||
space = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (salad[row][collumn+j] != EMPTY_CHAR) {space = 0; break;}
|
||||
//Prüfen ob das Wort ein bereits vorhandenes Wort überspeichern würde
|
||||
}
|
||||
if ((spalte + wordLength >= searchFieldLen-1) || (space == 1))
|
||||
{
|
||||
attempts++;
|
||||
}
|
||||
|
||||
if ((collumn + wordLength >= searchFieldLen-1) || (space == 0)) {attempts++;}
|
||||
//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[reihe][spalte+j] = words[i][j]; //Einfügen des Wortes Buchstabe für Buchstabe
|
||||
}
|
||||
salad[row][collumn+j] = words[i][j]; //Einfügen des Wortes Buchstabe für Buchstabe
|
||||
}
|
||||
added=1;
|
||||
addedWords++;
|
||||
}
|
||||
|
||||
}
|
||||
else if (direction == 1) // Vertikal
|
||||
{
|
||||
int spalte = rand() % searchFieldLen;
|
||||
int reihe = rand() % searchFieldLen;
|
||||
}
|
||||
else if (direction == 1) {// Vertikal funktioniert analog zu horizontal
|
||||
int collumn = rand() % searchFieldLen;
|
||||
int row = rand() % searchFieldLen;
|
||||
for (int j = 0; j < wordLength; j++)
|
||||
{
|
||||
if (salad[reihe+j][spalte] != '.')
|
||||
{
|
||||
space = 1;
|
||||
break;
|
||||
}
|
||||
if (salad[row+j][collumn] != EMPTY_CHAR) {space = 0; break;}
|
||||
}
|
||||
if ((reihe + wordLength >= searchFieldLen-1) || (space == 1))
|
||||
{
|
||||
attempts++;
|
||||
}
|
||||
|
||||
|
||||
else
|
||||
{
|
||||
if ((row + wordLength >= searchFieldLen-1) || (space == 0)) {attempts++;}
|
||||
else {
|
||||
for (int j = 0; j < wordLength; 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;
|
||||
addedWords++;
|
||||
}
|
||||
}
|
||||
space = 0;
|
||||
}
|
||||
space = 1;
|
||||
}
|
||||
attempts = 0;
|
||||
added = 0;
|
||||
|
||||
}
|
||||
for (int i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for (int i = 0; i < searchFieldLen; i++) {
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return addedWords;
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -46,7 +46,7 @@ int main(int argc, char *argv[])
|
||||
else
|
||||
{
|
||||
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
|
||||
// error message if some words couldn't be placed
|
||||
|
||||
Binary file not shown.
1
Start_Windows/testwords_delims.txt
Normal file
1
Start_Windows/testwords_delims.txt
Normal file
@ -0,0 +1 @@
|
||||
Hund,Katze; Maus
|
||||
0
Start_Windows/testwords_empty.txt
Normal file
0
Start_Windows/testwords_empty.txt
Normal file
3
Start_Windows/testwords_simple.txt
Normal file
3
Start_Windows/testwords_simple.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Apfel
|
||||
Banane
|
||||
Kiwi
|
||||
Loading…
x
Reference in New Issue
Block a user