Files
Info2-Aufgaben/Startcode/main.c
T

71 lines
2.3 KiB
C

#include <stdlib.h>
#include <stdio.h>
#include "input.h"
#include "game.h"
#include "graphicalGame.h"
#define MAX_NUMBER_OF_WORDS 100 //Maximale Anzahl an Wörtern, die eingelesen werden können
#define SALAD_SIZE 20 //Größe des Wortsalats 20 Zeilen * 20 Spalten
int main(int argc, char *argv[]) // Hauptfunktion des Programms
// argc = Anzahl der übergebenen Kommandozeilenargumente
// argv = enthält die übergebenen Argumente
{
int exitCode = EXIT_SUCCESS; // Speichert, ob das Programm erfolgreich beendet wird
// EXIT_SUCCESS = kein Fehler
// 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)
{
startGame(wordSalad, SALAD_SIZE, words, wordCount,800);
}
else
{
fprintf(stderr, "Not all words could be placed.\n");
exitCode = EXIT_FAILURE;
}
// TODO:
// Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed
}
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;
}