Compare commits

...
10 Commits
Author SHA1 Message Date
MiraSchütz b5d6a5d1b3 main.c verändert 2026-10-26 17:51:49 +01:00
MiraSchütz a0bd61a872 game.c verändert 2026-10-26 17:48:56 +01:00
roesselid103915 556a83c9af nach test2 korrigiert game.c 2026-10-26 09:16:27 +01:00
roesselid103915 d2357c9040 nach test2 korrigiert game.c 2026-10-26 09:15:19 +01:00
roesselid103915 69d0c0ee4d nach tests korrigiert game.c 2026-10-26 09:09:13 +01:00
roesselid103915 075a2ad50c korrigiert game.c 2026-10-26 08:42:06 +01:00
roesselid103915 b0b70e371d fertig game.c 2026-10-26 08:31:30 +01:00
roesselid103915 7df641beb3 main.c fertig 2026-10-26 08:30:18 +01:00
roesselid103915 88575ba8bf fertig game.c 2026-10-26 08:07:43 +01:00
roesselid103915 f1fdbb5424 game.c bearbeitet 2026-10-21 15:07:56 +02:00
2 changed files with 77 additions and 11 deletions

No files matched your search

+72 -10
View File
@@ -11,18 +11,80 @@
/* * 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) {
int placedWords = 0;
srand(time(NULL));
char bustaben[] = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
char zufall = bustaben[rand() % 26];
printf("Zufaelliger Bustabe: %c\n", zufall);
const char words[15][MAX_WORD_LEN] = "Yeti,Nessie,Werwolf,Vampir,Monster,Hydra,Frankenstein,Dracula,KingKong,Gremlin,Kobold,Hexe,Poltergeist,Gespenst,Oge";
for (unsigned int r=0; r < searchFieldLen; r++) {
for (unsigned int c =0; c <searchFieldLen; c++) {
salad[r][c] = EMPTY_CHAR;
}
}
return 0;
}
//Wörter plazieren
for (unsigned int w = 0; w< wordCount; w++) {
int wordLen = strlen(words[w]);
if (wordLen > searchFieldLen) {
continue;
}
int tries = 0;
int placed = 0;
while (!placed && tries < MAX_RAND_TRIES_PER_WORD) {
int direction = rand() % 2;
int row;
int col;
int fits = 1;
if (direction == 0) {
row = rand() % searchFieldLen;
col = rand() % (searchFieldLen - wordLen +1);
for (int i = 0; i< wordLen; i++) {
if (salad[row][col +i] != EMPTY_CHAR) {
fits = 0;
break;
}
}
if (fits) {
for (int i=0; i < wordLen; i++) {
salad[row][col +i] = words[w][i];
}
placed = 1;
placedWords++;
}
}
else {
row = rand() % (searchFieldLen - wordLen +1);
col = rand() % searchFieldLen;
for (int i = 0; i< wordLen; i++) {
if (salad[row+i][col] != EMPTY_CHAR) {
fits = 0;
break;
}
}
if (fits) {
for (int i = 0; i<wordLen; i++) {
salad[row+i][col] = words[w][i];
}
placed = 1;
placedWords++;
}
}
tries++;
}
}
//Rest mit Zufallsbustaben füllen
for (unsigned int r=0; r < searchFieldLen; r++) {
for (int c=0; c < searchFieldLen; c++) {
if (salad[r][c] == EMPTY_CHAR) {
salad[r][c]='A' + rand() % 26;
}
}
}
return placedWords;
}
+5 -1
View File
@@ -40,7 +40,11 @@ int main(int argc, char *argv[])
// Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed
if (placedWords == wordCount){
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
}else {
fprintf(stderr, "Could not open file %s for reading ...\n");
exitCode = EXIT_FAILURE;
}
else
{