Files
Wortsalat/Startcode/game.c
T
2026-10-22 11:23:38 +02:00

39 lines
1.0 KiB
C

#include "game.h"
#include <time.h>
#include <stdlib.h>
#include <string.h>
#define MAX_RAND_TRIES_PER_WORD 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)
{
//Initialisiert den seed für rand()
srand(time(NULL));
int placedWords = 0;
//Iterate over words
unsigned int counter = 0;
while(counter < wordCount){
//load current word
char currentWord[MAX_WORD_LEN] = words[counter];
//try to place a word
int try = 0;
while(try < 10){
int x = rand() % MAX_SEARCH_FIELD_LEN;
int y = rand() % MAX_SEARCH_FIELD_LEN;
try++;
}
}
return placedWords;
}