From b60812d6c6020179087ec7b65c545c5d27b7cf26 Mon Sep 17 00:00:00 2001 From: Simon Schuerer Date: Mon, 3 Nov 2025 14:11:13 +0000 Subject: [PATCH] Start_Windows/game.c aktualisiert --- Start_Windows/game.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Start_Windows/game.c b/Start_Windows/game.c index d8cc133..58814c9 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -10,6 +10,35 @@ /* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren * restliche Felder mit zufälligen Buchstaben füllen */ + /********************************************************************************************* + + // Platziert Wörter aus der Liste zufällig horizontal oder vertikal +void createWordSalad(char grid[20][20], const char words[][50], int wordCount) { + srand(time(NULL)); + for (int w = 0; w < wordCount; w++) { + int len = strlen(words[w]); + int horizontal = rand() % 2; + int row = rand() % 20; + int col = rand() % 20; + + if (horizontal && col + len <= 20) { + for (int i = 0; i < len; i++) grid[row][col + i] = words[w][i]; + } else if (!horizontal && row + len <= 20) { + for (int i = 0; i < len; i++) grid[row + i][col] = words[w][i]; + } + } +} + +// Füllt alle leeren Felder mit zufälligen Buchstaben +void fillEmptySpaces(char grid[20][20]) { + for (int i = 0; i < 20; i++) + for (int j = 0; j < 20; j++) + if (grid[i][j] == 0) + grid[i][j] = 'A' + rand() % 26; +} + +************************************************************************************************************/ + // 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) {