Compare commits

..
16 Commits
Author SHA1 Message Date
tiewataffoch99039 af4a6848fe Finished Project 2026-10-20 15:51:14 +02:00
tiewataffoch99039 4a20144af9 Implement input.c, game.c and main.c -all unit test passed 2026-10-20 15:25:18 +02:00
tiewataffoch99039 03ff8e655a Implement game initialization in main.c and add Wordsalad_myversion target 2026-10-20 10:47:50 +02:00
Anja Freudenreich 93db739464 updating repo 2026-09-17 14:36:54 +02:00
freudenreichan eaa16ed84c Module fehlerhaft übersetzt. 2025-10-28 09:18:39 +00:00
freudenreichan 32a6133d18 Merge pull request 'extend-unittests' (#3) from schroederen/info2Praktikum-Wortsalat:extend-unittests into main
Reviewed-on: freudenreichan/info2Praktikum-Wortsalat#3
2025-10-21 13:45:46 +00:00
freudenreichan 39e8380916 Merge pull request 'fix-makefiles' (#2) from schroederen/info2Praktikum-Wortsalat:fix-makefiles into main
Reviewed-on: freudenreichan/info2Praktikum-Wortsalat#2
2025-10-21 13:45:24 +00:00
schroederen ffaed665b9 Unittest für das Platzieren aller Wörter hinzugefügt. 2025-10-21 15:24:07 +02:00
schroederen e20bf82c19 Makefile angepasst 2025-10-21 11:45:37 +02:00
schroederen 1ed03a3444 Windows Makefile korrigiert 2025-10-21 11:24:14 +02:00
schroederen 6b435cf82d Fix makefiles. 2025-10-20 14:39:05 +02:00
schroederen 92c0ab2c28 macOS lib Ordner umbenannt (x86_64) 2025-10-16 13:48:45 +02:00
freudenreichan 7c25208a58 Typo korrigiert 2025-10-10 12:33:43 +00:00
freudenreichan 78b6fc32ff raylib für MinGW 2025-09-28 08:11:52 +00:00
freudenreichan a04fe8aa39 Start_Linux/wordsalad_initial gelöscht 2025-09-25 09:11:38 +00:00
Anja Freudenreich d075414c0a adding content 2025-09-25 11:11:07 +02:00
7 changed files with 155 additions and 0 deletions

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
# Wortsalat - Praktikum Informatik 2
Ein klassisches Wortsuchspiel, bei dem Wörter aus einer Textdatei zufällig horizontal oder vertikal in einem Gitter platziert werden. Der Spieler muss diese Wörter im Spielfeld finden.
## Bedienung & Kompilierung
1. **Eigenes Target bauen:**
make wordsalad_myversion
+84
View File
@@ -13,5 +13,89 @@
// 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)
{
if (salad == NULL || words == NULL || searchFieldLen == 0){
return 0;
}
//1. Spielfeld mit Nullen (Leerzeichen/leeren Zellen) Vorinitialisieren
for(unsigned int i = 0; i< searchFieldLen; i++){
for(unsigned int j = 0; j < searchFieldLen; j++)
{
salad[i][j] = '\0';
}
}
//Zufallszahlengenerator initialisation
srand((unsigned int)time(NULL));
unsigned int sucessfullyPlaced = 0;
//2. Jedes Wort einzeln im Gitter Plazieren
for(unsigned int w = 0; w < wordCount; w++)
{
int len = (int)strlen(words[w]);
if((unsigned int)len > searchFieldLen){
//wort ist zu lang für das Suchfeld
continue;
}
int placed = 0;
int attempts = 0;
//MAximum Versuche, um eine passende Position zu finden, um ENdlosshleifen zu vermeiden
while(!placed && attempts < 5000){
attempts++;
int direction = rand() %2; // 0 = horizontal, 1 = vertical
int row = 0;
int col = 0;
if(direction == 0) // horizontal
{
row = rand() % searchFieldLen;
col = rand() % (searchFieldLen - len + 1);
}
else // vertical
{
row = rand() % (searchFieldLen - len + 1);
col = rand() % searchFieldLen;
}
// KOllisionsprüfung
int collision = 0;
for(int i = 0; i < len; i++)
{
int r = row + (direction == 1? i : 0);
int c = col + (direction == 0 ? i : 0);
if(salad[r][c] != '\0' && salad[r][c] != words[w][i]){
collision = 1;
break;
}
}
//wenn keine kollision vorliegt, Wort ins Gitter schreiben
if(!collision){
for(int i = 0; i < len; i++){
int r = row + (direction == 1 ? i : 0);
int c = col + (direction == 0 ? i : 0);
salad[r][c] = words[w][i];
}
sucessfullyPlaced++;
placed = 1;
}
}
}
// Alle restlichen (leeren) Felder mit zufäalligen Großbuchstaben ('A' - 'Z') auffullen
for(unsigned int i = 0; i < searchFieldLen; i++){
for(unsigned int j = 0; j < searchFieldLen; j++)
{
if(salad[i][j] == '\0'){
salad[i][j] = (char)('A' + (rand() % 26));
}
}
}
return (int)sucessfullyPlaced;
}
+43
View File
@@ -4,9 +4,52 @@
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
// HIlfsfunktion: LIest das nächste Wort(Tocken) aus der Datei und gibt es als C-String züruck
char* readNextWord(FILE *file, char *lineBuffer, unsigned int maxLineLen, int *isNewLineNeeded){
const char *delimiters = " ,;\t\r\n";
char *token = NULL;
//Falls wir schon in einer Zeile sind, Versuche das nächste Word daraus zu holen
if(!(*isNewLineNeeded)){
token = strtok(NULL, delimiters);
}
while (token == NULL)
{
if(fgets(lineBuffer, maxLineLen, file) == NULL)
{
// Dateiend (EOF) erreicht
return NULL;
}
token = strtok(lineBuffer, delimiters);
*isNewLineNeeded = 0;
}
return token;
}
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
if(file == NULL || words == NULL || maxWordCount == 0){
return 0;
}
char lineBuffer[MAX_LINE_LEN];
int isNewLineNeeded = 1;
unsigned int count = 0;
char *word = NULL;
while(count < maxWordCount && (word = readNextWord(file, lineBuffer, MAX_LINE_LEN, &isNewLineNeeded)) != NULL)
{
//Sicher kopieren mit strncpy und Nulltermination garantieren
strncpy(words[count], word, MAX_WORD_LEN - 1);
words[count][MAX_WORD_LEN - 1] = '\0';
//changing all leter to caplogs
for(unsigned int i = 0; words[count][i] != '\0'; i++){
words[count][i] = (char)toupper((unsigned char)words[count][i]);
}
count++;
}
return (int)count;
}
+8
View File
@@ -40,6 +40,14 @@ int main(int argc, char *argv[])
// Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed
if(placedWords == wordCount){
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
}
else{
fprintf(stderr, "Error: Could not place all worlds into the world salad (%u of %u placed).\n", placedWords, wordCount);
exitCode = EXIT_FAILURE;
}
}
else
+11
View File
@@ -23,6 +23,17 @@ wordsalad_initial:
$(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
# --------------------------
#---------------------------
# My version
#-----------------------
#wordsalad_myversion: main.o
# $(CC) $(CFLAGS) -o wordsalad_myversion main.o -L. $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
#-----------------------------
#Building myversion
#------------------------
wordsalad_myversion: main.o graphicalGame.o
$(CC) $(CFLAGS) -o wordsalad_myversion main.o graphicalGame.o -L. $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
# Normales Spiel bauen
# --------------------------
wordsalad: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.