game main input änderung v2

This commit is contained in:
Efe Turhan 2025-11-03 15:20:50 +01:00
parent 3dee993d24
commit c671a2cf52
2 changed files with 25 additions and 31 deletions

View File

@ -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);

View File

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