From ebb886ae9e2ee09cdea397078dc5802e5629249a Mon Sep 17 00:00:00 2001 From: kachelto100370 Date: Tue, 4 Nov 2025 04:57:02 +0100 Subject: [PATCH] Last commits of tonight --- Start_Linux/game.c | 40 +++++++++++++++++++++++++++++++++------- Start_Linux/input.c | 5 ++--- Start_Linux/main.c | 13 +++++++++++-- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/Start_Linux/game.c b/Start_Linux/game.c index 38a1d57..fa70d1a 100644 --- a/Start_Linux/game.c +++ b/Start_Linux/game.c @@ -6,19 +6,20 @@ #define MAX_RAND_TRIES_PER_WORD 10 #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 */ void emptyArray(); int placeWord(); void fillEmptySpots(); + +//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) { srand(time(NULL)); emptyArray(salad,MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN); placeWord(salad,words); - fillEmptySpots(salad); + fillEmptySpots(salad, MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN); } // Prints the word salad to console @@ -46,10 +47,35 @@ void emptyArray(char array[][], int arrayLength) int placeWord(char intoArray[][], char insertedWord[][]) { - + int numberWord; + int tries; + while(tries <= MAX_RAND_TRIES_PER_WORD) + { + int xCord = rand() % MAX_SEARCH_FIELD_LEN; + int yCord = rand() % MAX_SEARCH_FIELD_LEN; + int isHorizontal = rand() % 2; + + if(isHorizontal) + { + if(xCord + sizeof(insertedWord[numberWord][0]) <= MAX_SEARCH_FIELD_LEN) + { + + } + + } + } } -void fillEmptySpots(char useArray[][]) +void fillEmptySpots(char array[][], int arrayLength) { - + char* element = (char*) &array; + for(int i = 0; i < arrayLength; i++ ) + { + if(*element == EMPTY_CHAR) + { + *element == rand() % ('Z' - 'A' + 1) + 'A'; + } + element++; + } + } \ No newline at end of file diff --git a/Start_Linux/input.c b/Start_Linux/input.c index a6149bb..ea19ad0 100644 --- a/Start_Linux/input.c +++ b/Start_Linux/input.c @@ -2,7 +2,6 @@ #include #include -// TODO: // eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei // (words.txt) einliest und als C-String zurückgibt. @@ -12,7 +11,7 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN],unsigned int maxWordCount) file = fopen("words.txt", "r"); if (file == NULL) { - return -1; + return -1; } char teiler[] = " ;,.\n"; @@ -32,6 +31,6 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN],unsigned int maxWordCount) aktuellesWort = strtok(NULL, teiler); // Nächstes Token } } - + fclose(file); return wortAnzahl; // Anzahl der eingelesenen Wörter } \ No newline at end of file diff --git a/Start_Linux/main.c b/Start_Linux/main.c index 03da755..8da67d8 100644 --- a/Start_Linux/main.c +++ b/Start_Linux/main.c @@ -38,8 +38,17 @@ int main(int argc, char *argv[]) // TODO: // Check if all words were successfully placed - // Start the game if successful - // error message if some words couldn't be placed + if(placedWords == wordCount) + { + // Start the game if successful + } + else + { + // error message if some words couldn't be placed + fprintf(stderr, "Could not place every word \n"); + exitCode = EXIT_FAILURE; + } + } else