angepasstes makefile

This commit is contained in:
Kristin 2025-11-02 16:56:58 +01:00
parent c5c2824a97
commit 8adb201876
5 changed files with 55 additions and 59 deletions

View File

@ -20,7 +20,6 @@ int createWordSalad(
unsigned int searchFieldLen, const char words[][MAX_WORD_LEN],
unsigned int wordCount) {
srand(time(NULL));
enum Richtung { HORIZONTAL, VERTIKAL };
// wipe field
@ -33,7 +32,7 @@ int createWordSalad(
salad[y][x] = EMPTY_CHAR;
}
}
int placedWords = 0; // variable platzierte Wörter
unsigned int placedWords = 0; // variable platzierte Wörter
// place words
// for schleife mit wortzahl = 0 bis wordCount
@ -59,18 +58,16 @@ int createWordSalad(
int y = rand() % searchFieldLen;
int fits = 1;
if (r == HORIZONTAL) {
if (r == VERTIKAL) {
if ((y + wortLen) > (searchFieldLen)) {
fits = 0;
}
if (fits) {
for (int i = 0; i < wortLen; i++) {
char var = salad[y + i][x];
if (var != EMPTY_CHAR) {
fits = 0;
}
for (int i = 0; (i < wortLen) && (fits != 0); i++) {
char var = salad[y + i][x];
if (var != EMPTY_CHAR) {
fits = 0;
}
}
@ -80,26 +77,22 @@ int createWordSalad(
salad[y + i][x] = words[wortNummer][i];
}
platziert = 1;
placedWords++;
platziert = 1;
}
}
else if (r == VERTIKAL) {
else if (r == HORIZONTAL) {
if ((x + wortLen) > searchFieldLen) {
fits = 0;
}
if (fits) {
for (int i = 0; i < wortLen; i++) {
char var = salad[y][x + i];
if (var != EMPTY_CHAR) {
fits = 0;
}
for (int i = 0; (i < wortLen) && (fits != 0); i++) {
char var = salad[y][x + i];
if (var != EMPTY_CHAR) {
fits = 0;
}
}
@ -109,9 +102,8 @@ int createWordSalad(
salad[y][x + i] = words[wortNummer][i];
}
platziert = 1;
placedWords++;
platziert = 1;
}
}

View File

@ -2,10 +2,6 @@
#include <ctype.h>
#include <string.h>
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei
// (words.txt) einliest und als C-String zurückgibt.
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN],
unsigned int maxWordCount) {
@ -15,38 +11,32 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN],
return 0;
}
// zunächst fehlerhaften String einlesen und in anderem Array
// zwischenspeichern
char line[MAX_LINE_LEN];
char *token;
int wordCount = 0;
unsigned int wordCount = 0;
while (fgets(line, sizeof(line), file) !=
NULL && // während mit fgets alle Zeichen aus dem file eingelesen
// werden
wordCount < maxWordCount) {
while ((fgets(line, sizeof(line), file) != NULL) &&
(wordCount < maxWordCount)) {
token = strtok(line, " ;,.\n"); // Erstes Wort mit strtok aus dem
// fehlerhaften String herauslösen
// Token initialisieren
char *token = strtok(line, " ,;.\n");
while (token != NULL &&
wordCount < maxWordCount) { // while strtok nicht am Ende ist und
// noch Wörter in words passen
while (token && (wordCount < maxWordCount)) {
for (int i = 0; token[i] != '\0'; i++) {
token[i] = toupper((unsigned char)token[i]);
if (*token == '\0') {
token = strtok(NULL, " ,;.\n");
continue;
}
strncpy(words[wordCount], token,
sizeof(words[wordCount]) -
1); // mit strcpy das aktuelle Wort in words kopieren
words[wordCount][sizeof(words[wordCount]) - 1] =
'\0'; // Nullterminator mit sizeof des aktuellen Worts - 1 an Ende des
// Worts setzen
// Token in Großbuchstaben konvertieren
for (int i = 0; token[i] != '\0'; i++) {
token[i] = toupper(token[i]);
}
// In das words-Array kopieren
strcpy(words[wordCount], token);
wordCount++; // Nächstes Wort
token = strtok(NULL, " ;,.\n"); // Nächstes Token
token = strtok(NULL, " ,;.\n"); // Nächstes Token
}
}

View File

@ -3,11 +3,13 @@
#include "input.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAX_NUMBER_OF_WORDS 100
#define SALAD_SIZE 20
int main(int argc, char *argv[]) {
srand(time(NULL));
int exitCode = EXIT_SUCCESS;
// Check if the correct number of arguments is provided
@ -15,8 +17,8 @@ int main(int argc, char *argv[]) {
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]; // Array to hold the words to be used in the game
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN] = {
{0}}; // Array to hold the words to be used in the game
unsigned int wordCount = 0;
FILE *file = fopen(argv[1], "r");
@ -37,11 +39,21 @@ int main(int argc, char *argv[]) {
// Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed
printf("Placed Words: %d\n", placedWords);
printf("Word Count:%d\n", wordCount);
int var = 0;
for (unsigned int i = 0; i < wordCount; i++) {
printf("Word %u: %s ", i, words[i]);
if (var == 10) {
printf("\n");
var = 0;
}
}
if (placedWords == wordCount) {
startGame(wordSalad, SALAD_SIZE, words, wordCount,
MAX_SEARCH_FIELD_LEN);
startGame(wordSalad, SALAD_SIZE, words, placedWords, 1024);
}
else

View File

@ -15,16 +15,18 @@ wordsalad_initial:
#---------------------------
# eigenes Target bauen
#---------------------------
wordsalad_myversion: main.o graphicalGame.o
$(CC) -o wordsalad_myversion main.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
wordsalad_myversion: main.o graphicalGame.o input.o game.o
$(CC) main.o graphicalGame.o input.o game.o -o wordsalad_myversion $(BINARIES)/libraylib.a $(LDFLAGS)
# --------------------------
# Normales Spiel bauen
# --------------------------
all: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
all: $(BINARIES)/libwordsalad.a main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)
$(BINARIES)/libwordsalad.a: main.o input.o game.o graphicalGame.o
ar rcs $(BINARIES)/libwordsalad.a main.o input.o game.o graphicalGame.o
main.o: main.c
$(CC) -c $(CFLAGS) main.c
@ -49,4 +51,4 @@ test: input.o game.o unit_tests.c
# Clean
# --------------------------
clean:
rm -f *.o *.exe
rm -f *.o *.exe $(BINARIES)/libwordsalad.a

Binary file not shown.