forked from freudenreichan/info2Praktikum-Wortsalat
game.c fertig ohne test
This commit is contained in:
1 parent
ea276d358e
commit
4f09d24c90
1 file changed
+82
-85
+82
-85
@@ -18,111 +18,108 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
|
|
||||||
int startpoint_x, startpoint_y, direction, possible, tries;
|
int startpoint_x, startpoint_y, direction, possible, tries;
|
||||||
|
|
||||||
for(int i = 0; i < MAX_SEARCH_FIELD_LEN; i++){
|
for(int i = 0; i < searchFieldLen; i++){
|
||||||
for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++){
|
for(int j = 0; j < searchFieldLen; j++){
|
||||||
salad[i][j] = '0';
|
salad[i][j] = EMPTY_CHAR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < wordCount; i++){
|
for(int i = 0; i < wordCount; i++){
|
||||||
possible = 0;
|
if(strlen(words[i]) <= searchFieldLen){
|
||||||
tries = 0;
|
possible = 0;
|
||||||
while(possible == 0 && tries <= MAX_RAND_TRIES_PER_WORD){
|
tries = 0;
|
||||||
direction = rand() % 4;
|
while(possible == 0 && tries < MAX_RAND_TRIES_PER_WORD){
|
||||||
|
direction = rand() % 4;
|
||||||
switch(direction){
|
possible = 1;
|
||||||
case 0: //X-Positiv
|
switch(direction){
|
||||||
startpoint_x = rand() % (searchFieldLen - strlen(words [i])) + 1;
|
case 0: //X-Positiv
|
||||||
startpoint_y = rand() % searchFieldLen;
|
startpoint_x = rand() % (searchFieldLen - strlen(words[i]) + 1);
|
||||||
for(int j = 0; j < strlen(words[i]); j++){
|
startpoint_y = rand() % searchFieldLen;
|
||||||
if(salad[startpoint_x + j][startpoint_y] != '0'){
|
for(int j = 0; j < strlen(words[i]); j++){
|
||||||
possible = 0;
|
if(salad[startpoint_x + j][startpoint_y] != EMPTY_CHAR){
|
||||||
|
possible = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(possible == 0){
|
||||||
|
tries += 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
possible = 1;
|
for(int j = 0; j < strlen(words[i]); j++){
|
||||||
|
salad[startpoint_x + j][startpoint_y] = words[i][j];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(possible = 0){
|
|
||||||
tries += 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
case 1: //X-Negativ
|
||||||
|
startpoint_x = strlen(words[i]) - 1 + rand() % (searchFieldLen - strlen(words[i]) + 1);
|
||||||
for(int j = 0; j < strlen(words[i]); j++){
|
startpoint_y = rand() % searchFieldLen;
|
||||||
salad[startpoint_x + j][startpoint_y] = Words[i][j]
|
for(int j = 0; j < strlen(words[i]); j++){
|
||||||
}
|
if(salad[startpoint_x - j][startpoint_y] != EMPTY_CHAR){
|
||||||
break;
|
possible = 0;
|
||||||
case 1: //X-Negativ
|
break;
|
||||||
startpoint_x = searchFieldLen - rand() % (searchFieldLen - strlen(words [i])) + 1;
|
}
|
||||||
startpoint_y = rand() % searchFieldLen;
|
}
|
||||||
for(int j = 0; j < strlen(words[i]); j++){
|
|
||||||
if(salad[startpoint_x - j][startpoint_y] != '0'){
|
if(possible == 0){
|
||||||
possible = 0;
|
tries += 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
possible = 1;
|
for(int j = 0; j < strlen(words[i]); j++){
|
||||||
|
salad[startpoint_x - j][startpoint_y] = words[i][j];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(possible = 0){
|
|
||||||
tries += 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
case 2: //Y-Positiv
|
||||||
|
startpoint_x = rand() % searchFieldLen;
|
||||||
for(int j = 0; j < strlen(words[i]); j++){
|
startpoint_y = rand() % (searchFieldLen - strlen(words[i]) + 1);
|
||||||
salad[startpoint_x - j][startpoint_y] = Words[i][j]
|
for(int j = 0; j < strlen(words[i]); j++){
|
||||||
}
|
if(salad[startpoint_x][startpoint_y + j] != EMPTY_CHAR){
|
||||||
break;
|
possible = 0;
|
||||||
case 2: //Y-Positiv
|
break;
|
||||||
startpoint_x = rand() % searchFieldLen;
|
}
|
||||||
startpoint_y = rand() % (searchFieldLen - strlen(words [i])) + 1;
|
}
|
||||||
for(int j = 0; j < strlen(words[i]); j++){
|
|
||||||
if(salad[startpoint_x][startpoint_y + j] != '0'){
|
if(possible == 0){
|
||||||
possible = 0;
|
tries += 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
possible = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(possible = 0){
|
for(int j = 0; j < strlen(words[i]); j++){
|
||||||
tries += 1;
|
salad[startpoint_x ][startpoint_y + j] = words[i][j];
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
case 3: //Y-Negativ
|
||||||
|
startpoint_x = rand() % searchFieldLen;
|
||||||
for(int j = 0; j < strlen(words[i]); j++){
|
startpoint_y = strlen(words[i]) - 1 + rand() % (searchFieldLen - strlen(words[i]) + 1);
|
||||||
salad[startpoint_x ][startpoint_y + j] = Words[i][j]
|
for(int j = 0; j < strlen(words[i]); j++){
|
||||||
}
|
if(salad[startpoint_x][startpoint_y - j] != EMPTY_CHAR){
|
||||||
break;
|
possible = 0;
|
||||||
case 3: //Y-Negativ
|
break;
|
||||||
startpoint_x = rand() % searchFieldLen;
|
}
|
||||||
startpoint_y = searchFieldLen - rand() % (searchFieldLen - strlen(words [i])) + 1;
|
}
|
||||||
for(int j = 0; j < strlen(words[i]); j++){
|
|
||||||
if(salad[startpoint_x][startpoint_y - j] != '0'){
|
if(possible == 0){
|
||||||
possible = 0;
|
tries += 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
possible = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(possible = 0){
|
|
||||||
tries += 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int j = 0; j < strlen(words[i]); j++){
|
for(int j = 0; j < strlen(words[i]); j++){
|
||||||
salad[startpoint_x][startpoint_y - j] = Words[i][j]
|
salad[startpoint_x][startpoint_y - j] = words[i][j];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < searchFieldLen; i++){
|
||||||
|
for(int j = 0; j < searchFieldLen; j++){
|
||||||
|
if(salad[i][j] == EMPTY_CHAR){
|
||||||
|
salad[i][j] = rand() % 26 + 'A';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user