Merge remote-tracking branch 'origin/main'

This commit is contained in:
Henrik Batz committed 2026-10-29 15:57:34 +01:00
commit 4a7d34044b
6 files changed
+261 -42

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
unity/*
raylib/*
macos-*/*
windows/*
linux/*
+18 -7
View File
@@ -1,12 +1,23 @@
#include "input.h"
#include <string.h>
#include <ctype.h>
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
int readWord(char *buffer, char *divisor, char words[][MAX_WORD_LEN], unsigned int maxWordCount, int *count);
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) {
char buffer[MAX_LINE_LEN];
int count = 0;
char *divisor = " ,;.\n";
while (fgets(buffer, MAX_LINE_LEN, file) != NULL) {
for (char *word = strtok(buffer, divisor); word != NULL && count < maxWordCount; word = strtok(NULL, divisor))
{
strncpy(words[count], word, MAX_WORD_LEN);
++count;
}
}
return count;
}
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
}
+37 -35
View File
@@ -6,49 +6,51 @@
#define MAX_NUMBER_OF_WORDS 100
#define SALAD_SIZE 20
#define WINDOW_WIDTH 480
int main(int argc, char *argv[])
{
int exitCode = EXIT_SUCCESS;
// Check if the correct number of arguments is provided
if(argc != 2)
{
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
exitCode = EXIT_FAILURE;
return EXIT_FAILURE;
}
else
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game
unsigned int wordCount = 0;
FILE *file = fopen(argv[1], "r");
if(file == NULL)
{
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game
unsigned int wordCount = 0;
FILE *file = fopen(argv[1], "r");
if(file != NULL)
{
unsigned int placedWords = 0;
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
// Read words from file and store in 'words' array
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
fclose(file);
// Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// TODO:
// Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed
}
else
{
// Print error message if file couldn't be opened
fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]);
exitCode = EXIT_FAILURE;
}
// Print error message if file couldn't be opened
fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]);
return EXIT_FAILURE;
}
return exitCode;
}
unsigned int placedWords = 0;
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
// Read words from file and store in 'words' array
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
fclose(file);
if(wordCount == 0)
{
fprintf(stderr, "No words found...\n");
return EXIT_FAILURE;
}
// Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
if(placedWords != wordCount)
{
fprintf(stderr, "Could not place %u out of %u words ...\n", wordCount - placedWords, wordCount);
return EXIT_FAILURE;
}
startGame(wordSalad, SALAD_SIZE, words, placedWords, WINDOW_WIDTH);
return EXIT_SUCCESS;
}