diff --git a/Startcode/game.c b/Startcode/game.c index 93710d3..fa09486 100644 --- a/Startcode/game.c +++ b/Startcode/game.c @@ -29,8 +29,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi int placedWords = 0; //Iterate over words - unsigned int counter = 0; - while(counter < wordCount){ + for(int counter = 0; counter < wordCount; counter++){ size_t len = strlen(words[counter]); //try to place a word @@ -41,8 +40,8 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi int dir = rand() % 2; - if ((MAX_SEARCH_FIELD_LEN - x) < len){ - if((MAX_SEARCH_FIELD_LEN - y) < len){ + if ((MAX_SEARCH_FIELD_LEN - x - 1) < len){ + if((MAX_SEARCH_FIELD_LEN - y - 1) < len){ // cant place word here (too far in the bottom right corner) continue; } @@ -65,29 +64,28 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi salad[x][y+i] = words[counter][i]; } placedWords++; - counter++; + break; + }else{ + //place currentWord horizontally + //see if all neccessary spaces are emtry + bool cont = false; + for (int i = 0; i < (int)len; i++){ + if(salad[x+1][y] != '0'){ + cont = true; + break; + } + } + + //if not all spaces are empty try again + if(cont) continue; + + //place currentWord + for (int i = 0; i < (int)len; i++){ + salad[x+1][y] = words[counter][i]; + } + placedWords++; break; } - //place currentWord horizontally - - //see if all neccessary spaces are emtry - bool cont = false; - for (int i = 0; i < (int)len; i++){ - if(salad[x+1][y] != '0'){ - cont = true; - break; - } - } - - //if not all spaces are empty try again - if(cont) continue; - - //place currentWord - for (int i = 0; i < (int)len; i++){ - salad[x+1][y] = words[counter][i]; - } - placedWords++; - counter++; } } for (int i = 0; i < MAX_SEARCH_FIELD_LEN; i++){