diff --git a/Startcode/game.c b/Startcode/game.c index fa09486..f442b1f 100644 --- a/Startcode/game.c +++ b/Startcode/game.c @@ -32,23 +32,25 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi for(int counter = 0; counter < wordCount; counter++){ size_t len = strlen(words[counter]); - //try to place a word + //try to place a word for(int try = 0; try < 10; try++){ int x = rand() % MAX_SEARCH_FIELD_LEN; int y = rand() % MAX_SEARCH_FIELD_LEN; int dir = rand() % 2; - - 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; - } + // cant place vertically + if(dir == 1 && MAX_SEARCH_FIELD_LEN < (y + (int) len -1)){ + dir = 0; + } + //cant place horizontally + if((x + (int) len -1) > MAX_SEARCH_FIELD_LEN){ + continue; } //place word vertically if(dir == 1){ + //see if all neccessary spaces are empty bool cont = false; for (int i = 0; i < (int)len; i++){