2025-11-11 10:27:57 +01:00

72 lines
2.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdlib.h>
#include <stdio.h>
#include "input.h"
#include "game.h"
#include "graphicalGame.h"
#define MAX_NUMBER_OF_WORDS 100
#define SALAD_SIZE 20
int main(int argc, char *argv[])
{
int exitCode = EXIT_SUCCESS;
// Check if the correct number of arguments is provided
if(argc != 2)
{
fprintf(stderr, "Usage: %s <path to file with search words>\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)
{
unsigned int placedWords = 0;
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
// 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);
if (placedWords == wordCount) {
printf("[OK] %u/%u Wörter platziert.\n", placedWords, wordCount);
showWordSalad(wordSalad, SALAD_SIZE);
// Optional: Grafische Ausgabe starten, falls vorhanden.
// Aktivieren durch -DSTART_GRAPHICS beim Kompilieren
// und wenn in graphicalGame.h eine passende Funktion existiert.
#ifdef START_GRAPHICS
// Beispiel-Signatur bitte ggf. an deine API anpassen:
// void startGraphicalGame(const char field[][MAX_SEARCH_FIELD_LEN], unsigned int size,
// const char words[][MAX_WORD_LEN], unsigned int wordCount);
startGraphicalGame((const char (*)[MAX_SEARCH_FIELD_LEN])wordSalad,
SALAD_SIZE,
(const char (*)[MAX_WORD_LEN])words,
wordCount);
#endif
} else {
fprintf(stderr, "[FEHLER] Nur %u von %u Wörtern konnten platziert werden.\n",
placedWords, wordCount);
fprintf(stderr, "Tipp: Größe des Suchfeldes (SALAD_SIZE) erhöhen oder kürzere Wortliste verwenden.\n");
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;
}