#include "game.h" #include #include #include #include #define MAX_RAND_TRIES_PER_WORD 10 #define EMPTY_CHAR 0 #define RANDOMNUMBER(minimum, maximum) ((rand() % ((maximum)-(minimum)+1))+cd minimum) //Macro to generate a Number between minimum and maximum (both are possibly rolled) //TODO: Spiellogik implementieren: /* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren --> Vorher eingabe festlegen! * restliche Felder mit zufälligen Buchstaben füllen - erldeigt*/ // 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));//sets the seed of the random function to the current time in order to guarantee unique results for(int i = 0; i < searchFieldLen; i++)//Clears the array to simplify the process of findings empty slots { for(int j = 0; j < searchFieldLen; j++) { salad[i][j] = 63; } } for(int i = 0; i < wordCount; i++) { } for(int i = 0; i < searchFieldLen; i++)//Randomly fills the rest of the array { for(int j = 0; j < searchFieldLen; j++) { if((salad[i][j] == 63))//checks if there is already a letter of a word placed in here { salad[i][j] = RANDOMNUMBER(65, 90);//fills "empty" chars in word salad with a random upper case letter } } } } // Prints the word salad to console void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) { if(searchFieldLen <= MAX_SEARCH_FIELD_LEN) { for(int i = 0; i < searchFieldLen; i++) { for(int j = 0; j < searchFieldLen; j++) { putchar(salad[i][j]);//Prints a letter within the salad array } putchar(10);//Prints a Line Feed, thus ensuring the correct formatting of the program } } else { puts("FEHLER! Buchstabenfeld uebersteigt Maximalzahl der Buchstaben!"); } }