angepasstes makefile
This commit is contained in:
parent
c5c2824a97
commit
8adb201876
@ -20,7 +20,6 @@ int createWordSalad(
|
|||||||
unsigned int searchFieldLen, const char words[][MAX_WORD_LEN],
|
unsigned int searchFieldLen, const char words[][MAX_WORD_LEN],
|
||||||
unsigned int wordCount) {
|
unsigned int wordCount) {
|
||||||
|
|
||||||
srand(time(NULL));
|
|
||||||
enum Richtung { HORIZONTAL, VERTIKAL };
|
enum Richtung { HORIZONTAL, VERTIKAL };
|
||||||
|
|
||||||
// wipe field
|
// wipe field
|
||||||
@ -33,7 +32,7 @@ int createWordSalad(
|
|||||||
salad[y][x] = EMPTY_CHAR;
|
salad[y][x] = EMPTY_CHAR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int placedWords = 0; // variable platzierte Wörter
|
unsigned int placedWords = 0; // variable platzierte Wörter
|
||||||
|
|
||||||
// place words
|
// place words
|
||||||
// for schleife mit wortzahl = 0 bis wordCount
|
// for schleife mit wortzahl = 0 bis wordCount
|
||||||
@ -59,18 +58,16 @@ int createWordSalad(
|
|||||||
int y = rand() % searchFieldLen;
|
int y = rand() % searchFieldLen;
|
||||||
int fits = 1;
|
int fits = 1;
|
||||||
|
|
||||||
if (r == HORIZONTAL) {
|
if (r == VERTIKAL) {
|
||||||
|
|
||||||
if ((y + wortLen) > (searchFieldLen)) {
|
if ((y + wortLen) > (searchFieldLen)) {
|
||||||
fits = 0;
|
fits = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fits) {
|
for (int i = 0; (i < wortLen) && (fits != 0); i++) {
|
||||||
for (int i = 0; i < wortLen; i++) {
|
char var = salad[y + i][x];
|
||||||
char var = salad[y + i][x];
|
if (var != EMPTY_CHAR) {
|
||||||
if (var != EMPTY_CHAR) {
|
fits = 0;
|
||||||
fits = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,26 +77,22 @@ int createWordSalad(
|
|||||||
|
|
||||||
salad[y + i][x] = words[wortNummer][i];
|
salad[y + i][x] = words[wortNummer][i];
|
||||||
}
|
}
|
||||||
|
|
||||||
platziert = 1;
|
|
||||||
placedWords++;
|
placedWords++;
|
||||||
|
platziert = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (r == VERTIKAL) {
|
else if (r == HORIZONTAL) {
|
||||||
|
|
||||||
if ((x + wortLen) > searchFieldLen) {
|
if ((x + wortLen) > searchFieldLen) {
|
||||||
fits = 0;
|
fits = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fits) {
|
for (int i = 0; (i < wortLen) && (fits != 0); i++) {
|
||||||
|
char var = salad[y][x + i];
|
||||||
for (int i = 0; i < wortLen; i++) {
|
if (var != EMPTY_CHAR) {
|
||||||
char var = salad[y][x + i];
|
fits = 0;
|
||||||
if (var != EMPTY_CHAR) {
|
|
||||||
fits = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,9 +102,8 @@ int createWordSalad(
|
|||||||
|
|
||||||
salad[y][x + i] = words[wortNummer][i];
|
salad[y][x + i] = words[wortNummer][i];
|
||||||
}
|
}
|
||||||
|
|
||||||
platziert = 1;
|
|
||||||
placedWords++;
|
placedWords++;
|
||||||
|
platziert = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,10 +2,6 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.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
|
// Read words from file and store in 'words' array
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN],
|
int readWords(FILE *file, char words[][MAX_WORD_LEN],
|
||||||
unsigned int maxWordCount) {
|
unsigned int maxWordCount) {
|
||||||
@ -15,40 +11,34 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN],
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// zunächst fehlerhaften String einlesen und in anderem Array
|
|
||||||
// zwischenspeichern
|
|
||||||
|
|
||||||
char line[MAX_LINE_LEN];
|
char line[MAX_LINE_LEN];
|
||||||
char *token;
|
unsigned int wordCount = 0;
|
||||||
int wordCount = 0;
|
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), file) !=
|
while ((fgets(line, sizeof(line), file) != NULL) &&
|
||||||
NULL && // während mit fgets alle Zeichen aus dem file eingelesen
|
(wordCount < maxWordCount)) {
|
||||||
// werden
|
|
||||||
wordCount < maxWordCount) {
|
// Token initialisieren
|
||||||
|
char *token = strtok(line, " ,;.\n");
|
||||||
|
|
||||||
token = strtok(line, " ;,.\n"); // Erstes Wort mit strtok aus dem
|
while (token && (wordCount < maxWordCount)) {
|
||||||
// fehlerhaften String herauslösen
|
|
||||||
|
|
||||||
while (token != NULL &&
|
if (*token == '\0') {
|
||||||
wordCount < maxWordCount) { // while strtok nicht am Ende ist und
|
token = strtok(NULL, " ,;.\n");
|
||||||
// noch Wörter in words passen
|
continue;
|
||||||
|
|
||||||
for (int i = 0; token[i] != '\0'; i++) {
|
|
||||||
token[i] = toupper((unsigned char)token[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(words[wordCount], token,
|
// Token in Großbuchstaben konvertieren
|
||||||
sizeof(words[wordCount]) -
|
for (int i = 0; token[i] != '\0'; i++) {
|
||||||
1); // mit strcpy das aktuelle Wort in words kopieren
|
token[i] = toupper(token[i]);
|
||||||
words[wordCount][sizeof(words[wordCount]) - 1] =
|
}
|
||||||
'\0'; // Nullterminator mit sizeof des aktuellen Worts - 1 an Ende des
|
|
||||||
// Worts setzen
|
// In das words-Array kopieren
|
||||||
|
strcpy(words[wordCount], token);
|
||||||
|
|
||||||
wordCount++; // Nächstes Wort
|
wordCount++; // Nächstes Wort
|
||||||
token = strtok(NULL, " ;,.\n"); // Nächstes Token
|
token = strtok(NULL, " ,;.\n"); // Nächstes Token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return wordCount; // Anzahl der eingelesenen Wörter
|
return wordCount; // Anzahl der eingelesenen Wörter
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,11 +3,13 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#define MAX_NUMBER_OF_WORDS 100
|
#define MAX_NUMBER_OF_WORDS 100
|
||||||
#define SALAD_SIZE 20
|
#define SALAD_SIZE 20
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
srand(time(NULL));
|
||||||
int exitCode = EXIT_SUCCESS;
|
int exitCode = EXIT_SUCCESS;
|
||||||
|
|
||||||
// Check if the correct number of arguments is provided
|
// 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]);
|
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
|
||||||
exitCode = EXIT_FAILURE;
|
exitCode = EXIT_FAILURE;
|
||||||
} else {
|
} else {
|
||||||
char words[MAX_NUMBER_OF_WORDS]
|
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN] = {
|
||||||
[MAX_WORD_LEN]; // Array to hold the words to be used in the game
|
{0}}; // Array to hold the words to be used in the game
|
||||||
unsigned int wordCount = 0;
|
unsigned int wordCount = 0;
|
||||||
|
|
||||||
FILE *file = fopen(argv[1], "r");
|
FILE *file = fopen(argv[1], "r");
|
||||||
@ -37,11 +39,21 @@ int main(int argc, char *argv[]) {
|
|||||||
// Check if all words were successfully placed
|
// Check if all words were successfully placed
|
||||||
// Start the game if successful
|
// Start the game if successful
|
||||||
// error message if some words couldn't be placed
|
// 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) {
|
if (placedWords == wordCount) {
|
||||||
|
|
||||||
startGame(wordSalad, SALAD_SIZE, words, wordCount,
|
startGame(wordSalad, SALAD_SIZE, words, placedWords, 1024);
|
||||||
MAX_SEARCH_FIELD_LEN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|||||||
@ -15,16 +15,18 @@ wordsalad_initial:
|
|||||||
#---------------------------
|
#---------------------------
|
||||||
# eigenes Target bauen
|
# eigenes Target bauen
|
||||||
#---------------------------
|
#---------------------------
|
||||||
wordsalad_myversion: main.o graphicalGame.o
|
wordsalad_myversion: main.o graphicalGame.o input.o game.o
|
||||||
$(CC) -o wordsalad_myversion main.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
$(CC) main.o graphicalGame.o input.o game.o -o wordsalad_myversion $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Normales Spiel bauen
|
# 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)
|
$(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
|
main.o: main.c
|
||||||
$(CC) -c $(CFLAGS) main.c
|
$(CC) -c $(CFLAGS) main.c
|
||||||
|
|
||||||
@ -49,4 +51,4 @@ test: input.o game.o unit_tests.c
|
|||||||
# Clean
|
# Clean
|
||||||
# --------------------------
|
# --------------------------
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o *.exe
|
rm -f *.o *.exe $(BINARIES)/libwordsalad.a
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user