From 195ce396985738dcdd45bc103a4fe5e8e00ceb20 Mon Sep 17 00:00:00 2001 From: Alexei Date: Mon, 10 Nov 2025 15:03:49 +0100 Subject: [PATCH] final changes to game.c --- Start_Windows/game.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Start_Windows/game.c b/Start_Windows/game.c index 95ad8ab..4c053de 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -14,15 +14,19 @@ // 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 addedWords = 0; int attempts = 0; int added = 0; // = 1 wäre Wort hinzugefügt int space = 0; // = 1 wäre Wort zu lang für diese Stelle unsigned long long wordLength = 0; + srand(time(NULL)); - for (int i = 0; i < searchFieldLen; i++) { - for (int j = 0; j < searchFieldLen; j++) { + for (int i = 0; i < searchFieldLen; i++) + { + for (int j = 0; j < searchFieldLen; j++) + { salad[i][j] = '.'; //Füllen des gesamten Arrays mit '.' } } @@ -31,7 +35,8 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi wordLength = strlen(words[i]); - while (attempts <= MAX_RAND_TRIES_PER_WORD && added != 1) { + while (attempts <= MAX_RAND_TRIES_PER_WORD && added != 1) + { int direction = rand() % 2;// 0 = Horizontal, 1 = Vertikal if (direction == 0) //Horizontal { @@ -97,7 +102,8 @@ 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++) { + for (int j = 0; j < searchFieldLen; j++) + { if (salad[i][j] == '.') { salad[i][j] = rand()%('Z'-'A'+1)+'A';//Zufällige Befüllung der noch nicht befüllten Felder