From 30ef5e53f5687b80d638f18f0a476f363f2de8a4 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 25 Oct 2025 17:49:24 +0200 Subject: [PATCH] sync --- Start_Windows/game.c | 54 +++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/Start_Windows/game.c b/Start_Windows/game.c index 08b197e..8a3e93a 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -14,6 +14,18 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount) { // set seed + // showWordSalad(salad, 20); + + for (int i = 0; i < MAX_SEARCH_FIELD_LEN; i++) + { + for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++) + { + salad[i][j] = '\0'; + } + } + + + showWordSalad(salad, 20); srand(time(NULL)); int wordsPlaced = 0; @@ -27,17 +39,13 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi // get random coordinates int rndX = rand() % (searchFieldLen - wordLength + 1); int rndY = rand() % (searchFieldLen - wordLength + 1); - - // 0 = horizontal 1 = vertikal - int direction = rand() % 2; - switch (direction) +// rand() % 2 + if (1) { - case 0: - retries = 0; while (letterPlaced < wordLength) { // checks if word fits into gamefield - while (!(checkSquare == wordLength) && (retries < 10)) + while (checkSquare != wordLength && retries < 10) { checkSquare = 0; // checks if squares to paste into is already taken @@ -53,16 +61,16 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi rndX = rand() % (searchFieldLen - wordLength + 1); rndY = rand() % (searchFieldLen - wordLength + 1); - retries++; + // retries++; } } if (retries >= 10) { - printf("Word %u couldn't be placed", n); + printf("Word %d couldn't be placed", n); break; } - + printf("%d %d",n, checkSquare); // pastes word into the line if (checkSquare == wordLength) { @@ -73,15 +81,15 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi } } } - wordsPlaced++; - case 1: - retries = 0; + } + else + { while (letterPlaced < wordLength) { // checks if word fits into gamefield - while (!(checkSquare == wordLength) && (retries < 10)) + while (checkSquare != wordLength && retries < 10) { checkSquare = 0; // checks if squares to paste into is already taken @@ -117,7 +125,6 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi } } } - wordsPlaced++; } } @@ -130,10 +137,12 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi if(salad[y][x] == '\0') { // random number from 65 (A) to 90 (Z) with ASCII - salad[y][x] = (char) (rand() % (25 + 1) + 65); + // salad[y][x] = (char) (rand() % (25 + 1) + 65); + salad[y][x] = 120; } } } + return 15; } // Prints the word salad to console @@ -150,3 +159,16 @@ void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], printf(" %c\n", salad[i][searchFieldLen]); } } + +// Clear Wordsalad +void clearWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) +{ + int i, j = 0; + for (i = 0; i < searchFieldLen; i++) + { + for (j = 0; j < searchFieldLen; j++) + { + salad[i][j] = '\0'; + } + } +} \ No newline at end of file