generated from freudenreichan/info2Praktikum-Wortsalat
Compare commits
2
Commits
Lukas
..
markus-game
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfef59e0a6 | ||
|
|
3ab8b26e05 |
No files matched your search
+52
-2
@@ -11,7 +11,57 @@
|
|||||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||||
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
|
unsigned int placedWords = 0;
|
||||||
|
|
||||||
}
|
// 1. Spielfeld leeren
|
||||||
|
for (unsigned int i = 0; i < searchFieldLen; i++) {
|
||||||
|
for (unsigned int j = 0; j < searchFieldLen; j++) {
|
||||||
|
salad[i][j] = EMPTY_CHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Alle Wörter durchlaufen
|
||||||
|
for (unsigned int i = 0; i < wordCount; i++) {
|
||||||
|
|
||||||
|
size_t wordLen = strlen(words[i]);
|
||||||
|
|
||||||
|
// Leere oder zu lange Wörter überspringen
|
||||||
|
if (wordLen == 0 || wordLen > searchFieldLen) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Platzierungsversuche
|
||||||
|
for (int attempt = 0;
|
||||||
|
attempt < MAX_RAND_TRIES_PER_WORD;
|
||||||
|
attempt++) {
|
||||||
|
unsigned int row = rand() % searchFieldLen;
|
||||||
|
unsigned int col = rand() % searchFieldLen;
|
||||||
|
int direction = rand() % 2;
|
||||||
|
int canPlace = 1;
|
||||||
|
|
||||||
|
// 4. Horizontale Platzierung prüfen
|
||||||
|
if (direction == 0) {
|
||||||
|
|
||||||
|
if (col + wordLen > searchFieldLen) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t j = 0; j < wordLen; j++) {
|
||||||
|
|
||||||
|
if (salad[row][col + j] != EMPTY_CHAR &&
|
||||||
|
salad[row][col + j] != words[i][j]) {
|
||||||
|
|
||||||
|
canPlace = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 5. Vertikale Platzierung prüfen
|
||||||
+3
-2
@@ -24,7 +24,7 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (letterCount < MAX_WORD_LEN - 1) //wörter Buchstabenweise einlesen
|
if (letterCount < MAX_WORD_LEN - 1) //wörter Buchstabenweise einlesen
|
||||||
{
|
{
|
||||||
words[count][letterCount] = (char)toupper(c);
|
words[count][letterCount] = (char)toupper(c);
|
||||||
letterCount++;
|
letterCount++;
|
||||||
}
|
}
|
||||||
@@ -43,4 +43,5 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
File renamed without changes.
+4
-14
@@ -1,15 +1,5 @@
|
|||||||
Yeti
|
Yeti,Nessie Werwolf; Vampir
|
||||||
Nessie
|
|
||||||
Werwolf
|
|
||||||
Vampir
|
|
||||||
Monster
|
Monster
|
||||||
Hydra
|
Hydra;Frankenstein
|
||||||
Frankenstein
|
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
|
||||||
Dracula
|
Gespenst, Oger
|
||||||
KingKong
|
|
||||||
Gremlin
|
|
||||||
Kobold
|
|
||||||
Hexe
|
|
||||||
Poltergeist
|
|
||||||
Gespenst
|
|
||||||
Oger
|
|
||||||
Reference in new issue
Block a user