game.c vervollständigt

This commit is contained in:
welschph103497 committed 2026-10-26 16:26:02 +01:00
1 parent c93dd9a734
commit 01b1660858
1 file changed
+57 -5
+57 -5
View File
@@ -6,12 +6,64 @@
#define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0
//TODO: Spiellogik implementieren:
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
* restliche Felder mit zufälligen Buchstaben füllen */
// 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;
}