generated from freudenreichan/info2Praktikum-Wortsalat
game.c Bugfix Startpunkt
This commit is contained in:
parent
b2118b4c24
commit
a5d5cf82b6
@ -17,11 +17,11 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
|
||||
//1. Schritt: Alle Felder mit 0 befüllen
|
||||
int size_word;
|
||||
int placed_words = 0;
|
||||
int placedWords = 0;
|
||||
unsigned int succesfully_placed = 0;
|
||||
unsigned int tries = 0;
|
||||
unsigned int check_direction = 0, check_overlap = 0;
|
||||
int zeile, spalte;
|
||||
int zeile = 0, spalte = 0, len = 0;
|
||||
|
||||
for(int m = 0; m < searchFieldLen; m++) //m Zeilen
|
||||
{
|
||||
@ -34,7 +34,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
// 2. Schritt: Prüfen ob Wort in Array geschrieben darf
|
||||
for(int num_words = 0; num_words < wordCount && num_words < searchFieldLen; num_words++) //eingelesen Wörter zählen
|
||||
{
|
||||
size_t len = strlen(words[num_words]); //Größe des Wortes ermitteln
|
||||
len = strlen(words[num_words]); //Größe des Wortes ermitteln
|
||||
|
||||
if (len < searchFieldLen)
|
||||
return -1; //ERROR, falls Wort größer als Größe des Feldes (unnötig, da bei worteingabe bereits überprüft)
|
||||
@ -45,30 +45,19 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
int direction = rand() % 2; // 0 = VERTIKAL, 1 = HORIZONTAL
|
||||
|
||||
// zufälliger Startpunkt, Startkoordinaten
|
||||
for(int i = 0; i < wordCount; i++)
|
||||
{
|
||||
if (direction == 0) // 0 = VERTIKAL -> Spalte egal
|
||||
{
|
||||
for(int j = 0; j < len; j++)
|
||||
{
|
||||
zeile = rand() % (searchFieldLen - len);
|
||||
spalte = rand() % (searchFieldLen);
|
||||
salad[zeile][spalte] = words[j];
|
||||
check_direction = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (direction == 1) // 1 = HORIZONTAL -> Zeile egal
|
||||
{
|
||||
for(int k = 0; k < len; k++)
|
||||
{
|
||||
int zeile = rand() % (searchFieldLen);
|
||||
int spalte = rand() % (searchFieldLen - len);
|
||||
salad[zeile][spalte] = words[k];
|
||||
check_direction = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Prüfen auf Überlappung
|
||||
for(int i_overlap = 0; i_overlap < len; i_overlap++)
|
||||
@ -95,19 +84,19 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
if (direction == 0) // 0 = VERTIKAL
|
||||
{
|
||||
salad[zeile + i_set][spalte] = words[num_words][i_set];
|
||||
placed_words++;
|
||||
placedWords++;
|
||||
}
|
||||
|
||||
if (direction == 1) // 1 = HORIZONTAL
|
||||
{
|
||||
salad[zeile][spalte + i_set] = words[num_words][i_set];
|
||||
placed_words++;
|
||||
placedWords++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return placed_words; //platzierte Wörter zurückgeben
|
||||
}
|
||||
return placedWords; //platzierte Wörter zurückgeben
|
||||
}
|
||||
|
||||
// Prints the word salad to console
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user