Compare commits

...
27 Commits
Author SHA1 Message Date
zidanmo99094 ebd16cedec test 2026-10-30 01:09:40 +01:00
zidanmo99094 408e58205a test 2026-10-30 01:08:54 +01:00
zidanmo99094 464c7ff1ad test 2026-10-30 01:05:15 +01:00
zidanmo99094 b78f7ac560 test 2026-10-30 01:03:14 +01:00
zidanmo99094 2ef856d08a test 2026-10-30 01:00:30 +01:00
zidanmo99094 ad2984a808 test 2026-10-30 00:52:24 +01:00
zidanmo99094 0d0ab8ab7e Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/kleinleinta105608/Informatik2-Praktikum-Wortsalat 2026-10-30 00:47:09 +01:00
zidanmo99094 4c76932472 txt 2026-10-27 12:48:56 +01:00
zidanmo99094 ef95895501 txt 2026-10-27 12:48:19 +01:00
kleinleinta105608 6c5710f2f1 Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/kleinleinta105608/Informatik2-Praktikum-Wortsalat 2026-10-27 12:46:42 +01:00
kleinleinta105608 def3034ede Hilfsfunktion in input.c 2026-10-27 12:46:37 +01:00
zidanmo99094 fb4211872e text 2026-10-27 12:37:21 +01:00
zidanmo99094 70c6635991 text 2026-10-27 12:24:34 +01:00
zidanmo99094 213103dad0 text 2026-10-27 12:06:41 +01:00
kleinleinta105608 c3e875f493 Spielinitialisierung in main.c und Makefile Target wordsalad_myversion hinzugefügt 2026-10-26 00:49:47 +01:00
kleinleinta105608 fbd986c66f Wörter geändert 2026-10-25 00:40:54 +02:00
zidanmo99094 2100c8da2c Wolf hinzugefuegt 2026-10-22 16:02:48 +02:00
zidanmo99094 1ae5e39309 Merge-Konflikt gelöst 2026-10-22 15:56:10 +02:00
zidanmo99094 a297e25d94 test 2026-10-22 15:44:19 +02:00
zidanmo99094 df5c3e2ed0 test 2026-10-21 20:09:50 +02:00
zidanmo99094 49e4f22a22 test 2026-10-21 19:43:39 +02:00
zidanmo99094 f1fad264c8 test 2026-10-20 12:42:25 +02:00
kleinleinta105608 977f80eb24 Versuch 2026-10-20 12:29:22 +02:00
Anja Freudenreich 450697aac9 updating repo 2026-10-20 12:12:50 +02:00
kleinleinta105608 302c684558 Test 2026-10-20 11:52:52 +02:00
kleinleinta105608 5ef39bbddd Test2 2026-10-20 01:33:00 +02:00
kleinleinta105608 2869474747 Test 2026-10-13 12:43:04 +02:00
9 changed files with 94 additions and 7 deletions

No files matched your search

+58 -5
View File
@@ -6,12 +6,65 @@
#define MAX_RAND_TRIES_PER_WORD 10 #define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0 #define EMPTY_CHAR 0
//TODO: Spiellogik implementieren:
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
* 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 wordCount, char words[][100], unsigned int seed)
{ {
// 1. Zufallsgenerator für deterministische Unit-Tests initialisieren
srand(seed);
// 2. Spielfeld initialisieren (memset füllt das gesamte 2D-Array sehr effizient mit EMPTY_CHAR)
memset(salad, EMPTY_CHAR, MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN);
int placedWordsCount = 0;
// 3. Jedes Wort aus der Wörterliste platzieren
for (unsigned int i = 0; i < wordCount; i++) {
int len = (int)strlen(words[i]);
if (len == 0 || len > MAX_SEARCH_FIELD_LEN) continue;
// Versuche bis zu MAX_RAND_TRIES_PER_WORD Mal, eine freie Position zu finden
for (int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD; attempt++) {
// Richtung und Deltas bestimmen (is_vert: 1=Vertikal, 0=Horizontal)
int is_vert = rand() % 2;
int dr = is_vert; // Zeilensprung (Delta Row): 1 wenn vertikal, sonst 0
int dc = !is_vert; // Spaltensprung (Delta Col): 1 wenn horizontal, sonst 0
// Startposition berechnen (verhindert automatisch Out-of-Bounds Fehler)
int row = rand() % (MAX_SEARCH_FIELD_LEN - (is_vert ? len - 1 : 0));
int col = rand() % (MAX_SEARCH_FIELD_LEN - (is_vert ? 0 : len - 1));
// Kollisionsprüfung
int canPlace = 1;
for (int k = 0; k < len; k++) {
char current = salad[row + k * dr][col + k * dc];
// Feld muss noch leer sein oder exakt den gleichen Buchstaben enthalten (Überschneidung)
if (current != EMPTY_CHAR && current != words[i][k]) {
canPlace = 0;
break;
}
}
// Wenn die Position gültig ist, Buchstaben eintragen
if (canPlace) {
for (int k = 0; k < len; k++) {
salad[row + k * dr][col + k * dc] = words[i][k];
}
placedWordsCount++;
break; // Erfolgreich platziert -> Schleife abbrechen, nächstes Wort verarbeiten
}
}
}
// 4. Verbleibende leere Felder mit Zufallsbuchstaben 'A'-'Z' auffüllen
for (int r = 0; r < MAX_SEARCH_FIELD_LEN; r++) {
for (int c = 0; c < MAX_SEARCH_FIELD_LEN; c++) {
if (salad[r][c] == EMPTY_CHAR) {
salad[r][c] = 'A' + (rand() % 26);
}
}
}
return placedWordsCount;
} }
+1 -1
View File
@@ -5,6 +5,6 @@
#define MAX_SEARCH_FIELD_LEN 100 #define MAX_SEARCH_FIELD_LEN 100
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 wordCount, char words[][100], unsigned int seed);
#endif #endif
+14
View File
@@ -4,6 +4,20 @@
// 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.
char* readSingleWord(FILE *file, char *destination, int maxLen)
{
char buffer[256]; // Zwischenspeicher zum einlesen
if (fgets(buffer, sizeof(buffer), file) != NULL)
{
buffer[strcspn(buffer, "\r\n")] = '\0'; // Entfernt Umbrüche
strncpy(destination, buffer, maxLen - 1);
destination[maxLen - 1] = '\0'; // Zwingendes Ende des C-Strings setzen, verhindert Pufferüberlauf
return destination; //Rückgabe bei Erfolg
}
return NULL; //Rückgabe nur bei Dateiende
}
// 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)
+10 -1
View File
@@ -6,6 +6,7 @@
#define MAX_NUMBER_OF_WORDS 100 #define MAX_NUMBER_OF_WORDS 100
#define SALAD_SIZE 20 #define SALAD_SIZE 20
#define WINDOW_WIDTH 800 //Breite Spielfenster 800 Pixel
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@@ -36,10 +37,18 @@ 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: erledigt
// 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 (placedWords == wordCount) //wenn alle Wörter erfolgreicht plaziert sind
{
startGame(wordSalad, SALAD_SIZE, words, wordCount, WINDOW_WIDTH); //Startet das Spiel
}
else
{
printf("Fehler: Es konnten nicht alle Wörter plaziert werden\n"); //Gibt Fehlermeldung aus
}
} }
else else
+7
View File
@@ -22,6 +22,13 @@ 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)
# --------------------------
# meine Version
# --------------------------
wordsalad_myversion: main.o graphicalGame.o $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad_myversion main.o graphicalGame.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
# -------------------------- # --------------------------
# Normales Spiel bauen # Normales Spiel bauen
# -------------------------- # --------------------------
BIN
View File
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
Hund,Katze; Maus
View File
Whitespace-only changes.
+3
View File
@@ -0,0 +1,3 @@
Apfel
Banane
Kiwi