Compare commits

...

17 Commits
main ... main

16 changed files with 683 additions and 86 deletions

1
.vscode/configurationCache.log vendored Normal file
View File

@ -0,0 +1 @@
{"buildTargets":[],"launchTargets":[],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":[],"compilerArgs":[]},"fileIndex":[]}}

6
.vscode/dryrun.log vendored Normal file
View File

@ -0,0 +1,6 @@
make.exe --dry-run --always-make --keep-going --print-directory
make: *** No targets specified and no makefile found. Stop.
make: Entering directory 'c:/Users/Moritz/Documents/Informatik 2 Praktikum/info2Praktikum-WortsalatGruppe1_richtig'
make: Leaving directory 'c:/Users/Moritz/Documents/Informatik 2 Praktikum/info2Praktikum-WortsalatGruppe1_richtig'

297
.vscode/targets.log vendored Normal file
View File

@ -0,0 +1,297 @@
make.exe all --print-data-base --no-builtin-variables --no-builtin-rules --question
make: *** No rule to make target 'all'. Stop.
# GNU Make 4.4.1
# Built for Windows32
# Copyright (C) 1988-2023 Free Software Foundation, Inc.
# License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
# This is free software: you are free to change and redistribute it.
# There is NO WARRANTY, to the extent permitted by law.
# Make data base, printed on Tue Nov 04 15:04:11 2025
# Variables
# environment
FPS_BROWSER_APP_PROFILE_STRING = Internet Explorer
# environment
SYSTEMDRIVE = C:
# environment
LC_ALL = C
# environment
USERPROFILE = C:\Users\Moritz
# environment
LOCALAPPDATA = C:\Users\Moritz\AppData\Local
# environment
VSCODE_CRASH_REPORTER_PROCESS_TYPE = extensionHost
# environment
VSCODE_CWD = C:\Program Files\Microsoft VS Code
# environment
CHOCOLATEYINSTALL = C:\ProgramData\chocolatey
# environment
SYSTEMROOT = C:\Windows
# environment
PROCESSOR_LEVEL = 25
# environment
PSMODULEPATH = C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
# default
MAKE_COMMAND := C:/ProgramData/chocolatey/lib/make/tools/install/bin/make.exe
# automatic
@D = $(patsubst %/,%,$(patsubst %\,%,$(dir $@)))
# environment
CHROME_CRASHPAD_PIPE_NAME = \\.\pipe\crashpad_3256_UEJPRASITZYEFUKO
# environment
FPS_BROWSER_USER_PROFILE_STRING = Default
# environment
VSCODE_HANDLES_UNCAUGHT_ERRORS = true
# default
.VARIABLES :=
# automatic
%D = $(patsubst %/,%,$(patsubst %\,%,$(dir $%)))
# environment
IVIROOTDIR64 = C:\Program Files\IVI Foundation\IVI\
# automatic
^D = $(patsubst %/,%,$(patsubst %\,%,$(dir $^)))
# automatic
%F = $(notdir $%)
# environment
VSCODE_CODE_CACHE_PATH = C:\Users\Moritz\AppData\Roaming\Code\CachedData\7d842fb85a0275a4a8e4d7e040d2625abbf7f084
# environment
LANG = C
# default
.LOADED :=
# environment
TMP = C:\Users\Moritz\AppData\Local\Temp
# default
.INCLUDE_DIRS := .
# environment
PROCESSOR_ARCHITEW6432 = AMD64
# makefile
MAKEFLAGS = pqrR
# environment
ONEDRIVE = C:\Users\Moritz\OneDrive
# makefile
CURDIR := c:/Users/Moritz/Documents/Informatik 2 Praktikum/info2Praktikum-WortsalatGruppe1_richtig
# environment
APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL = true
# automatic
*D = $(patsubst %/,%,$(patsubst %\,%,$(dir $*)))
# environment
PROGRAMFILES = C:\Program Files (x86)
# environment
MFLAGS = -pqrR
# default
.SHELLFLAGS := -c
# environment
COMMONPROGRAMW6432 = C:\Program Files\Common Files
# automatic
+D = $(patsubst %/,%,$(patsubst %\,%,$(dir $+)))
# makefile
MAKEFILE_LIST :=
# automatic
@F = $(notdir $@)
# environment
VSCODE_PID = 3256
# automatic
?D = $(patsubst %/,%,$(patsubst %\,%,$(dir $?)))
# environment
__PSLOCKDOWNPOLICY = 0
# automatic
*F = $(notdir $*)
# automatic
<D = $(patsubst %/,%,$(patsubst %\,%,$(dir $<)))
# environment
VSCODE_NLS_CONFIG = {"userLocale":"en-us","osLocale":"de-de","resolvedLanguage":"en","defaultMessagesFile":"C:\\Program Files\\Microsoft VS Code\\resources\\app\\out\\nls.messages.json","locale":"en-us","availableLanguages":{}}
# default
MAKE_HOST := Windows32
# environment
PROGRAMDATA = C:\ProgramData
# default
SHELL := sh.exe
# environment
HOMEPATH = \Users\Moritz
# default
MAKECMDGOALS := all
# environment
DRIVERDATA = C:\Windows\System32\Drivers\DriverData
# environment
COMSPEC = C:\Windows\system32\cmd.exe
# environment
WINDIR = C:\Windows
# environment
MAKELEVEL := 0
# default
MAKE = $(MAKE_COMMAND)
# environment
PATH = C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\ProgramData\chocolatey\bin;C:\msys64\ucrt64\bin;C:\Program Files\Microsoft VS Code\bin;C:\ProgramData\mingw64\mingw64\bin;C:\Program Files\dotnet\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin\;C:\Program Files\IVI Foundation\VISA\Win64\Bin\;C:\Program Files (x86)\National Instruments\Shared\LabVIEW CLI;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin;C:\Program Files (x86)\IVI Foundation\IVI\Bin\;C:\Program Files\IVI Foundation\IVI\Bin\;C:\Users\Moritz\AppData\Local\Programs\Python\Launcher\;C:\Users\Moritz\AppData\Local\Microsoft\WindowsApps;;C:\intelFPGA_lite\18.1\modelsim_ase\win32aloem
# environment
COMPUTERNAME = DESKTOP-TV1DOMD
# default
MAKEFILES :=
# automatic
^F = $(notdir $^)
# environment
NIEXTCCOMPILERSUPP = C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\
# environment
PROMPT = $P$G
# environment
CHOCOLATEYLASTPATHUPDATE = 134060496987803747
# environment
VXIPNPPATH64 = C:\Program Files\IVI Foundation\VISA\
# environment
NIDAQMXSWITCHDIR = C:\Program Files (x86)\National Instruments\NI-DAQ\Switch\
# environment
APPLICATION_INSIGHTS_NO_STATSBEAT = true
# environment
LOGONSERVER = \\DESKTOP-TV1DOMD
# environment
QSYS_ROOTDIR = C:\intelFPGA_lite\18.1\quartus\sopc_builder\bin
# environment
USERNAME = Moritz
# environment
COMMONPROGRAMFILES = C:\Program Files (x86)\Common Files
# automatic
?F = $(notdir $?)
# environment
PROGRAMW6432 = C:\Program Files
# environment
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
# automatic
+F = $(notdir $+)
# environment
ORIGINAL_XDG_CURRENT_DESKTOP = undefined
# environment
USERDOMAIN = DESKTOP-TV1DOMD
# 'override' directive
GNUMAKEFLAGS :=
# environment
OS = Windows_NT
# makefile
.DEFAULT_GOAL :=
# default
MAKE_VERSION := 4.4.1
# environment
PROGRAMFILES(X86) = C:\Program Files (x86)
# environment
USERDOMAIN_ROAMINGPROFILE = DESKTOP-TV1DOMD
# environment
NUMBER_OF_PROCESSORS = 12
# environment
PUBLIC = C:\Users\Public
# environment
QUARTUS_ROOTDIR = C:\intelFPGA_lite\18.1\quartus
# environment
SOPC_KIT_NIOS2 = C:\intelFPGA_lite\18.1\nios2eds
# environment
APPDATA = C:\Users\Moritz\AppData\Roaming
# environment
HOMEDRIVE = C:
# environment
PROCESSOR_ARCHITECTURE = x86
# environment
VXIPNPPATH = C:\Program Files (x86)\IVI Foundation\VISA\
# environment
COMMONPROGRAMFILES(X86) = C:\Program Files (x86)\Common Files
# environment
ELECTRON_RUN_AS_NODE = 1
# environment
TEMP = C:\Users\Moritz\AppData\Local\Temp
# environment
VSCODE_IPC_HOOK = \\.\pipe\14d1de4b-1.105.1-main-sock
# default
.RECIPEPREFIX :=
# automatic
<F = $(notdir $<)
# default
SUFFIXES :=
# environment
ALLUSERSPROFILE = C:\ProgramData
# environment
SESSIONNAME = Console
# default
.FEATURES := target-specific order-only second-expansion else-if shortest-stem undefine oneshell nocomment grouped-target extra-prereqs notintermediate shell-export archives jobserver output-sync load dospaths
# environment
PROCESSOR_REVISION = 5000
# environment
IVIROOTDIR32 = C:\Program Files (x86)\IVI Foundation\IVI\
# environment
VSCODE_ESM_ENTRYPOINT = vs/workbench/api/node/extensionHostProcess
# environment
PROCESSOR_IDENTIFIER = AMD64 Family 25 Model 80 Stepping 0, AuthenticAMD
# variable set hash-table stats:
# Load=103/1024=10%, Rehash=0, Collisions=9/128=7%
# Pattern-specific Variable Values
# No pattern-specific variable values.
# Directories
# . (key c:/Users/Moritz/Documents/Informatik 2 Praktikum/info2Praktikum-WortsalatGruppe1_richtig, mtime 1761578721): 11 files, no impossibilities.
# 11 files, no impossibilities in 1 directories.
# Implicit Rules
# No implicit rules.
# Files
# Not a target:
Makefile:
# Implicit rule search has been done.
# File does not exist.
# File has been updated.
# Failed to be updated.
# Not a target:
.DEFAULT:
# Implicit rule search has not been done.
# Modification time never checked.
# File has not been updated.
# Not a target:
all:
# Command line target.
# Implicit rule search has been done.
# File does not exist.
# File has not been updated.
# Not a target:
makefile:
# Implicit rule search has been done.
# File does not exist.
# File has been updated.
# Failed to be updated.
# Not a target:
makefile.mak:
# Implicit rule search has been done.
# File does not exist.
# File has been updated.
# Failed to be updated.
# Not a target:
GNUmakefile:
# Implicit rule search has been done.
# File does not exist.
# File has been updated.
# Failed to be updated.
# files hash-table stats:
# Load=7/1024=1%, Rehash=0, Collisions=0/17=0%
# VPATH Search Paths
# No 'vpath' search paths.
# No general ('VPATH' variable) search path.
# strcache buffers: 1 (0) / strings = 18 / storage = 209 B / avg = 11 B
# current buf: size = 8174 B / used = 209 B / count = 18 / avg = 11 B
# strcache performance: lookups = 21 / hit rate = 14%
# hash-table stats:
# Load=18/8192=0%, Rehash=0, Collisions=0/21=0%
# Finished Make data base on Tue Nov 04 15:04:11 2025

View File

@ -4,9 +4,42 @@
// TODO: // TODO:
// 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.
/**
* @param file Zeiger auf die geöffnete Datei
* @param words 2D-Array zum Speichern der Wörter
* @param maxWordCount Maximale Anzahl von Wörtern, die eingelesen werden sollen
* @return Anzahl der eingelesenen Wörter
*/
// Read words from file and store in 'words' array // Read words from file and store in 'words' array
// ERLEDIGT
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{ {
if (file == NULL || words == NULL || maxWordCount == 0) {
return 0;
}
int wordCount = 0;
char line[MAX_LINE_LEN];
// Zeilen einlesen
while (wordCount < maxWordCount && fgets(line, MAX_LINE_LEN, file) != NULL) {
// Zeile in Wörter aufteilen (Trennzeichen: Leerzeichen, Komma, Semikolon, Newline)
char *token = strtok(line, " ,;\t\n\r");
while (token != NULL && wordCount < maxWordCount) {
// Prüfen ob Token nicht leer ist
if (strlen(token) > 0 && strlen(token) < MAX_WORD_LEN) {
// Wort kopieren und in Großbuchstaben umwandeln
strcpy(words[wordCount], token);
for (int i = 0; words[wordCount][i] != '\0'; i++) {
words[wordCount][i] = toupper((unsigned char)words[wordCount][i]);
}
wordCount++;
}
// Nächstes Wort
token = strtok(NULL, " ,;\t\n\r");
}
}
return wordCount;
} }

View File

@ -36,10 +36,21 @@ int main(int argc, char *argv[])
// Create the word salad by placing words into grid // Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// TODO: // TODO:
// Check if all words were successfully placed // Check if all words were successfully placed
// Start the game if successful if(placedWords == wordCount)
// error message if some words couldn't be placed {
// Start the game if successful
startGame(wordSalad,SALAD_SIZE,words,wordCount,SALAD_SIZE);
}
else
{
// Error message if some words couldn't be placed
fprintf(stderr, "Error: Only %u out of %u words could be placed in the word salad.\n",
placedWords, wordCount);
exitCode = EXIT_FAILURE;
}
} }
else else

View File

@ -2,6 +2,7 @@
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#define MAX_RAND_TRIES_PER_WORD 10 #define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0 #define EMPTY_CHAR 0
@ -11,13 +12,96 @@
* restliche Felder mit zufälligen Buchstaben füllen */ * restliche Felder mit zufälligen Buchstaben füllen */
// Creates the word salad by placing words randomly and filling empty spaces // Creates the word salad by placing words randomly and filling empty spaces
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)
{ {
// Spielfeld vorbereiten
for(unsigned int i = 0; i < searchFieldLen; i++) {
for(unsigned int j = 0; j < searchFieldLen; j++) {
salad[i][j] = EMPTY_CHAR;
}
}
int placedWordsCount = 0; // Zähler für platzierte Wörter
// Jedes Wort versuchen zu platzieren
for (unsigned int w = 0; w < wordCount; w++) {
size_t len = strlen(words[w]);
int placed = 0;
for(int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD && !placed; attempt++) {
int horizontal = rand() % 2;
int row = rand() % searchFieldLen;
int col = rand() % searchFieldLen;
if(horizontal) {
// Horizontal platzieren
if(col + len > searchFieldLen) continue;
int conflict = 0;
for(size_t i = 0; i < len; i++) {
if(salad[row][col+i] != EMPTY_CHAR && salad[row][col+i] != words[w][i]) {
conflict = 1;
break;
}
}
if(conflict) continue;
for(size_t i = 0; i < len; i++) {
salad[row][col+i] = words[w][i];
}
placed = 1;
}
else {
// Vertikal platzieren
if(row + len > searchFieldLen) continue;
int conflict = 0;
for(size_t i = 0; i < len; i++) {
if(salad[row+i][col] != EMPTY_CHAR && salad[row+i][col] != words[w][i]) {
conflict = 1;
break;
}
}
if(conflict) continue;
for(size_t i = 0; i < len; i++) {
salad[row+i][col] = words[w][i];
}
placed = 1;
}
}
if(placed) {
placedWordsCount++;
}
}
// Leere Felder mit zufälligen Buchstaben befüllen
for(unsigned int i = 0; i < searchFieldLen; i++) {
for(unsigned int j = 0; j < searchFieldLen; j++) {
if (salad[i][j] == EMPTY_CHAR) {
salad[i][j] = 'A' + rand() % 26;
}
}
}
return placedWordsCount; // Rückgabewert wie viele Wörter eingefügt wurden
} }
// Prints the word salad to console // Prints the word salad to console
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
unsigned int searchFieldLen)
{ {
for (int i = 0; i < searchFieldLen; i++) {
} for (int j = 0; j < searchFieldLen; j++) {
printf("%c", salad[i][j]);
printf(" ");
}
printf("\n");
}
}

View File

@ -4,9 +4,42 @@
// TODO: // TODO:
// 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.
/**
* @param file Zeiger auf die geöffnete Datei
* @param words 2D-Array zum Speichern der Wörter
* @param maxWordCount Maximale Anzahl von Wörtern, die eingelesen werden sollen
* @return Anzahl der eingelesenen Wörter
*/
// Read words from file and store in 'words' array // Read words from file and store in 'words' array
// ERLEDIGT
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{ {
if (file == NULL || words == NULL || maxWordCount == 0) {
return 0;
}
int wordCount = 0;
char line[MAX_LINE_LEN];
// Zeilen einlesen
while (wordCount < maxWordCount && fgets(line, MAX_LINE_LEN, file) != NULL) {
// Zeile in Wörter aufteilen (Trennzeichen: Leerzeichen, Komma, Semikolon, Newline)
char *token = strtok(line, " ,;\t\n\r");
while (token != NULL && wordCount < maxWordCount) {
// Prüfen ob Token nicht leer ist
if (strlen(token) > 0 && strlen(token) < MAX_WORD_LEN) {
// Wort kopieren und in Großbuchstaben umwandeln
strcpy(words[wordCount], token);
for (int i = 0; words[wordCount][i] != '\0'; i++) {
words[wordCount][i] = toupper((unsigned char) words[wordCount][i]);
}
wordCount++;
}
// Nächstes Wort
token = strtok(NULL, " ,;\t\n\r");
}
}
return wordCount;
} }

Binary file not shown.

View File

@ -37,10 +37,21 @@ int main(int argc, char *argv[])
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// TODO: // TODO:
// Check if all words were successfully placed // Check if all words were successfully placed
// Start the game if successful if(placedWords == wordCount)
// error message if some words couldn't be placed {
// Start the game if successful
startGame(wordSalad,SALAD_SIZE,words,wordCount,500);
// welche Variable wird für windowWidth gewählt?
}
else
{
// Error message if some words couldn't be placed
fprintf(stderr, "Error: Only %u out of %u words could be placed in the word salad.\n",
placedWords, wordCount);
exitCode = EXIT_FAILURE;
}
} }
else else
{ {

View File

@ -3,24 +3,20 @@ CFLAGS = -g -Wall
LDFLAGS = -framework OpenGL -framework CoreFoundation -framework CoreGraphics -framework IOKit -framework Cocoa -framework CoreVideo LDFLAGS = -framework OpenGL -framework CoreFoundation -framework CoreGraphics -framework IOKit -framework Cocoa -framework CoreVideo
ARCH := $(shell uname -m) ARCH := $(shell uname -m)
BINARIES = ./macos-$(ARCH) BINARIES = ./macos-$(ARCH)
raylib_folder = ./raylib
unityfolder = ./unity unityfolder = ./unity
# -------------------------- RAYLIB_PATH = $(shell brew --prefix raylib)
# initiales Spiel bauen RAYLIB_INCLUDE = -I$(RAYLIB_PATH)/include
# -------------------------- RAYLIB_LIB = -L$(RAYLIB_PATH)/lib -lraylib
wordsalad_initial:
$(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
# -------------------------- wordsalad_initial:
# Normales Spiel bauen $(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(RAYLIB_LIB) $(LDFLAGS)
# --------------------------
wordsalad: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a wordsalad: main.o input.o game.o graphicalGame.o
$(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 $(RAYLIB_LIB) $(LDFLAGS)
main.o: main.c main.o: main.c
$(CC) -c $(CFLAGS) main.c $(CC) -c $(CFLAGS) $(RAYLIB_INCLUDE) main.c
input.o: input.c input.o: input.c
$(CC) -c $(CFLAGS) input.c $(CC) -c $(CFLAGS) input.c
@ -29,18 +25,11 @@ game.o: game.c
$(CC) -c $(CFLAGS) game.c $(CC) -c $(CFLAGS) game.c
graphicalGame.o: graphicalGame.c graphicalGame.o: graphicalGame.c
$(CC) -I$(raylibfolder) -c $(CFLAGS) graphicalGame.c $(CC) -c $(CFLAGS) $(RAYLIB_INCLUDE) graphicalGame.c
# --------------------------
# Unit Tests
# --------------------------
TEST_BIN = runTests TEST_BIN = runTests
test: input.o game.o unit_tests.c $(BINARIES)/libunity.a test: input.o game.o unit_tests.c $(BINARIES)/libunity.a
$(CC) -Wall -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a $(CC) -Wall -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a
# --------------------------
# Clean
# --------------------------
clean: clean:
rm -f *.o wordsalad rm -f *.o wordsalad wordsalad_initial $(TEST_BIN)

BIN
Start_Mac/runTests Executable file

Binary file not shown.

BIN
Start_Mac/wordsalad_initial Executable file

Binary file not shown.

View File

@ -2,6 +2,7 @@
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#define MAX_RAND_TRIES_PER_WORD 10 #define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0 #define EMPTY_CHAR 0
@ -11,13 +12,96 @@
* restliche Felder mit zufälligen Buchstaben füllen */ * restliche Felder mit zufälligen Buchstaben füllen */
// Creates the word salad by placing words randomly and filling empty spaces // Creates the word salad by placing words randomly and filling empty spaces
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)
{ {
// Spielfeld vorbereiten
for(unsigned int i = 0; i < searchFieldLen; i++) {
for(unsigned int j = 0; j < searchFieldLen; j++) {
salad[i][j] = EMPTY_CHAR;
}
}
int placedWordsCount = 0; // Zähler für platzierte Wörter
// Jedes Wort versuchen zu platzieren
for (unsigned int w = 0; w < wordCount; w++) {
size_t len = strlen(words[w]);
int placed = 0;
for(int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD && !placed; attempt++) {
int horizontal = rand() % 2;
int row = rand() % searchFieldLen;
int col = rand() % searchFieldLen;
if(horizontal) {
// Horizontal platzieren
if(col + len > searchFieldLen) continue;
int conflict = 0;
for(size_t i = 0; i < len; i++) {
if(salad[row][col+i] != EMPTY_CHAR && salad[row][col+i] != words[w][i]) {
conflict = 1;
break;
}
}
if(conflict) continue;
for(size_t i = 0; i < len; i++) {
salad[row][col+i] = words[w][i];
}
placed = 1;
}
else {
// Vertikal platzieren
if(row + len > searchFieldLen) continue;
int conflict = 0;
for(size_t i = 0; i < len; i++) {
if(salad[row+i][col] != EMPTY_CHAR && salad[row+i][col] != words[w][i]) {
conflict = 1;
break;
}
}
if(conflict) continue;
for(size_t i = 0; i < len; i++) {
salad[row+i][col] = words[w][i];
}
placed = 1;
}
}
if(placed) {
placedWordsCount++;
}
}
// Leere Felder mit zufälligen Buchstaben befüllen
for(unsigned int i = 0; i < searchFieldLen; i++) {
for(unsigned int j = 0; j < searchFieldLen; j++) {
if (salad[i][j] == EMPTY_CHAR) {
salad[i][j] = 'A' + rand() % 26;
}
}
}
return placedWordsCount; // Rückgabewert wie viele Wörter eingefügt wurden
} }
// Prints the word salad to console // Prints the word salad to console
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
unsigned int searchFieldLen)
{ {
for (int i = 0; i < searchFieldLen; i++) {
} for (int j = 0; j < searchFieldLen; j++) {
printf("%c", salad[i][j]);
printf(" ");
}
printf("\n");
}
}

View File

@ -4,9 +4,42 @@
// TODO: // TODO:
// 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.
/**
* @param file Zeiger auf die geöffnete Datei
* @param words 2D-Array zum Speichern der Wörter
* @param maxWordCount Maximale Anzahl von Wörtern, die eingelesen werden sollen
* @return Anzahl der eingelesenen Wörter
*/
// Read words from file and store in 'words' array // Read words from file and store in 'words' array
// ERLEDIGT
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{ {
if (file == NULL || words == NULL || maxWordCount == 0) {
return 0;
}
int wordCount = 0;
char line[MAX_LINE_LEN];
// Zeilen einlesen
while (wordCount < maxWordCount && fgets(line, MAX_LINE_LEN, file) != NULL) {
// Zeile in Wörter aufteilen (Trennzeichen: Leerzeichen, Komma, Semikolon, Newline)
char *token = strtok(line, " ,;\t\n\r");
while (token != NULL && wordCount < maxWordCount) {
// Prüfen ob Token nicht leer ist
if (strlen(token) > 0 && strlen(token) < MAX_WORD_LEN) {
// Wort kopieren und in Großbuchstaben umwandeln
strcpy(words[wordCount], token);
for (int i = 0; words[wordCount][i] != '\0'; i++) {
words[wordCount][i] = toupper((unsigned char)words[wordCount][i]);
}
wordCount++;
}
// Nächstes Wort
token = strtok(NULL, " ,;\t\n\r");
}
}
return wordCount;
} }

View File

@ -37,10 +37,20 @@ int main(int argc, char *argv[])
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// TODO: // TODO:
// Check if all words were successfully placed // Check if all words were successfully placed
// Start the game if successful if(placedWords == wordCount)
// error message if some words couldn't be placed {
// Start the game if successful
startGame(wordSalad,SALAD_SIZE,words,wordCount,800);
}
else
{
// Error message if some words couldn't be placed
fprintf(stderr, "Error: Only %u out of %u words could be placed in the word salad.\n",
placedWords, wordCount);
exitCode = EXIT_FAILURE;
}
} }
else else
{ {

View File

@ -1,46 +1,51 @@
CC = gcc # --------------------------
CFLAGS = -g -Wall -I$(raylibfolder) # Variablen
LDFLAGS = -lopengl32 -lgdi32 -lwinmm # --------------------------
raylib_folder = ./raylib
unity_folder = ./unity
BINARIES = ./windows BINARIES = ./windows
raylib_folder = ./raylib CC = gcc
unityfolder = ./unity CFLAGS = -g -Wall -I$(raylib_folder)
LDFLAGS = -lopengl32 -lgdi32 -lwinmm
# --------------------------
# initiales Spiel bauen
# --------------------------
wordsalad_initial:
$(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
# --------------------------
# Normales Spiel bauen
# --------------------------
all: 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)
main.o: main.c
$(CC) -c $(CFLAGS) main.c
input.o: input.c
$(CC) -c $(CFLAGS)input.c
game.o: game.c
$(CC) -c $(CFLAGS) game.c
graphicalGame.o: graphicalGame.c
$(CC) -I$(raylib_folder) -c $(CFLAGS) graphicalGame.c
# --------------------------
# Unit Tests
# --------------------------
TEST_BIN = runTests TEST_BIN = runTests
test: input.o game.o unit_tests.c # --------------------------
$(CC) $(CFLAGS) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a # Ziel: Normales Spiel bauen
# --------------------------
all: wordsalad
wordsalad: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
main.o: main.c
$(CC) -c $(CFLAGS) $< -o $@
input.o: input.c
$(CC) -c $(CFLAGS) $< -o $@
game.o: game.c
$(CC) -c $(CFLAGS) $< -o $@
graphicalGame.o: graphicalGame.c
$(CC) -c $(CFLAGS) $< -o $@
# -------------------------- # --------------------------
# Clean # Ziel: Initiales Spiel bauen
# --------------------------
wordsalad_initial:
$(CC) -o $@ $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
# --------------------------
# Ziel: Unit Tests
# --------------------------
test: $(TEST_BIN)
$(TEST_BIN): input.o game.o unit_tests.c
$(CC) $(CFLAGS) -I$(unity_folder) -o $@ input.o game.o unit_tests.c $(BINARIES)/libunity.a
# --------------------------
# Ziel: Aufräumen
# -------------------------- # --------------------------
clean: clean:
del /f *.o *.exe rm -f *.o wordsalad wordsalad_initial $(TEST_BIN)