generated from freudenreichan/info2Praktikum-Wortsalat
game main input änderung v2
This commit is contained in:
parent
3dee993d24
commit
c671a2cf52
@ -1,6 +1,6 @@
|
||||
#include "game.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
// Input eine datei erstellen und einfügen sodass wie eine andere datei zu implementierne und dazu noch Ende und Wichtig ! noch main funktion einfügen //
|
||||
@ -17,11 +17,13 @@ typedef enum {HORIZONTAL, VERTIKAL} Direction;
|
||||
// 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)
|
||||
{
|
||||
for (int r=0; r< serachFieldLen; r++) {
|
||||
int placed_count=0;
|
||||
for (int r=0; r< searchFieldLen; r++) {
|
||||
for (int c=0;c< searchFieldLen; c++) {
|
||||
salad[r][c] = EMPTY_CHAR;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < wordCount; i++) {
|
||||
const char *word = words[i];
|
||||
int len = strlen(word);
|
||||
|
||||
@ -9,41 +9,33 @@
|
||||
#define SALAD_SIZE 20
|
||||
#define WINDOW_WIDTH 800
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int exitCode = EXIT_SUCCESS;
|
||||
srand(time(NULL));
|
||||
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];
|
||||
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];
|
||||
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN];
|
||||
unsigned int wordCount = 0;
|
||||
|
||||
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
|
||||
fclose(file);
|
||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, (const char(*)[MAX_WORD_LEN])words, wordCount);
|
||||
if (placedWords == wordCount) {
|
||||
printf("Info: %d Wörter geladen und platziert. Starte speil...\n", placedWords);
|
||||
showWordSalad(wordSalad, SALAD_SIZE);
|
||||
startGame(wordSalad, SALAD_SIZE, words, wordCount,WINDOW_WIDTH);
|
||||
printf("Spielbeendet.\n");
|
||||
} else {
|
||||
fprintf(stderr, "Fehler: Es konnten nur %d von %d Wörtern platziert werden.\n", placedWords, wordCount, wordCount);
|
||||
fprintf(stderr, "Das Spiel ist evtl. zu klein.\n");
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
FILE *file = fopen("words.txt", "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, (const char(*)[MAX_WORD_LEN])words, wordCount);
|
||||
if (placedWords == wordCount) {
|
||||
printf("Info: %d Wörter geladen und platziert. Starte speil...\n", placedWords);
|
||||
showWordSalad(wordSalad, SALAD_SIZE);
|
||||
startGame(wordSalad, SALAD_SIZE, words, wordCount,WINDOW_WIDTH);
|
||||
printf("Spielbeendet.\n");
|
||||
} else {
|
||||
fprintf(stderr, "Datei konnte nicht geöffnet werden.\n");
|
||||
fprintf(stderr, "Fehler: Es konnten nur %d von %d Wörtern platziert werden.\n", placedWords, wordCount, wordCount);
|
||||
fprintf(stderr, "Das Spiel ist evtl. zu klein.\n");
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
return exitCode;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user