forked from freudenreichan/info2Praktikum-Wortsalat
game.c verändert
This commit is contained in:
1 parent
556a83c9af
commit
a0bd61a872
1 file changed
+12
-13
+12
-13
@@ -14,22 +14,15 @@
|
||||
|
||||
// Creates the word salad by placing words randomly and filling empty spaces
|
||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount) {
|
||||
/*srand(time(NULL));
|
||||
char bustaben[] = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
|
||||
char zufall = bustaben[rand() % 26];
|
||||
|
||||
printf("Zufaelliger Bustabe: %c\n", zufall);
|
||||
|
||||
const char words[15][MAX_WORD_LEN] = "Yeti,Nessie,Werwolf,Vampir,Monster,Hydra,Frankenstein,Dracula,KingKong,Gremlin,Kobold,Hexe,Poltergeist,Gespenst,Oge";
|
||||
|
||||
|
||||
|
||||
return 0; */
|
||||
int placedWords = 0;
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
|
||||
for (unsigned int r=0; r < searchFieldLen; r++) {
|
||||
for (int c =0; c <searchFieldLen; c++) {
|
||||
for (unsigned int c =0; c <searchFieldLen; c++) {
|
||||
salad[r][c] = EMPTY_CHAR;
|
||||
}
|
||||
}
|
||||
@@ -37,8 +30,12 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
//Wörter plazieren
|
||||
for (unsigned int w = 0; w< wordCount; w++) {
|
||||
int wordLen = strlen(words[w]);
|
||||
int placed = 0;
|
||||
if (wordLen > searchFieldLen) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int tries = 0;
|
||||
int placed = 0;
|
||||
while (!placed && tries < MAX_RAND_TRIES_PER_WORD) {
|
||||
int direction = rand() % 2;
|
||||
int row;
|
||||
@@ -58,6 +55,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
salad[row][col +i] = words[w][i];
|
||||
}
|
||||
placed = 1;
|
||||
placedWords++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -73,7 +71,8 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
for (int i = 0; i<wordLen; i++) {
|
||||
salad[row+i][col] = words[w][i];
|
||||
}
|
||||
placed =1;
|
||||
placed = 1;
|
||||
placedWords++;
|
||||
}
|
||||
}
|
||||
tries++;
|
||||
@@ -87,5 +86,5 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return placedWords;
|
||||
}
|
||||
Reference in new issue
Block a user