array befuellen in game und mit empty char

This commit is contained in:
Tobias Busch 2025-11-04 17:31:59 +01:00
parent 25f7fb4d39
commit 81d0e35517
5 changed files with 13 additions and 10 deletions

View File

@ -31,6 +31,14 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
int voll = 0;
int tries = 0;
for (int i = 0; i < MAX_SEARCH_FIELD_LEN; i++)
{
for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++)
{
salad[i][j] = EMPTY_CHAR;
}
}
if (vertikal_horizontal == VERTIKAL) {
tries = 0;
@ -39,7 +47,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
positionX = rand() % (searchFieldLen);
positionY = rand() % (searchFieldLen-leange);
for(int j = positionY; j < positionY+leange ; j++) { //überprüfung ob alle positionen 0 sind
if(salad[j][positionX] != '0') {
if(salad[j][positionX] != EMPTY_CHAR) {
voll = 1;
}
}
@ -51,7 +59,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
}
placedWordsCount++;
} else if (voll == 1)
printf("Das Wort '%s' konnte nicht plaziert werden", words[i]);
printf("Das Wort '%s' konnte nicht plaziert werden\n", words[i]);
} else if (vertikal_horizontal == HORIZONTAL) {
@ -61,7 +69,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
positionY = rand() % (searchFieldLen);
positionX = rand() % (searchFieldLen-leange);
for(int j = positionX; j < positionX+leange ; j++) { //überprüfung ob alle positionen 0 sind
if(salad[positionY][j] != '0') {
if(salad[positionY][j] != EMPTY_CHAR) {
voll = 1;
}
}
@ -73,7 +81,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
}
placedWordsCount++;
} else if (voll == 1)
printf("Das Wort '%s' konnte nicht plaziert werden", words[i]);
printf("Das Wort '%s' konnte nicht plaziert werden\n", words[i]);
} else
printf("Fehler bei Vertikal Horizontal Wert: %d", vertikal_horizontal);
@ -81,7 +89,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
for(int i = 0; i < searchFieldLen; i++) {
for(int j = 0; j < searchFieldLen; j++) {
if(salad[i][j] == '0') {
if(salad[i][j] == EMPTY_CHAR) {
salad[i][j] = buchstaben[rand() % anzahlBuchstaben];
}
}

Binary file not shown.

View File

@ -28,11 +28,6 @@ int main(int argc, char *argv[])
{
unsigned int placedWords = 0;
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
for(int i = 0; i < MAX_SEARCH_FIELD_LEN; i++) {
for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++) {
wordSalad[i][j] = '0';
}
}
// Read words from file and store in 'words' array
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);

Binary file not shown.

Binary file not shown.