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
|
//1. Schritt: Alle Felder mit 0 befüllen
|
||||||
int size_word;
|
int size_word;
|
||||||
int placed_words = 0;
|
int placedWords = 0;
|
||||||
unsigned int succesfully_placed = 0;
|
unsigned int succesfully_placed = 0;
|
||||||
unsigned int tries = 0;
|
unsigned int tries = 0;
|
||||||
unsigned int check_direction = 0, check_overlap = 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
|
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
|
// 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
|
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)
|
if (len < searchFieldLen)
|
||||||
return -1; //ERROR, falls Wort größer als Größe des Feldes (unnötig, da bei worteingabe bereits überprüft)
|
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
|
int direction = rand() % 2; // 0 = VERTIKAL, 1 = HORIZONTAL
|
||||||
|
|
||||||
// zufälliger Startpunkt, Startkoordinaten
|
// zufälliger Startpunkt, Startkoordinaten
|
||||||
for(int i = 0; i < wordCount; i++)
|
|
||||||
{
|
|
||||||
if (direction == 0) // 0 = VERTIKAL -> Spalte egal
|
if (direction == 0) // 0 = VERTIKAL -> Spalte egal
|
||||||
{
|
|
||||||
for(int j = 0; j < len; j++)
|
|
||||||
{
|
{
|
||||||
zeile = rand() % (searchFieldLen - len);
|
zeile = rand() % (searchFieldLen - len);
|
||||||
spalte = rand() % (searchFieldLen);
|
spalte = rand() % (searchFieldLen);
|
||||||
salad[zeile][spalte] = words[j];
|
|
||||||
check_direction = 1;
|
check_direction = 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (direction == 1) // 1 = HORIZONTAL -> Zeile egal
|
if (direction == 1) // 1 = HORIZONTAL -> Zeile egal
|
||||||
{
|
|
||||||
for(int k = 0; k < len; k++)
|
|
||||||
{
|
{
|
||||||
int zeile = rand() % (searchFieldLen);
|
int zeile = rand() % (searchFieldLen);
|
||||||
int spalte = rand() % (searchFieldLen - len);
|
int spalte = rand() % (searchFieldLen - len);
|
||||||
salad[zeile][spalte] = words[k];
|
|
||||||
check_direction = 1;
|
check_direction = 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Prüfen auf Überlappung
|
//Prüfen auf Überlappung
|
||||||
for(int i_overlap = 0; i_overlap < len; i_overlap++)
|
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
|
if (direction == 0) // 0 = VERTIKAL
|
||||||
{
|
{
|
||||||
salad[zeile + i_set][spalte] = words[num_words][i_set];
|
salad[zeile + i_set][spalte] = words[num_words][i_set];
|
||||||
placed_words++;
|
placedWords++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (direction == 1) // 1 = HORIZONTAL
|
if (direction == 1) // 1 = HORIZONTAL
|
||||||
{
|
{
|
||||||
salad[zeile][spalte + i_set] = words[num_words][i_set];
|
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
|
// Prints the word salad to console
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user