Compare commits

...
6 Commits
4 changed files with 53 additions and 6 deletions

No files matched your search

+2 -1
View File
@@ -6,6 +6,7 @@
#define MAX_RAND_TRIES_PER_WORD 10 #define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0 #define EMPTY_CHAR 0
// Funktion die eine zufällige Zahl von 0-range zurückgibt
int randomNumberInRange(unsigned int range); int randomNumberInRange(unsigned int range);
//TODO: Spiellogik implementieren: //TODO: Spiellogik implementieren:
@@ -26,7 +27,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
} }
} }
// Schleife bis alle Wörter durchlaufen
for (int wordToBePlaced = 0; wordToBePlaced < wordCount; wordToBePlaced++) { for (int wordToBePlaced = 0; wordToBePlaced < wordCount; wordToBePlaced++) {
int triesPerWord = 1; int triesPerWord = 1;
while (triesPerWord <= MAX_RAND_TRIES_PER_WORD) { while (triesPerWord <= MAX_RAND_TRIES_PER_WORD) {
+32 -2
View File
@@ -6,7 +6,37 @@
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt. // 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], unsigned int maxWordCount) int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount){
{
char lineRead[MAX_LINE_LEN] = {};
char *splitters = ",; \n";
int wordsRead = 0;
while(fgets(lineRead,MAX_LINE_LEN,file) != NULL && wordsRead < maxWordCount){
char *token = strtok(lineRead, splitters);
while(token != NULL && wordsRead < maxWordCount){
strcpy(words[wordsRead],token);
//Kleinbuchstaben -> Grossbuchstaben
int len = strlen(words[wordsRead]);
for(int i = 0; i < len; i++){
if(islower(words[wordsRead][i])){
words[wordsRead][i] = toupper(words[wordsRead][i]);
}
}
wordsRead++;
token = strtok(NULL, splitters);
}
}
return wordsRead;
} }
+6 -1
View File
@@ -40,7 +40,12 @@ 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
if(wordCount == placedWords){
startGame(wordSalad,SALAD_SIZE,words,wordCount,800);
}else{
printf("error. not enough words could be placed");
return 0;
}
} }
else else
{ {
+13 -2
View File
@@ -22,11 +22,22 @@ codefolder = .
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)
#--------------
# Mein Test
#--------------
my_wordsalad_input: input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o my_wordsalad_input input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
final_wordsalad: main.o game.o input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o final_wordsalad main.o game.o input.o $(BINARIES)/libraylib.a $(LDFLAGS) $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
# -------------------------- # --------------------------
# NUR Game Test # NUR Game Test
# -------------------------- # --------------------------
wordsalad_mein_game: game.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a wordsalad_mein_game: game.o input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad_mein_test game.o $(BINARIES)/libraylib.a $(LDFLAGS) $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS) $(CC) $(CFLAGS) -o wordsalad_mein_test game.o input.o $(BINARIES)/libraylib.a $(LDFLAGS) $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
# -------------------------- # --------------------------
# Normales Spiel bauen # Normales Spiel bauen