Format Project

This commit is contained in:
Tobias Linz committed 2026-10-29 16:00:21 +01:00
1 parent 4a7d34044b
commit e94da31756
4 files changed
+33 -39

No files matched your search

+16 -7
View File
@@ -1,14 +1,15 @@
#include "game.h"
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0
int placeWord(const char* word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
int placeWord(const char *word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
int searchFieldLen, int column, int row, int axis);
// Creates the word salad by placing words randomly and filling empty spaces
@@ -19,7 +20,9 @@ int createWordSalad(
unsigned int wordCount)
{
if (searchFieldLen == 0 || searchFieldLen > MAX_SEARCH_FIELD_LEN)
{
return 0;
}
int placedWords = 0;
@@ -27,8 +30,12 @@ int createWordSalad(
// Spielfeld leeren:
for (int x = 0; x < searchFieldLen; x++)
{
for (int y = 0; y < searchFieldLen; y++)
{
salad[x][y] = EMPTY_CHAR;
}
}
// Wörter platzieren
@@ -37,7 +44,9 @@ int createWordSalad(
int wordlenght = strlen(words[w]); // Wortlänge festgelegt
if (wordlenght == 0 || wordlenght > searchFieldLen)
{
continue;
}
for (int attempts = 0;
attempts < MAX_RAND_TRIES_PER_WORD;
@@ -48,7 +57,7 @@ int createWordSalad(
int row = rand() % searchFieldLen;
int column = rand() % searchFieldLen;
int success = placeWord( words[w],wordlenght, salad, searchFieldLen, column, row, axis);
int success = placeWord(words[w], wordlenght, salad, searchFieldLen, column, row, axis);
if (success)
{
@@ -69,12 +78,12 @@ int createWordSalad(
}
}
}
printf("%d placed" ,placedWords);
printf("%d placed", placedWords);
return placedWords;
}
int placeWord(const char* word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
int placeWord(const char *word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
int searchFieldLen, int column, int row, int axis)
{
// Available space check & word collision avoidance
@@ -112,4 +121,4 @@ int placeWord(const char* word, int wordLength, char salad[MAX_SEARCH_FIELD_LEN]
}
return 1;
}
}