generated from freudenreichan/info2Praktikum-Wortsalat
Zufalläig Horiz/Verti & Plazieren im Filler Array
This commit is contained in:
parent
a980b80623
commit
3e77de5152
@ -5,11 +5,41 @@
|
|||||||
|
|
||||||
#define MAX_RAND_TRIES_PER_WORD 10
|
#define MAX_RAND_TRIES_PER_WORD 10
|
||||||
#define EMPTY_CHAR 0
|
#define EMPTY_CHAR 0
|
||||||
|
#define FILLER '.'
|
||||||
|
#define SIZE 20
|
||||||
|
|
||||||
//TODO: Spiellogik implementieren:
|
//TODO: Spiellogik implementieren:
|
||||||
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||||
|
|
||||||
|
int can_Place(char grid[SIZE][SIZE], const char *word, int row, int col, int orient)
|
||||||
|
{
|
||||||
|
srand(time(NULL)); //Zufallsgenerator
|
||||||
|
orient = rand() % 2;
|
||||||
|
|
||||||
|
int len = strlen(word); //Wortlänge best.
|
||||||
|
|
||||||
|
if (orient == 0) //Horizontal
|
||||||
|
{
|
||||||
|
if (col + len > SIZE) //Rand
|
||||||
|
return 0;
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
if (grid[row][col + i] != FILLER && grid[row][col + i] != word[i])
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
else //Vertikal
|
||||||
|
{
|
||||||
|
if (row + len > SIZE) //Rand
|
||||||
|
return 0;
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
if (grid[row + i][col] != FILLER && grid[row + i][col] != word[i])
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Creates the word salad by placing words randomly and filling empty spaces
|
// 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 createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user