Compare commits

..
39 Commits
Author SHA1 Message Date
zidanmo99094 f732b3edf9 ttt 2026-10-30 15:25:53 +01:00
zidanmo99094 c859d76447 test 2026-10-30 15:24:24 +01:00
zidanmo99094 561fd213b6 test 2026-10-30 15:23:50 +01:00
zidanmo99094 3c43aca7b1 tt 2026-10-30 15:23:00 +01:00
zidanmo99094 49f1a06e02 test 2026-10-30 15:21:29 +01:00
zidanmo99094 2f0857c711 testt 2026-10-30 15:18:54 +01:00
zidanmo99094 b4ee9ae4e4 tt 2026-10-30 15:18:08 +01:00
zidanmo99094 29551521f0 test 2026-10-30 15:11:20 +01:00
zidanmo99094 b9c4545cc0 tst1 2026-10-30 15:08:56 +01:00
zidanmo99094 edf465fd79 tst 2026-10-30 15:07:49 +01:00
zidanmo99094 ae2024266a txt3 2026-10-30 15:02:56 +01:00
zidanmo99094 9c29e702e9 txt2 2026-10-30 15:01:05 +01:00
zidanmo99094 45a30468f7 txt1 2026-10-30 14:58:59 +01:00
zidanmo99094 cb0bbc68de txt 2026-10-30 14:58:09 +01:00
zidanmo99094 580e84491d test 2026-10-30 14:50:36 +01:00
zidanmo99094 b732b3d526 test 2026-10-30 14:46:33 +01:00
zidanmo99094 b6f873833d test 2026-10-30 14:38:27 +01:00
kleinleinta105608 852ae19472 Anpassung input.c nach Unit Tests 2026-10-30 13:58:13 +01:00
kleinleinta105608 9e53289322 Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/kleinleinta105608/Informatik2-Praktikum-Wortsalat 2026-10-30 13:00:03 +01:00
kleinleinta105608 361e5ddaca Hauptfunktion und Anpassung Hilfsfunktion in input.c 2026-10-30 12:59:47 +01:00
zidanmo99094 825aa17877 test 2026-10-30 01:13:17 +01:00
zidanmo99094 fd8b643197 test 2026-10-30 01:12:27 +01:00
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
7 changed files with 161 additions and 17 deletions

No files matched your search

+64 -8
View File
@@ -1,17 +1,73 @@
#include "game.h" #include "game.h"
#include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h>
#include <ctype.h>
#define MAX_RAND_TRIES_PER_WORD 10 #define MAX_RAND_TRIES_PER_WORD 1000
#define EMPTY_CHAR 0 #define EMPTY_CHAR 0
//TODO: Spiellogik implementieren: int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int wordCount, char words[][MAX_WORD_LEN], unsigned int gridSize)
/* * 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
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
{ {
// 1. Spielfeld zurücksetzen
memset(salad, EMPTY_CHAR, MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN);
int placedWordsCount = 0;
// 2. Wörter platzieren
for (unsigned int i = 0; i < wordCount; i++) {
size_t len = strlen(words[i]);
// Steuerzeichen am Ende entfernen
while (len > 0 && (words[i][len - 1] == '\n' || words[i][len - 1] == '\r' || words[i][len - 1] == ' ' || words[i][len - 1] == '\t')) {
words[i][--len] = '\0';
}
if (len == 0 || len > gridSize) {
continue;
}
for (int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD; attempt++) {
Direction dir = (rand() % 2 == 0) ? DIR_HORIZONTAL : DIR_VERTICAL;
int dr = (dir == DIR_VERTICAL) ? 1 : 0;
int dc = (dir == DIR_HORIZONTAL) ? 1 : 0;
unsigned int maxRow = (dir == DIR_VERTICAL) ? (gridSize - (unsigned int)len + 1) : gridSize;
unsigned int maxCol = (dir == DIR_HORIZONTAL) ? (gridSize - (unsigned int)len + 1) : gridSize;
unsigned int row = (unsigned int)(rand() % maxRow);
unsigned int col = (unsigned int)(rand() % maxCol);
int canPlace = 1;
for (unsigned int k = 0; k < len; k++) {
char current = salad[row + k * dr][col + k * dc];
char wordChar = (char)toupper((unsigned char)words[i][k]);
if (current != EMPTY_CHAR && current != wordChar) {
canPlace = 0;
break;
}
}
if (canPlace) {
for (unsigned int k = 0; k < len; k++) {
salad[row + k * dr][col + k * dc] = (char)toupper((unsigned char)words[i][k]);
}
placedWordsCount++;
break;
}
}
}
// 3. Leere Felder mit Zufallsbuchstaben ('A'-'Z') füllen
for (unsigned int r = 0; r < gridSize; r++) {
for (unsigned int c = 0; c < gridSize; c++) {
if (salad[r][c] == EMPTY_CHAR) {
salad[r][c] = 'A' + (rand() % 26);
}
}
}
return placedWordsCount;
} }
+11 -1
View File
@@ -3,8 +3,18 @@
#include "input.h" #include "input.h"
#ifndef MAX_SEARCH_FIELD_LEN
#define MAX_SEARCH_FIELD_LEN 100 #define MAX_SEARCH_FIELD_LEN 100
#endif
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount); typedef enum {
DIR_HORIZONTAL = 0,
DIR_VERTICAL = 1
} Direction;
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
unsigned int wordCount,
char words[][MAX_WORD_LEN],
unsigned int gridSize);
#endif #endif
+68 -2
View File
@@ -2,11 +2,77 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
// TODO: // TODO: erledigt
// 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];
int ch;
int bufIndex = 0;
// Alle Trennzeichen überspringen, bis ein echter Buchstabe kommt
while ((ch = fgetc(file)) != EOF)
{
// Prüfen der Buchstaben
if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
{
// Wenn Kleinbuchstabe, in Großbuchstabe umwandeln
if (ch >= 'a' && ch <= 'z')
{
ch = ch - 32;
}
buffer[bufIndex] = ch;
bufIndex++;
break;
}
}
if (ch == EOF)
{
return NULL;
}
// Den Rest des Wortes einlesen (bricht bei Kommas, Leerzeichen etc. ab)
while ((ch = fgetc(file)) != EOF && ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')))
{
if (bufIndex < 255)
{
if (ch >= 'a' && ch <= 'z')
{
ch = ch - 32;
}
buffer[bufIndex] = ch;
bufIndex++;
}
}
// Zwischenspeicher abschließen
buffer[bufIndex] = '\0';
// Sicheres Kopieren in das Ziel-Array
strncpy(destination, buffer, maxLen - 1);
destination[maxLen - 1] = '\0';
return destination;
}
// 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)
{ {
unsigned int count = 0;
// Schleife läuft, solange noch Platz im Array ist
while (count < maxWordCount)
{
if (readSingleWord(file, words[count], MAX_WORD_LEN) != NULL)
{
if (strlen(words[count]) > 0) // Prüfen, ob das Wort nicht leer ist
{
count++; // nächstes Wort
}
}
else
{
break; // Bei Dateiende wird die Schleife abgebrochen
}
}
return count;
} }
+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 -5
View File
@@ -2,8 +2,4 @@ Yeti,Nessie Werwolf; Vampir
Monster Monster
Hydra;Frankenstein Hydra;Frankenstein
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
Gespenst, Oger, hund Gespenst, Oger
hase
nnna, hello, Info2
Gespenst, Oger, Maus
Nour