Version_1.0.0 Branch
This commit is contained in:
commit
e835244717
@ -1,23 +1,42 @@
|
||||
#include "game.h"
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "game.h" // Einbindung der Header-Datei mit Funktionsdeklarationen und Konstanten
|
||||
#include <time.h> // Für die Initialisierung des Zufallszahlengenerators
|
||||
#include <stdlib.h> // Für rand(), srand() und Speicherfunktionen
|
||||
#include <string.h> // Für strlen() zur Ermittlung der Wortlänge
|
||||
#include <stdio.h> // 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");
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user