#include "game.h" #include #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) { // Wörter in salad einsortieren // strtok durch words ersetzen, pro Zeile ein Wort char * einzelwort = strtok(words, "\0"); for (int i = 0; i < wordCount; i++){ int einzelwort_laenge = strlen(einzelwort); int richtung = rand()% 2; // muss noch prüfen, ob in der Zeile schon was ist // 1 ist horizontal, 0 ist vertikal if (richtung == 1){ for(int k = 0; k < einzelwort_laenge; k++){ int zeile = rand()% MAX_SEARCH_FIELD_LEN; int spalte = rand()% MAX_SEARCH_FIELD_LEN- einzelwort_laenge + 1; salad[zeile][spalte + k] = einzelwort[k]; } } else if (richtung == 0){ for(int j = 0; j < einzelwort_laenge; j++){ int zeile = rand()% MAX_SEARCH_FIELD_LEN - einzelwort_laenge + 1; int spalte = rand()% MAX_SEARCH_FIELD_LEN; salad[zeile + k][spalte] = einzelwort[k]; } } strtok(NULL, "\0"); } // zufällige Buchstaben erzeugen srand(time(NULL)); char alphabet [] = "abcdefghijklmnopqrstuvwxyz"; int laenge = strlen(alphabet); int zufallszahl = rand()% laenge; char zufallsbuchstabe = alphabet[zufallszahl]; //prüfen, ob Wörter vorhanden sind mit isalpha // -> erst wenn die ganze Länge des Wortes frei ist, array hinzufügen // MAX Versuche das Wort zu platzieren == 10 -> hinzufügen // isalpha == 0 -> kein Buchstabe for(int l = 0; l < MAX_SEARCH_FIELD_LEN; l++){ for(int m = 0; m < MAX_SEARCH_FIELD_LEN; m++ ){ if(isalpha(salad[l][m]) == 0 ) salad[m][n] == zufallsbuchstabe; } } } // Prints the word salad to console void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) { }