Compare commits

..

2 Commits

Author SHA1 Message Date
249298afc6 changes to game.c 2025-11-10 14:52:05 +01:00
6d8371d487 test 23 2025-11-10 14:13:31 +01:00
8 changed files with 45 additions and 30 deletions

View File

@ -17,12 +17,13 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
int addedWords = 0; int addedWords = 0;
int attempts = 0; //Anzahl an Versuchen ein Wort hinzuzufügen int attempts = 0; //Anzahl an Versuchen ein Wort hinzuzufügen
int added = 0; //0 Wort nicht hinzugefügt , 1 Wort hinzugefügt int added = 0; //0 Wort nicht hinzugefügt , 1 Wort hinzugefügt
int space = 1; // 0 Wort zu lang, 1 Wort passt an diese Stelle int space = 0; // 1 = Wort zu lang für diese Stelle
unsigned long long wordLength = 0; unsigned long long wordLength = 0;
srand(time(NULL));
for (int i = 0; i < searchFieldLen; i++) { for (int i = 0; i < searchFieldLen; i++) {
for (int j = 0; j < searchFieldLen; j++) { for (int j = 0; j < searchFieldLen; j++) {
salad[i][j] = EMPTY_CHAR; //Füllen des gesamten Arrays mit Nullen salad[i][j] = '.'; //Füllen des gesamten Arrays mit Nullen
} }
} }
for (int i=0; i < wordCount; i++) { for (int i=0; i < wordCount; i++) {
@ -32,33 +33,53 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
while (attempts <= MAX_RAND_TRIES_PER_WORD && added != 1) { while (attempts <= MAX_RAND_TRIES_PER_WORD && added != 1) {
int direction = rand() % 2;// 0 Horizontal, 1 Vertikal int direction = rand() % 2;// 0 Horizontal, 1 Vertikal
if (direction == 0) { if (direction == 0) {
int collumn = rand() % searchFieldLen; int spalte = rand() % searchFieldLen;
int row = rand() % searchFieldLen; int reihe = rand() % searchFieldLen;
for (int j = 0; j < wordLength; j++) for (int j = 0; j < wordLength; j++)
{ {
if (salad[row][collumn+j] != EMPTY_CHAR) {space = 0; break;} if (salad[reihe][spalte+j] != '.') //Prüfen ob das Wort ein bereits vorhandenes Wort überspeichern würde
//Prüfen ob das Wort ein bereits vorhandenes Wort überspeichern würde {
space = 1;
break;
}
} }
if ((collumn + wordLength >= searchFieldLen-1) || (space == 0)) {attempts++;} if ((spalte + wordLength >= searchFieldLen-1) || (space == 1))
//Prüfen ob Wort an der Stelle (Zeile, Spalte) in das Array passt
else {for (int j = 0; j < wordLength; j++)
{ {
salad[row][collumn+j] = words[i][j]; //Einfügen des Wortes Buchstabe für Buchstabe attempts++;
} }
//Prüfen ob Wort an der Stelle (Zeile, Spalte) in das Array passt
else
{
for (int j = 0; j < wordLength; j++)
{
salad[reihe][spalte+j] = words[i][j]; //Einfügen des Wortes Buchstabe für Buchstabe
}
added=1; added=1;
addedWords++; addedWords++;
}
} }
} else if (direction == 1) // Vertikal
else if (direction == 1) {// Vertikal funktioniert analog zu horizontal {
int collumn = rand() % searchFieldLen; int spalte = rand() % searchFieldLen;
int row = rand() % searchFieldLen; int reihe = rand() % searchFieldLen;
for (int j = 0; j < wordLength; j++) for (int j = 0; j < wordLength; j++)
{ {
if (salad[row+j][collumn] != EMPTY_CHAR) {space = 0; break;} if (salad[reihe+j][spalte] != '.')
{
space = 1;
break;
}
} }
if ((row + wordLength >= searchFieldLen-1) || (space == 0)) {attempts++;} if ((reihe + wordLength >= searchFieldLen-1) || (space == 1))
else { {
attempts++;
}
else
{
for (int j = 0; j < wordLength; j++) for (int j = 0; j < wordLength; j++)
{ {
salad[row+j][collumn] = words[i][j]; salad[row+j][collumn] = words[i][j];
@ -66,21 +87,19 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
added=1; added=1;
addedWords++; addedWords++;
} }
} }
space = 1; space = 0;
} }
attempts = 0; attempts = 0;
added = 0; added = 0;
} }
for (int i = 0; i < searchFieldLen; i++) { for (int i = 0; i < searchFieldLen; i++)
{
for (int j = 0; j < searchFieldLen; j++) { for (int j = 0; j < searchFieldLen; j++) {
if (salad[i][j] == EMPTY_CHAR) if (salad[i][j] == '.')
{ {
salad[i][j] = rand()%('Z'-'A'+1)+'A';//Alle Felder, die noch nicht befüllt sind, werden zufällig befüllt salad[i][j] = rand()%('Z'-'A'+1)+'A';//Alle Felder, die noch nicht befüllt sind, werden zufällig befüllt
} }
} }
} }
return addedWords; return addedWords;

BIN
Start_Windows/game.o Normal file

Binary file not shown.

BIN
Start_Windows/input.o Normal file

Binary file not shown.

View File

@ -46,7 +46,7 @@ int main(int argc, char *argv[])
else else
{ {
exitCode = EXIT_FAILURE; exitCode = EXIT_FAILURE;
printf("Bei der Platzierung ist etwas falsch gelaufen!"); printf("Error. The words couldn't be placed.\n");
} }
// Start the game if successful // Start the game if successful
// error message if some words couldn't be placed // error message if some words couldn't be placed

BIN
Start_Windows/runTests2.exe Normal file

Binary file not shown.

View File

@ -1 +0,0 @@
Hund,Katze; Maus

View File

@ -1,3 +0,0 @@
Apfel
Banane
Kiwi