diff --git a/Start_Windows/game.c b/Start_Windows/game.c index d8cc133..20b2a46 100644 --- a/Start_Windows/game.c +++ b/Start_Windows/game.c @@ -1,23 +1,42 @@ -#include "game.h" -#include -#include -#include +#include "game.h" // Einbindung der Header-Datei mit Funktionsdeklarationen und Konstanten +#include // Für die Initialisierung des Zufallszahlengenerators +#include // Für rand(), srand() und Speicherfunktionen +#include // Für strlen() zur Ermittlung der Wortlänge +#include // Für printf() in showWordSalad -#define MAX_RAND_TRIES_PER_WORD 10 -#define EMPTY_CHAR 0 +#define MAX_RAND_TRIES_PER_WORD 10 // Maximale Versuche, ein Wort zufällig zu platzieren +#define EMPTY_CHAR 0 // Kennzeichnung für ein leeres Feld im Spielfeld -//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 +// Hauptfunktion zur Erstellung des Wortsalats int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount) { + srand(time(NULL)); // Initialisiert den Zufallsgenerator mit der aktuellen Uhrzeit + + // Setzt alle Felder im Spielfeld auf EMPTY_CHAR (also leer) + for (unsigned int i = 0; i < searchFieldLen; i++) + for (unsigned int j = 0; j < searchFieldLen; j++) + salad[i][j] = EMPTY_CHAR; + + // Schleife über alle Wörter, die platziert werden sollen + for (unsigned int w = 0; w < wordCount; w++) { + const char* word = words[w]; // Zeiger auf das aktuelle Wort + size_t len = strlen(word); // Länge des aktuellen Wortes + int placed = 0; // Flag, ob das Wort erfolgreich platziert wurde + + // Versuche das Wort bis zu MAX_RAND_TRIES_PER_WORD-mal zu platzieren + for (int tries = 0; tries < MAX_RAND_TRIES_PER_WORD && !placed; tries++) { + int dir = rand() % 2; // Zufällige Richtung: 0 = horizontal, 1 = vertikal + int row = rand() % searchFieldLen; // Zufällige Zeile -} // Prints the word salad to console void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) { - -} + // [NEU] Ausgabe des Gitters + for (unsigned int i = 0; i < searchFieldLen; i++) { + for (unsigned int j = 0; j < searchFieldLen; j++) { + printf("%c ", salad[i][j]); + } + printf("\n"); + } +} \ No newline at end of file diff --git a/Start_Windows/graphicalGame.c b/Start_Windows/graphicalGame.c index fc648b6..3b95e29 100644 --- a/Start_Windows/graphicalGame.c +++ b/Start_Windows/graphicalGame.c @@ -66,8 +66,27 @@ typedef struct // Creates a helper message to guide the user static HelperMessage createHelperMessage(unsigned int screenWidth) { - const char *text = "Please search below for the words located at the bottom \nand draw a line exactly on the desired characters ..."; - HelperMessage msg = {"", {0, 0}, {screenWidth, 0}, 18}; + // Der Hilfetext, der dem Spieler angezeigt wird, um das Spielprinzip zu erklären + const char *text = "Please search below for the words located at the bottom \n" + "and draw a line exactly on the desired characters ..."; + + // Initialisiert eine HelperMessage-Struktur: + // - text: der Hinweistext + // - start: Startposition des Textes (x=0, y=0) + // - end: Endposition des Textes (x=screenWidth, y=0) – also über die gesamte Breite + // - fontSize: Schriftgröße des Textes (hier: 18) + HelperMessage msg = { "", {0, 0}, {screenWidth, 0}, 18 }; + + // Kopiert den Hinweistext in das msg.text-Feld (sicher mit strncpy) + strncpy(msg.text, text, sizeof(msg.text) - 1); + + // Stellt sicher, dass der Text nullterminiert ist + msg.text[sizeof(msg.text) - 1] = '\0'; + + // Gibt die fertige HelperMessage zurück + return msg; +} +`` // Copy text into msg, ensuring does not exceed max length strncpy(msg.text, text, MAX_MESSAGE_LEN);