generated from freudenreichan/info2Praktikum-Wortsalat
Compare commits
2 Commits
20465e1dc2
...
249298afc6
| Author | SHA1 | Date | |
|---|---|---|---|
| 249298afc6 | |||
| 6d8371d487 |
@ -17,12 +17,13 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
int addedWords = 0;
|
||||
int attempts = 0; //Anzahl an Versuchen ein Wort hinzuzufügen
|
||||
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;
|
||||
srand(time(NULL));
|
||||
|
||||
for (int i = 0; i < searchFieldLen; i++) {
|
||||
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++) {
|
||||
@ -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) {
|
||||
int direction = rand() % 2;// 0 Horizontal, 1 Vertikal
|
||||
if (direction == 0) {
|
||||
int collumn = rand() % searchFieldLen;
|
||||
int row = rand() % searchFieldLen;
|
||||
int spalte = rand() % searchFieldLen;
|
||||
int reihe = rand() % searchFieldLen;
|
||||
for (int j = 0; j < wordLength; j++)
|
||||
{
|
||||
if (salad[row][collumn+j] != EMPTY_CHAR) {space = 0; break;}
|
||||
//Prüfen ob das Wort ein bereits vorhandenes Wort überspeichern würde
|
||||
if (salad[reihe][spalte+j] != '.') //Prüfen ob das Wort ein bereits vorhandenes Wort überspeichern würde
|
||||
{
|
||||
space = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if ((collumn + wordLength >= searchFieldLen-1) || (space == 0)) {attempts++;}
|
||||
//Prüfen ob Wort an der Stelle (Zeile, Spalte) in das Array passt
|
||||
else {for (int j = 0; j < wordLength; j++)
|
||||
if ((spalte + wordLength >= searchFieldLen-1) || (space == 1))
|
||||
{
|
||||
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;
|
||||
addedWords++;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (direction == 1) {// Vertikal funktioniert analog zu horizontal
|
||||
int collumn = rand() % searchFieldLen;
|
||||
int row = rand() % searchFieldLen;
|
||||
else if (direction == 1) // Vertikal
|
||||
{
|
||||
int spalte = rand() % searchFieldLen;
|
||||
int reihe = rand() % searchFieldLen;
|
||||
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++;}
|
||||
else {
|
||||
if ((reihe + wordLength >= searchFieldLen-1) || (space == 1))
|
||||
{
|
||||
attempts++;
|
||||
}
|
||||
|
||||
|
||||
else
|
||||
{
|
||||
for (int j = 0; j < wordLength; 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;
|
||||
addedWords++;
|
||||
}
|
||||
}
|
||||
space = 1;
|
||||
}
|
||||
space = 0;
|
||||
}
|
||||
attempts = 0;
|
||||
added = 0;
|
||||
|
||||
}
|
||||
for (int i = 0; i < searchFieldLen; i++) {
|
||||
for (int i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return addedWords;
|
||||
|
||||
BIN
Start_Windows/game.o
Normal file
BIN
Start_Windows/game.o
Normal file
Binary file not shown.
BIN
Start_Windows/input.o
Normal file
BIN
Start_Windows/input.o
Normal file
Binary file not shown.
@ -46,7 +46,7 @@ int main(int argc, char *argv[])
|
||||
else
|
||||
{
|
||||
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
|
||||
// error message if some words couldn't be placed
|
||||
|
||||
BIN
Start_Windows/runTests2.exe
Normal file
BIN
Start_Windows/runTests2.exe
Normal file
Binary file not shown.
@ -1 +0,0 @@
|
||||
Hund,Katze; Maus
|
||||
@ -1,3 +0,0 @@
|
||||
Apfel
|
||||
Banane
|
||||
Kiwi
|
||||
Loading…
x
Reference in New Issue
Block a user