generated from freudenreichan/info2Praktikum-Wortsalat
Teil 1 von game.c
This commit is contained in:
1 parent
634c15ff32
commit
4821287319
1 file changed
+1
-55
+1
-55
@@ -40,7 +40,6 @@ int createWordSalad(
|
|||||||
for (int attempt = 0;
|
for (int attempt = 0;
|
||||||
attempt < MAX_RAND_TRIES_PER_WORD;
|
attempt < MAX_RAND_TRIES_PER_WORD;
|
||||||
attempt++) {
|
attempt++) {
|
||||||
|
|
||||||
unsigned int row = rand() % searchFieldLen;
|
unsigned int row = rand() % searchFieldLen;
|
||||||
unsigned int col = rand() % searchFieldLen;
|
unsigned int col = rand() % searchFieldLen;
|
||||||
int direction = rand() % 2;
|
int direction = rand() % 2;
|
||||||
@@ -64,58 +63,5 @@ int createWordSalad(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 5. Vertikale Platzierung prüfen
|
// 5. Vertikale Platzierung prüfen
|
||||||
else {
|
|
||||||
|
|
||||||
if (row + wordLen > searchFieldLen) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t j = 0; j < wordLen; j++) {
|
|
||||||
|
|
||||||
if (salad[row + j][col] != EMPTY_CHAR &&
|
|
||||||
salad[row + j][col] != words[i][j]) {
|
|
||||||
|
|
||||||
canPlace = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Platzierung nicht möglich
|
|
||||||
if (!canPlace) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6. Wort tatsächlich platzieren
|
|
||||||
for (size_t j = 0; j < wordLen; j++) {
|
|
||||||
|
|
||||||
if (direction == 0) {
|
|
||||||
salad[row][col + j] = words[i][j];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
salad[row + j][col] = words[i][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Erfolgreich platziertes Wort zählen
|
|
||||||
placedWords++;
|
|
||||||
|
|
||||||
// Nächstes Wort bearbeiten
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 7. Leere Felder mit Zufallsbuchstaben füllen
|
|
||||||
for (unsigned int i = 0; i < searchFieldLen; i++) {
|
|
||||||
for (unsigned int j = 0; j < searchFieldLen; j++) {
|
|
||||||
|
|
||||||
if (salad[i][j] == EMPTY_CHAR) {
|
|
||||||
salad[i][j] = 'A' + rand() % 26;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 8. Anzahl erfolgreich platzierter Wörter zurückgeben
|
|
||||||
return (int)placedWords;
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user