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++){
|
for(int counter = 0; counter < wordCount; counter++){
|
||||||
|
|
||||||
size_t len = strlen(words[counter]);
|
size_t len = strlen(words[counter]);
|
||||||
//try to place a word
|
|
||||||
|
|
||||||
|
//try to place a word
|
||||||
for(int try = 0; try < 10; try++){
|
for(int try = 0; try < 10; try++){
|
||||||
int x = rand() % MAX_SEARCH_FIELD_LEN;
|
int x = rand() % MAX_SEARCH_FIELD_LEN;
|
||||||
int y = rand() % MAX_SEARCH_FIELD_LEN;
|
int y = rand() % MAX_SEARCH_FIELD_LEN;
|
||||||
|
|
||||||
int dir = rand() % 2;
|
int dir = rand() % 2;
|
||||||
|
// cant place vertically
|
||||||
if ((MAX_SEARCH_FIELD_LEN - x - 1) < len){
|
if(dir == 1 && MAX_SEARCH_FIELD_LEN < (y + (int) len -1)){
|
||||||
if((MAX_SEARCH_FIELD_LEN - y - 1) < len){
|
dir = 0;
|
||||||
// cant place word here (too far in the bottom right corner)
|
}
|
||||||
continue;
|
//cant place horizontally
|
||||||
}
|
if((x + (int) len -1) > MAX_SEARCH_FIELD_LEN){
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//place word vertically
|
//place word vertically
|
||||||
if(dir == 1){
|
if(dir == 1){
|
||||||
|
|
||||||
//see if all neccessary spaces are empty
|
//see if all neccessary spaces are empty
|
||||||
bool cont = false;
|
bool cont = false;
|
||||||
for (int i = 0; i < (int)len; i++){
|
for (int i = 0; i < (int)len; i++){
|
||||||
|
|||||||
Reference in new issue
Block a user