game.c bearbeitet,noch nicht fertig

This commit is contained in:
Fabrice 2025-10-31 00:25:02 +01:00
parent d7c0c30de9
commit dc9b59395b
2 changed files with 34 additions and 0 deletions

View File

@ -13,11 +13,45 @@
// 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)
{ {
int r, c;
//Gesamtes Feld auf 0 setzen
for (r=0; r < searchFieldLen; r++) {
for (c=0; c < searchFieldLen; c++) {
salad [r][c] = EMPTY_CHAR;
}
}
//Wörter zufällig horizontal oder vertikal platzieren
enum Richtung {HORIZONTAL,VERTIKAL}; //0;1
enum Richtung dir;
dir = (rand() % 2 == 0) ? HORIZONTAL : VERTIKAL;
//Schleife, die das Setzen für alle Wörter durchführt, Zufällig horizontal(0) oder vertikal(1), an zufällige Stelle
//Prüfen, ob das Wort von der Länge her ins Feld passt
//Felder, in denen keine Wörter stehen, werden mit zufälligen Buchstaben befüllt
for (r=0; r < searchFieldLen; r++) {
for (c=0; c < searchFieldLen; c++) {
if (salad[r][c] == EMPTY_CHAR) {
salad [r][c] = 'A' + (rand()% 26);
}
}
}
return 0;
} }
// Prints the word salad to console // Prints the word salad to console
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
{ {
int r, c;
//Ausgabe des gesamten Feldes
for (r=0; r < searchFieldLen; r++) {
for (c=0; c < searchFieldLen; c++) {
printf("%c ", salad[r][c]);
}
printf("\n");
}
} }

Binary file not shown.