From e5a049842c4202fe421498544f16db5c4c813456 Mon Sep 17 00:00:00 2001 From: Tobias Grampp Date: Mon, 3 Nov 2025 12:02:28 +0100 Subject: [PATCH] Fixed bugs caused by method createWordSalad() --- Start_Windows/game.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Start_Windows/game.c b/Start_Windows/game.c index 76d1c24..0f12dce 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -7,7 +7,7 @@ #define MAX_RAND_TRIES_PER_WORD 10 #define EMPTY_CHAR 0 -#define RANDOMNUMBER(minimum, maximum) ((rand() % ((maximum)-(minimum)+1))+cd minimum) //Macro to generate a Number between minimum and maximum (both are possibly rolled) +#define RANDOMNUMBER(minimum, maximum) ((rand() % ((maximum)-(minimum)+1))+ minimum) //Macro to generate a Number between minimum and maximum (both are possibly rolled) //TODO: Spiellogik implementieren: /* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren - erledigt @@ -31,9 +31,9 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi for(int i = 0; i < wordCount; i++) { int wordPlaced = 0, amountFailed = 0; + int wordlength = 0; do { - int wordlength = 0; while(words[i][wordlength] != '0')//gets the length of the current word wordlength++; int startPosition1 = RANDOMNUMBER(0, MAX_SEARCH_FIELD_LEN - wordlength);//gets a random starting position for the word @@ -50,7 +50,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi { for(int j = 0; j < wordlength; j++) { - salad[startPosition1 + j][startPosition2] = words[i][j] + salad[startPosition1 + j][startPosition2] = words[i][j]; } wordPlaced++; wordamount++; @@ -72,7 +72,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi { for(int j = 0; j < wordlength; j++) { - salad[startPosition2][startPosition1 + j] = words[i][j] + salad[startPosition2][startPosition1 + j] = words[i][j]; } wordPlaced++; wordamount++; @@ -82,7 +82,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi amountFailed++; } } - } + }while((wordPlaced == 0)&&(amountFailed < MAX_RAND_TRIES_PER_WORD)); int index = 0; while((wordPlaced == 0)&&(index < searchFieldLen))//Places Words that couln't be put in normally in the highest up horizontal place. { @@ -96,7 +96,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi { for(int j = 0; j < wordlength; j++) { - salad[index + j][0] = words[i][j] + salad[index + j][0] = words[i][j]; } wordPlaced++; wordamount++;