From ad5a4de563f493770104e5d67bd40f16d54894c1 Mon Sep 17 00:00:00 2001 From: yannick Date: Mon, 3 Nov 2025 21:52:37 +0100 Subject: [PATCH] alles bis auf makefile --- Start_Windows/main.c | 77 ++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/Start_Windows/main.c b/Start_Windows/main.c index 3abf5f4..8d495d3 100644 --- a/Start_Windows/main.c +++ b/Start_Windows/main.c @@ -6,51 +6,66 @@ #define MAX_NUMBER_OF_WORDS 100 #define SALAD_SIZE 20 - - +#define WINDOW_SIZE 800 // Fenstergröße für das grafische Spiel int main(int argc, char *argv[]) { - int exitCode = EXIT_SUCCESS; +int exitCode = EXIT_SUCCESS; - // Check if the correct number of arguments is provided - if(argc != 2) +// Check if the correct number of arguments is provided +if(argc != 2) +{ + fprintf(stderr, "Usage: %s \n", argv[0]); + exitCode = EXIT_FAILURE; +} +else +{ + char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game + unsigned int wordCount = 0; + + FILE *file = fopen(argv[1], "r"); + + if(file != NULL) { - fprintf(stderr, "Usage: %s \n", argv[0]); - exitCode = EXIT_FAILURE; - } - else - { - char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game - unsigned int wordCount = 0; + unsigned int placedWords = 0; + char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad - FILE *file = fopen(argv[1], "r"); + // Read words from file and store in 'words' array + wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS); + fclose(file); - if(file != NULL) + // Create the word salad by placing words into grid + placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); + + // Check if all words were successfully placed + if (placedWords == wordCount) { - unsigned int placedWords = 0; - char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad + printf("All %u words successfully placed!\n\n", placedWords); - // Read words from file and store in 'words' array - wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS); - fclose(file); - - // Create the word salad by placing words into grid - 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 + // Show the generated word salad on console + showWordSalad(wordSalad, SALAD_SIZE); + // Start the graphical game (raylib-basierte Version) + printf("\nStarting graphical word search game ...\n"); + startGame(wordSalad, SALAD_SIZE, words, wordCount, WINDOW_SIZE); } else { - // Print error message if file couldn't be opened - fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]); + fprintf(stderr, + "Error: Only %u of %u words could be placed.\n" + "Please reduce the number of words or increase the grid size.\n", + placedWords, wordCount); exitCode = EXIT_FAILURE; } } + else + { + // Print error message if file couldn't be opened + fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]); + exitCode = EXIT_FAILURE; + } +} - return exitCode; -} \ No newline at end of file +return exitCode; + +}