diff --git a/Start_Windows/game.c b/Start_Windows/game.c index d8cc133..03ef09e 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -13,11 +13,138 @@ // 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 wortrest = wordCount; + int akt_word; + int belegtcounter; + int lage; + int spalte_zeile; + int fehlende_woerter; + char saladcpy[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; + char demostring[MAX_WORD_LEN]; + char comp_string[MAX_WORD_LEN]; + int zerocounter; + int maxzero[2]; + int ersterbuchstabe; + int erledigt; + //salad befuellen mit "0" + for (int i=0;i0){ + akt_word = wordCount - wortrest; + lage = rand()%2; + erledigt = 0; + belegtcounter = MAX_RAND_TRIES_PER_WORD; + while(belegtcounter>0){ + + strncpy(comp_string,demostring,MAX_WORD_LEN); + strncpy(comp_string,words[akt_word],strlen(words[akt_word])); + + zerocounter = 1; + maxzero[0] = 1; + spalte_zeile=rand()%searchFieldLen; + switch (lage){ + + case 0://Waagerecht + + for(int i=1;imaxzero[0]){ + maxzero[0] = zerocounter; //Menge an Nullen + maxzero[1] = i; //Pos der letzten Null + } + }else{ + zerocounter = 1; + } + } + if(maxzero[0]>=strlen(words[akt_word])){ + ersterbuchstabe = maxzero[1]-(maxzero[0])+1+rand()%(maxzero[0]-strlen(words[akt_word])+1); //Start = letzter freier Platz - anzahl Platz + 1 + rand()%(freierPlatz-benötigterPlatz +1) + for(int i=0;imaxzero[0]){ + maxzero[0] = zerocounter; //Menge an Nullen + maxzero[1] = i; //Pos der letzten Null + } + }else{ + zerocounter = 1; + } + } + if(maxzero[0]>=strlen(words[akt_word])){ + ersterbuchstabe = maxzero[1]-(maxzero[0])+1+rand()%(maxzero[0]-strlen(words[akt_word])+1); //Start = letzter freier Platz - anzahl Platz + 1 + rand()%(freierPlatz-benötigterPlatz +1) + for(int i=0;i +#include +#include + +#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 wortrest = wordCount; + int akt_word; + int lage; + int pos_x; + int pos_y; + int belegt = 2; + int belegt_counter; + int fehlende_woerter=0; + int startwechsel = 0; + char demostring[searchFieldLen]; + char vergleichstring[searchFieldLen]; + + //salad befuellen mit "0" + for (int i=0;i0){ + belegt_counter = MAX_RAND_TRIES_PER_WORD; + while (belegt_counter > 0){ + akt_word = (wordCount-wortrest); + + if(belegt_counter<(MAX_RAND_TRIES_PER_WORD/2)){ + + } + //horizontal/vertikal + lage = rand()%2; + switch (lage){ + + case 0://Waagerecht + + pos_x = rand()%(searchFieldLen-strlen(words[akt_word])); + pos_y = rand()%(searchFieldLen); + + for (int leange_counter = 0;leange_counter