Version_1.0.0 Branch
This commit is contained in:
commit
e835244717
@ -1,23 +1,42 @@
|
|||||||
#include "game.h"
|
#include "game.h" // Einbindung der Header-Datei mit Funktionsdeklarationen und Konstanten
|
||||||
#include <time.h>
|
#include <time.h> // Für die Initialisierung des Zufallszahlengenerators
|
||||||
#include <stdlib.h>
|
#include <stdlib.h> // Für rand(), srand() und Speicherfunktionen
|
||||||
#include <string.h>
|
#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 MAX_RAND_TRIES_PER_WORD 10 // Maximale Versuche, ein Wort zufällig zu platzieren
|
||||||
#define EMPTY_CHAR 0
|
#define EMPTY_CHAR 0 // Kennzeichnung für ein leeres Feld im Spielfeld
|
||||||
|
|
||||||
//TODO: Spiellogik implementieren:
|
// Hauptfunktion zur Erstellung des Wortsalats
|
||||||
/* * 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)
|
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
|
// Prints the word salad to console
|
||||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
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,9 +66,28 @@ typedef struct
|
|||||||
// Creates a helper message to guide the user
|
// Creates a helper message to guide the user
|
||||||
static HelperMessage createHelperMessage(unsigned int screenWidth)
|
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 ...";
|
// 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 };
|
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
|
// Copy text into msg, ensuring does not exceed max length
|
||||||
strncpy(msg.text, text, MAX_MESSAGE_LEN);
|
strncpy(msg.text, text, MAX_MESSAGE_LEN);
|
||||||
msg.text[MAX_MESSAGE_LEN-1] = '\0';
|
msg.text[MAX_MESSAGE_LEN-1] = '\0';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user