diff --git a/Start_Windows/.idea/editor.xml b/Start_Windows/.idea/editor.xml index 963c96f..7fcd005 100644 --- a/Start_Windows/.idea/editor.xml +++ b/Start_Windows/.idea/editor.xml @@ -1,6 +1,103 @@ + \ No newline at end of file diff --git a/Start_Windows/game.c b/Start_Windows/game.c index 4384fad..941292f 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -13,101 +13,73 @@ * 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 direction = 0; - int step = 0; - int added = 0; +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 addedWords = 0; - int positionX = 0; - int positionY = 0; + int attempts = 0; + int added = 0; + int space = 1; + unsigned long long wordLength = 0; - srand(time(NULL)); - - for(int i = 0; i < searchFieldLen; i++) - { - for(int j = 0; j < searchFieldLen; j++) - { - salad[i][j] = EMPTY_CHAR; + for (int i = 0; i < searchFieldLen; i++) { + for (int j = 0; j < searchFieldLen; j++) { + salad[i][j] = EMPTY_CHAR; } } - while(step <= wordCount) - { - int tries = 0; - int wordLength = 0; - direction = rand() % 1; + for (int i=0; i < wordCount; i++) { - for (int i = 0; i < MAX_WORD_LEN; i++) - { - if (words[step][i] == '\0') - break; - wordLength++; - } - if(direction == 0) - { - while(added <= 0 && tries < MAX_RAND_TRIES_PER_WORD){ - positionY = rand() % searchFieldLen-1; - positionX = rand() % searchFieldLen-1; - if(searchFieldLen - positionX >= wordLength) - { + wordLength = strlen(words[i]); - for(int i = 0; i < searchFieldLen; i++) - { - if(salad[positionY][positionX+i] != EMPTY_CHAR) - { - tries++; - break; - } - for (int j = 0; j < searchFieldLen; j++) - { - salad[positionY][positionX+j] = words[step][j]; - added = 1; - } - } - - } - else + while (attempts <= MAX_RAND_TRIES_PER_WORD && added != 1) { + int direction = rand() % 2; + if (direction == 0) { + int collumn = rand() % searchFieldLen; + int row = rand() % searchFieldLen; + for (int j = 0; j < wordLength; j++) { - tries++; + if (salad[row][collumn+j] != EMPTY_CHAR) {space = 0; break;} } - } - step++; - tries = 0; - added = 0; - } - if(direction == 1) - { - while(added <= 0 && tries < MAX_RAND_TRIES_PER_WORD){ - positionY = rand() % searchFieldLen-1; - positionX = rand() % searchFieldLen-1; - if(searchFieldLen - positionY >= wordLength) + if ((collumn + wordLength >= searchFieldLen-1) || (space == 0)) {attempts++;} + else {for (int j = 0; j < wordLength; j++) + { + salad[row][collumn+j] = words[i][j]; + } + added=1; + addedWords++; + + } + } + else if (direction == 1) { + int collumn = rand() % searchFieldLen; + int row = rand() % searchFieldLen; + for (int j = 0; j < wordLength; j++) + { + if (salad[row+j][collumn] != EMPTY_CHAR) {space = 0; break;} + } + if ((row + wordLength >= searchFieldLen-1) || (space == 0)) {attempts++;} + else { + for (int j = 0; j < wordLength; j++) { - - for(int i = 0; i < searchFieldLen; i++) - { - if(salad[positionY+i][positionX] != EMPTY_CHAR) - { - tries++; - break; - } - for (int j = 0; j < searchFieldLen; j++) - { - salad[positionY+j][positionX] = words[step][j]; - added = 1; - } - } - + salad[row+j][collumn] = words[i][j]; } - else { - tries++; - } - step++; - tries = 0; - added = 0; - } + added=1; + addedWords++; + } + } + space = 1; + } + attempts = 0; + added = 0; - } + } + for (int i = 0; i < searchFieldLen; i++) { + for (int j = 0; j < searchFieldLen; j++) { + if (salad[i][j] == EMPTY_CHAR) + { + salad[i][j] = rand()%('Z'-'A'+1)+'A'; + } + } + } return addedWords; } diff --git a/Start_Windows/game.o b/Start_Windows/game.o index 1edb3db..9f84c3f 100644 Binary files a/Start_Windows/game.o and b/Start_Windows/game.o differ diff --git a/Start_Windows/graphicalGame.o b/Start_Windows/graphicalGame.o new file mode 100644 index 0000000..35dff31 Binary files /dev/null and b/Start_Windows/graphicalGame.o differ diff --git a/Start_Windows/main.c b/Start_Windows/main.c index 3c75bc5..ed129e6 100644 --- a/Start_Windows/main.c +++ b/Start_Windows/main.c @@ -41,21 +41,16 @@ int main(int argc, char *argv[]) if(wordCount == placedWords) { exitCode = EXIT_SUCCESS; + startGame(wordSalad,SALAD_SIZE, words,wordCount,750); } else { - exitCode = EXIT_FAILIURE; + exitCode = EXIT_FAILURE; + printf("Bei der Platzierung ist etwas falsch gelaufen!"); } // Start the game if successful - if(exitCode == EXIT_SUCCESS) - { - void startGame(const char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldSize, char words[][MAX_WORD_LEN], unsigned int numberOfWords, unsigned int windowWidth); - } // error message if some words couldn't be placed - else if(exitCode == EXIT_FAILURE) - { - printf("Bei der Platzierung ist etwas falsch gelaufen!"); - } + } else { diff --git a/Start_Windows/main.o b/Start_Windows/main.o new file mode 100644 index 0000000..b71a673 Binary files /dev/null and b/Start_Windows/main.o differ diff --git a/Start_Windows/runTests.exe b/Start_Windows/runTests.exe index 6eb5c3b..2489cfa 100644 Binary files a/Start_Windows/runTests.exe and b/Start_Windows/runTests.exe differ diff --git a/Start_Windows/wordsalad.exe b/Start_Windows/wordsalad.exe new file mode 100644 index 0000000..e502980 Binary files /dev/null and b/Start_Windows/wordsalad.exe differ