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,18 +9,15 @@
|
|||||||
#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];
|
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN];
|
||||||
unsigned int wordCount = 0;
|
unsigned int wordCount = 0;
|
||||||
|
|
||||||
FILE *file = fopen(argv[1], "r");
|
FILE *file = fopen("words.txt", "r");
|
||||||
if (file != NULL) {
|
if (file != NULL) {
|
||||||
unsigned int placedWords = 0;
|
unsigned int placedWords = 0;
|
||||||
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
||||||
@ -39,11 +36,6 @@ int main(int argc, char *argv[])
|
|||||||
exitCode = EXIT_FAILURE;
|
exitCode = EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Datei konnte nicht geöffnet werden.\n");
|
|
||||||
exitCode = EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user