Update game.c
This commit is contained in:
1 parent
7cdcd0e8db
commit
281e3ad21b
1 file changed
+9
-7
+9
-7
@@ -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++){
|
||||
|
||||
Reference in new issue
Block a user