Compare commits

...
17 Commits
Author SHA1 Message Date
hruschkajo103995 dda045fee3 Clean Code 2026-11-04 12:59:00 +01:00
hruschkajo103995 cf2e2ae7aa Clean Code 2026-11-04 12:56:46 +01:00
hruschkajo103995 9f17181f9e clean Code 2026-11-04 12:18:53 +01:00
hruschkajo103995 add999961f Änderung Vektoren 2026-11-03 09:03:13 +01:00
Vorname Nachname 07e7ea5d59 Funktioniert. Ein Test nicht bestanden. Genauere Fehlermeldungen fehlen 2026-10-30 17:59:45 +01:00
hruschkajo103995 c2d35dfe89 Entfernen von doppelter else func 2026-10-28 22:20:01 +01:00
hruschkajo103995 6340b63273 Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/dellma103752/Wortsalat 2026-10-28 17:11:12 +01:00
hruschkajo103995 f81b98bc1c finished Programm 2026-10-28 17:10:44 +01:00
Vorname Nachname 2368d5aa38 added time.h 2026-10-28 16:25:06 +01:00
Vorname Nachname cbfd7d5071 Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/dellma103752/Wortsalat 2026-10-28 16:02:46 +01:00
Vorname Nachname b55d0a22e6 Implement game.c 2026-10-28 15:58:37 +01:00
hruschkajo103995 9e22ee3299 Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/dellma103752/Wortsalat 2026-10-28 15:13:28 +01:00
hruschkajo103995 54d2b81fae Delete Hallo Maxi 2026-10-28 14:59:47 +01:00
hruschkajo103995 ae1adadfee Implement readWords 2026-10-28 14:55:45 +01:00
Vorname Nachname 7bd095a2bb tests entfernt 2026-10-22 11:12:36 +02:00
hruschkajo103995 96082d1781 Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/dellma103752/Wortsalat 2026-10-22 10:52:48 +02:00
hruschkajo103995 8bf87d00ed Test 2026-10-22 10:51:45 +02:00
5 changed files with 161 additions and 23 deletions

No files matched your search

+111 -10
View File
@@ -1,17 +1,118 @@
#include "game.h"
#include <time.h>
#include <stdlib.h>
#include <string.h>
#define MAX_RAND_TRIES_PER_WORD 10
#define MAX_ATTEMPTS 10
#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
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
{
//das hier ist ein Test von dem Repository du Lausebube
HORIZONTAL,
VERTICAL
} Direction;
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 placedWords = 0;
/* Alle Felder initialisieren */
for (unsigned int i = 0; i < searchFieldLen; i++)
{
for (unsigned int j = 0; j < searchFieldLen; j++)
{
salad[i][j] = EMPTY_CHAR;
}
}
// Richtungsvektoren
int dx[] = {1, 0};
int dy[] = {0, 1};
// Alle Woerter durchlaufen
for (unsigned int w = 0; w < wordCount; w++)
{
size_t wordLen = strlen(words[w]);
//Leere oder zu lange Woerter ueberspringen
if (wordLen == 0 || wordLen > searchFieldLen)
{
continue;
}
int placed = 0;
int attempts = 0;
while (!placed && attempts < MAX_ATTEMPTS)
{
attempts++;
/* Zufallsrichtung bestimmen */
Direction dir = rand() % 2;
unsigned int Zeile;
unsigned int Spalte;
/* Zufallsposition so waehlen, dass das Wort hineinpasst */
if (dir == HORIZONTAL)
{
Zeile = rand() % searchFieldLen;
Spalte = rand() % (searchFieldLen - wordLen + 1);
}
else
{
Zeile = rand() % (searchFieldLen - wordLen + 1);
Spalte = rand() % searchFieldLen;
}
int collision = 0;
// Pruefen, ob die Position geeignet ist (cillision mit anderen Wörtern)
for (size_t i = 0; i < wordLen; i++)
{
unsigned int z = Zeile + dy[dir] * i;
unsigned int s = Spalte + dx[dir] * i;
char letter = words[w][i];
if (salad[z][s] != EMPTY_CHAR &&
salad[z][s] != letter)
{
collision = 1;
break;
}
}
// Wenn keine collision besteht wort eintragen
if (!collision)
{
for (size_t i = 0; i < wordLen; i++)
{
unsigned int z = Zeile + dy[dir] * i;
unsigned int s = Spalte + dx[dir] * i;
salad[z][s] = words[w][i];
}
placed = 1;
placedWords++;
}
}
}
// Leere Felder mit zufaelligen Buchstaben fuellen
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);// 26 Buchstaben insgesammt
}
}
}
return placedWords;
}
+1
View File
@@ -7,6 +7,7 @@
#define MAX_MESSAGE_LEN 256
#define MAX_SOLUTION_WORD_LEN 16
typedef struct
{
Vector2 startPosition;
+37 -3
View File
@@ -5,8 +5,42 @@
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
// Read words from file and store in 'words'
int readWords(FILE *file, char words[][MAX_WORD_LEN],
unsigned int maxWordCount)
{
if (file == NULL) {
return 0;
}
char line[MAX_LINE_LEN];
unsigned int wordCount = 0;
while (wordCount < maxWordCount &&
fgets(line, sizeof(line), file) != NULL) {
char *word = strtok(line, " ,;\n\t\r");
while (word != NULL && wordCount < maxWordCount)
{
strncpy(words[wordCount], word, MAX_WORD_LEN - 1);
words[wordCount][MAX_WORD_LEN - 1] = '\0';
unsigned int i = 0;
while (words[wordCount][i] != '\0') {
words[wordCount][i] =
(char)toupper((unsigned char)words[wordCount][i]);// char davor da toupper einen int wert liefert und einen unsigned char bekommt
i++;
}
wordCount++;
word = strtok(NULL, " ,;\n\t\r");
}
}
return (int)wordCount;
}
+11 -9
View File
@@ -1,24 +1,26 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "input.h"
#include "game.h"
#include <time.h>
#include "graphicalGame.h"
#define MAX_NUMBER_OF_WORDS 100
#define SALAD_SIZE 20
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
int exitCode = EXIT_SUCCESS;
srand(time(NULL)); //Seed für Zufallszahlen
// 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;
}
else
{
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;
@@ -36,11 +38,10 @@ int main(int argc, char *argv[])
// 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
if (placedWords == (int)wordCount)
{
// Alle Wörter wurden erfolgreich platziert
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
}
else
{
@@ -51,4 +52,5 @@ int main(int argc, char *argv[])
}
return exitCode;
}
}
+1 -1
View File
@@ -2,4 +2,4 @@ Yeti,Nessie Werwolf; Vampir
Monster
Hydra;Frankenstein
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
Gespenst, Oger
Gespenst, testesttesttesttes