61 lines
1.5 KiB
C
61 lines
1.5 KiB
C
#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
|
|
#define WINDOW_SIZE 700
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int exitCode = EXIT_SUCCESS;
|
|
|
|
if (argc != 2)
|
|
{
|
|
fprintf(stderr, "%s Textdatei mit angeben\n", argv[0]);
|
|
exitCode = EXIT_FAILURE;
|
|
}
|
|
else
|
|
{
|
|
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN];
|
|
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];
|
|
|
|
|
|
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
|
|
fclose(file);
|
|
|
|
|
|
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
|
|
|
|
|
if (placedWords == wordCount)
|
|
{
|
|
|
|
startGame(wordSalad, SALAD_SIZE, words, wordCount, WINDOW_SIZE);
|
|
}
|
|
else
|
|
{
|
|
|
|
fprintf(stderr, "Only %u of %u words could be placed in the word salad.\n", placedWords, wordCount);
|
|
exitCode = EXIT_FAILURE;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]);
|
|
exitCode = EXIT_FAILURE;
|
|
}
|
|
}
|
|
|
|
return exitCode;
|
|
} |