diff --git a/Wordsalat/game.c b/Wordsalat/game.c index 62e54a9..5ea312d 100644 --- a/Wordsalat/game.c +++ b/Wordsalat/game.c @@ -1,5 +1,4 @@ #include "game.h" -#include #include #include #include @@ -14,7 +13,6 @@ // 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)); unsigned int placedWords = 0; //printf("start game.c\n"); @@ -28,7 +26,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi //printf("[%d] of words: %s\n", i, words[i]); } - //fillRandAlpha(searchFieldLen, salad); + fillRandAlpha(searchFieldLen, salad); printf("placedWords:%d\n", placedWords); @@ -61,9 +59,7 @@ int placement(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned i printf("%s\n", word); - int verhor = rand() % 2; - - if(verhor == 1) + if(rand() % 2) { for(int i = 0; i < strlen(word); i++) { diff --git a/Wordsalat/game.o b/Wordsalat/game.o index f08ef04..04c6c6e 100644 Binary files a/Wordsalat/game.o and b/Wordsalat/game.o differ diff --git a/Wordsalat/main.c b/Wordsalat/main.c index fe36e7a..008e773 100644 --- a/Wordsalat/main.c +++ b/Wordsalat/main.c @@ -3,6 +3,9 @@ #include "input.h" #include "game.h" #include "graphicalGame.h" +#include +#include + #define MAX_NUMBER_OF_WORDS 100 #define SALAD_SIZE 20 @@ -10,8 +13,9 @@ int main(int argc, char *argv[]) { int exitCode = EXIT_SUCCESS; + printf("start main\n"); - + srand(time(NULL)); // Check if the correct number of arguments is provided if(argc != 2) { @@ -35,13 +39,26 @@ int main(int argc, char *argv[]) fclose(file); // Create the word salad by placing words into grid - placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); + //placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); // TODO: // Check if all words were successfully placed - // Start the game if successful - // error message if some words couldn't be placed + for(int i = 0; i < 10000; i++) + { + placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); + + if(placedWords == wordCount) + { + + // Start the game if successful + return exitCode; + } + } + + // error message if some words couldn't be placed + fprintf(stderr, "could not start wordsalad.\n"); + exitCode = EXIT_FAILURE; } else { diff --git a/Wordsalat/main.o b/Wordsalat/main.o index c0e880b..224f0a1 100644 Binary files a/Wordsalat/main.o and b/Wordsalat/main.o differ diff --git a/Wordsalat/runTests b/Wordsalat/runTests index 7a63686..00cfe74 100755 Binary files a/Wordsalat/runTests and b/Wordsalat/runTests differ diff --git a/Wordsalat/testwords_delims.txt b/Wordsalat/testwords_delims.txt new file mode 100644 index 0000000..e721fce --- /dev/null +++ b/Wordsalat/testwords_delims.txt @@ -0,0 +1 @@ +Hund,Katze; Maus diff --git a/Wordsalat/testwords_empty.txt b/Wordsalat/testwords_empty.txt new file mode 100644 index 0000000..e69de29 diff --git a/Wordsalat/testwords_simple.txt b/Wordsalat/testwords_simple.txt new file mode 100644 index 0000000..37d7524 --- /dev/null +++ b/Wordsalat/testwords_simple.txt @@ -0,0 +1,3 @@ +Apfel +Banane +Kiwi \ No newline at end of file diff --git a/Wordsalat/wordsalad b/Wordsalat/wordsalad index 6614200..a4004a0 100755 Binary files a/Wordsalat/wordsalad and b/Wordsalat/wordsalad differ