#include "game.h" #include #include #include #define MAX_RAND_TRIES_PER_WORD 20 #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) { int saladclone[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; int wordsplacedcounter=0; for (int i=0;i searchFieldLen) //erst wird überprüft, ob das Wort überlappt continue; for (int i=0;i < wordLen; i++) { if (saladclone[row][col + i]==1) { check=1; } } if (check == 1) continue; printf("Wort: %d,%d \n", row,col); for (int i = 0;i < wordLen; i++) { //Wort wird in Spalte geschrieben salad[row][col + i] = word[i]; saladclone[row][col + i] = 1; } wordPlaced = 1; wordsplacedcounter++; } else { if (row + wordLen > searchFieldLen) //erst wird überprüft, ob das Wort überlappt continue; for (int i=0;i < wordLen; i++) { if (saladclone[row+i][col]==1) { check=1; } } if (check == 1) continue; printf("Wort: %d,%d \n", row,col); for (int i = 0;i < wordLen; i++) { //Wort wird in Zeile geschrieben salad[row + i][col] = word[i]; saladclone[row+i][col] = 1; } wordPlaced = 1; wordsplacedcounter++; } } } return wordsplacedcounter; } // Prints the word salad to console void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) { printf("WORTSALAT:\n\n"); for (int i = 0; i < searchFieldLen; i++) { for (int j = 0; j < searchFieldLen; j++) { printf("%c ", salad[i][j]); } printf("\n"); } }