forked from freudenreichan/info2Praktikum-Wortsalat
Game.c vervollständigt
This commit is contained in:
1 parent
c93dd9a734
commit
0ee1c4e689
1 file changed
+58
-1
+58
-1
@@ -13,5 +13,62 @@
|
||||
// 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)
|
||||
{
|
||||
int row, col, word, startcol=0, startrow=0;
|
||||
srand(time(NULL));
|
||||
for(row=0; row<MAX_SEARCH_FIELD_LEN; row++)
|
||||
{
|
||||
for(col=0; col<MAX_SEARCH_FIELD_LEN; col++)
|
||||
{
|
||||
salad[row][col] = EMPTY_CHAR;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
for (word=0; word<wordCount; word++)
|
||||
{
|
||||
if (rand() % 2 == 0) //horizontal
|
||||
{
|
||||
startcol = rand() % (MAX_SEARCH_FIELD_LEN - strlen(words[word])+1);
|
||||
startrow = rand() % MAX_SEARCH_FIELD_LEN;
|
||||
for (int i=0; i<strlen(words[word]); i++)
|
||||
{
|
||||
salad[startrow][startcol+i] = words[word][i];
|
||||
}
|
||||
}
|
||||
else //vertikal
|
||||
{
|
||||
startrow = rand() % (MAX_SEARCH_FIELD_LEN - strlen(words[word])+1);
|
||||
startcol = rand() % MAX_SEARCH_FIELD_LEN;
|
||||
for (int j=0; j<strlen(words[word]); j++)
|
||||
{
|
||||
salad[startrow+j][startcol] = words[word][j];
|
||||
}
|
||||
}
|
||||
|
||||
if (rand()%26 !=0)
|
||||
{
|
||||
printf("%c",EMPTY_CHAR);
|
||||
}
|
||||
}
|
||||
|
||||
for (row=0; row<MAX_SEARCH_FIELD_LEN; row++)
|
||||
{
|
||||
for (col=0; col<MAX_SEARCH_FIELD_LEN; col++)
|
||||
{
|
||||
if (salad[row][col] == EMPTY_CHAR)
|
||||
{
|
||||
salad[row][col] = rand()%26+'A';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (row=0; row<MAX_SEARCH_FIELD_LEN; row++)
|
||||
{
|
||||
for (col=0; col<MAX_SEARCH_FIELD_LEN; col++)
|
||||
{
|
||||
printf("%c", salad[row][col]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n\nPlatzierung abgeschlossen\n\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user