Compare commits

...
6 Commits
6 changed files with 36 additions and 15 deletions

No files matched your search

+3 -2
View File
@@ -1,4 +1,5 @@
#include "game.h" #include "game.h"
#include "input.h"
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -40,11 +41,11 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
int dir = rand() % 2; int dir = rand() % 2;
// cant place vertically // cant place vertically
if(dir == 1 && MAX_SEARCH_FIELD_LEN < (y + (int) len -1)){ if(dir == 1 && MAX_SEARCH_FIELD_LEN < (y + (int) len)){
dir = 0; dir = 0;
} }
//cant place horizontally //cant place horizontally
if((x + (int) len -1) > MAX_SEARCH_FIELD_LEN){ if((x + (int) len) > MAX_SEARCH_FIELD_LEN){
continue; continue;
} }
+1 -1
View File
@@ -3,7 +3,7 @@
#include "input.h" #include "input.h"
#define MAX_SEARCH_FIELD_LEN 100 #define MAX_SEARCH_FIELD_LEN 20
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);
+2 -2
View File
@@ -27,7 +27,7 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
strncpy(words[count], copy, len); strncpy(words[count], copy, len);
words[count][len] = '\0'; words[count][len] = '\0';
count++;
//schaue ob auch alles groß geschrieben ist //schaue ob auch alles groß geschrieben ist
for(int i = 0; i < len; i++){ for(int i = 0; i < len; i++){
@@ -36,7 +36,7 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
words[count][i] -= 32; words[count][i] -= 32;
} }
} }
count++;
token = strtok(NULL, delimit); token = strtok(NULL, delimit);
} }
} }
+1 -1
View File
@@ -3,7 +3,7 @@
#include <stdio.h> #include <stdio.h>
#define MAX_WORD_LEN 100 #define MAX_WORD_LEN 20
#define MAX_LINE_LEN 1024 #define MAX_LINE_LEN 1024
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount); int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount);
+17 -8
View File
@@ -6,7 +6,8 @@
#include "graphicalGame.h" #include "graphicalGame.h"
#define MAX_NUMBER_OF_WORDS 100 #define MAX_NUMBER_OF_WORDS 100
#define SALAD_SIZE 20 #define SALAD_SIZE 36
int checkSalad(char words[][MAX_WORD_LEN], char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], int placedWords, int wordCount){ int checkSalad(char words[][MAX_WORD_LEN], char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], int placedWords, int wordCount){
//Iteriere über alle verfügbaren Wörter //Iteriere über alle verfügbaren Wörter
@@ -54,10 +55,11 @@ 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][MAX_WORD_LEN]; // Array to hold the words to be used in the game char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game
unsigned int wordCount = 0; int wordCount = 0;
FILE *file = fopen(argv[1], "r"); FILE *file = fopen(argv[1], "r");
@@ -76,16 +78,23 @@ int main(int argc, char *argv[])
// TODO: // TODO:
// 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 (return input.c / game.c <=0)
int check = checkSalad(words, wordSalad, placedWords, wordCount); // Prüfen, ob input.c (readWords) einen Fehler oder 0 Wörter zurückgegeben hat
//Fehlerfall if (wordCount <= 0)
if(check != 0){ {
fprintf(stderr, "Not all words could be placed!\n"); fprintf(stderr, "Fehler: Es konnten keine Wörter eingelesen werden (input.c Rückgabewert <= 0).\n");
exitCode = EXIT_FAILURE;
}
// Prüfen, ob game.c (createWordSalad) einen Fehler zurückgegeben hat (<= 0) oder ob nicht alle eingelesenen Wörter platziert werden konnten
else if (placedWords <= 0 || placedWords < wordCount)
{
fprintf(stderr, "Fehler: Nicht alle Wörter konnten im Wortsalat platziert werden (game.c Rückgabewert <= 0).\n");
exitCode = EXIT_FAILURE; exitCode = EXIT_FAILURE;
} }
//keine Ahnung wiegroß pixelSize sein soll //keine Ahnung wiegroß pixelSize sein soll
startGame(wordSalad, MAX_SEARCH_FIELD_LEN, words, placedWords, SALAD_SIZE * SALAD_SIZE); startGame(wordSalad, MAX_SEARCH_FIELD_LEN, words, placedWords, MAX_SEARCH_FIELD_LEN * SALAD_SIZE);
} }
else else
{ {
+12 -1
View File
@@ -16,12 +16,14 @@ raylibfolder = ./raylib
unityfolder = ./unity unityfolder = ./unity
codefolder = . codefolder = .
# -------------------------- # --------------------------
# initiales Spiel bauen # initiales Spiel bauen
# -------------------------- # --------------------------
wordsalad_initial: wordsalad_initial:
$(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS) $(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
# -------------------------- # --------------------------
# Normales Spiel bauen # Normales Spiel bauen
# -------------------------- # --------------------------
@@ -48,6 +50,8 @@ TEST_BIN = runTests
test: input.o game.o $(codefolder)/unit_tests.c $(unityfolder)/unity.c test: input.o game.o $(codefolder)/unit_tests.c $(unityfolder)/unity.c
$(CC) -Wall -I$(unityfolder) -o $(TEST_BIN) input.o game.o $(codefolder)/unit_tests.c $(unityfolder)/unity.c $(CC) -Wall -I$(unityfolder) -o $(TEST_BIN) input.o game.o $(codefolder)/unit_tests.c $(unityfolder)/unity.c
# -------------------------- # --------------------------
# Clean # Clean
# -------------------------- # --------------------------
@@ -56,4 +60,11 @@ ifeq ($(OS),Windows_NT)
del /f *.o *.exe del /f *.o *.exe
else else
rm -f *.o wordsalad $(TEST_BIN) rm -f *.o wordsalad $(TEST_BIN)
endif endif
# --------------------------
# Eigene Version bauen (Deine main.c + libwordsalad.a)
# --------------------------
wordsalad_TMN: main.o graphicalGame.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad_TMN main.o graphicalGame.o -L$(BINARIES) -lwordsalad $(BINARIES)/libraylib.a $(LDFLAGS)