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 "game.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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 //
|
// 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
|
// 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)
|
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++) {
|
for (int c=0;c< searchFieldLen; c++) {
|
||||||
salad[r][c] = EMPTY_CHAR;
|
salad[r][c] = EMPTY_CHAR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < wordCount; i++) {
|
for (int i = 0; i < wordCount; i++) {
|
||||||
const char *word = words[i];
|
const char *word = words[i];
|
||||||
int len = strlen(word);
|
int len = strlen(word);
|
||||||
|
|||||||
@ -9,41 +9,33 @@
|
|||||||
#define SALAD_SIZE 20
|
#define SALAD_SIZE 20
|
||||||
#define WINDOW_WIDTH 800
|
#define WINDOW_WIDTH 800
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
int main(int argc, char *argv[]) {
|
||||||
int exitCode = EXIT_SUCCESS;
|
int exitCode = EXIT_SUCCESS;
|
||||||
srand(time(NULL));
|
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");
|
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN];
|
||||||
if (file != NULL) {
|
unsigned int wordCount = 0;
|
||||||
unsigned int placedWords = 0;
|
|
||||||
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
|
||||||
|
|
||||||
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
|
FILE *file = fopen("words.txt", "r");
|
||||||
fclose(file);
|
if (file != NULL) {
|
||||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, (const char(*)[MAX_WORD_LEN])words, wordCount);
|
unsigned int placedWords = 0;
|
||||||
if (placedWords == wordCount) {
|
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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 {
|
} 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;
|
exitCode = EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user