60 lines
1.6 KiB
C
60 lines
1.6 KiB
C
#include "game.h"
|
|
#include <time.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#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)
|
|
{
|
|
srand(time(NULL));
|
|
int i,j;
|
|
int Woertergesetzt = 0;
|
|
for (i=0 ; i<MAX_SEARCH_FIELD_LEN;i++);
|
|
{
|
|
for (j=0 ; j<MAX_SEARCH_FIELD_LEN;j++);
|
|
{
|
|
salad[i][j] = 0;
|
|
}
|
|
}
|
|
for (int k = 0 ; k < wordCount ; k++);
|
|
{
|
|
int richtigplatziert = 0;
|
|
for (int f = 0 ; f < 1000 && !richtigplatziert ; f++);
|
|
{
|
|
int ausrichtung, zeile, spalte;
|
|
ausrichtung = rand() % 2;
|
|
zeile = rand() % (searchFieldLen);
|
|
spalte = rand() % (searchFieldLen);
|
|
|
|
if (ausrichtung == 0);
|
|
{
|
|
if ((spalte + strlen)(words[k]) < MAX_SEARCH_FIELD_LEN);
|
|
{
|
|
int moeglichePosition = 1;
|
|
for (int i1 = 0; i1< strlen(words[k]); i1++);
|
|
{
|
|
if (salad[zeile][spalte + i] !=0);
|
|
moeglichePosition = 0;
|
|
}
|
|
richtigplatziert = 1;
|
|
Woertergesetzt++;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ((zeile + strlen(words[k]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|