#include "game.h" #include "input.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) { /*srand(time(NULL)); char bustaben[] = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"; char zufall = bustaben[rand() % 26]; printf("Zufaelliger Bustabe: %c\n", zufall); const char words[15][MAX_WORD_LEN] = "Yeti,Nessie,Werwolf,Vampir,Monster,Hydra,Frankenstein,Dracula,KingKong,Gremlin,Kobold,Hexe,Poltergeist,Gespenst,Oge"; return 0; */ srand(time(NULL)); for (int r=0; r < ROWS; r++) { for (int c =0; c < COLS; c++) { grid[r][c] = '.'; } } //Wörter plazieren for (unsigned int w = 0; w< wordCount; w++) { int wordLen = strlen(words[w]); int placed = 0; while (!placed) { int direction = rand() % 2; int row; int col; int fits = 1; if (direction == 0) { row = rand() % ROWS; col = rand() % (COLS - wordLen +1); for (int i = 0; i< wordLen; i++) { if (grid[row][col +i] != '.') { fits = 0; } } if (fits) { for (int i=0; i < wordLen; i++) { grid[row][col +i] = words[w][i]; } placed = 1; } } else { row = rand() % (ROWS - wordLen +1); col = rand() % COLS; for (int i = 0; i< wordLen; i++) { if (grid[row+i][col] != '.') { fits = 0; } } if (fits) { for (int i = 0; i