generated from freudenreichan/info2Praktikum-Wortsalat
Erste Funktion fertig
s Please enter the commit message for your changes. Lines starting
This commit is contained in:
parent
e7d3cc9023
commit
d5539e08b8
@ -19,23 +19,44 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
for (int j = 0; j < searchFieldLen; j++) {
|
||||
salad[i][j] = 'A' + (rand() % 26);
|
||||
}
|
||||
salad[i][j] = 'A' + (rand() % 26);
|
||||
}
|
||||
|
||||
wordCount = sizeof(words) / sizeof(words[0]); //Array das mit der Anzahl der Wörter gefüllt wird
|
||||
//Array das mit der Anzahl der Wörter gefüllt wird
|
||||
int wordOrientation[wordCount];
|
||||
|
||||
for (int w = 0;w < wordCount; w++) { //Randomizer, ob Wort horizontal oder vertikal wird
|
||||
wordOrientation[w] = rand() % 2;
|
||||
for (int w = 0;w < wordCount; w++) { //Randomizer, ob Wort horizontal oder vertikal wird
|
||||
wordOrientation[w] = rand() % 2; //vertikal = 0, horizontal = 1
|
||||
}
|
||||
|
||||
for (int w = 0;w < wordCount; w++) {
|
||||
const char *word = words[w]; //zeiger word zeigt auf Anfang des aktuellen Wortes
|
||||
int wordLen = strlen(word); //Länge des Wortes wird ermittelt
|
||||
int horizontal = wordOrientation[w]; //horizontal bekommt 0 und 1 aus dem array
|
||||
int wordPlaced = 0;
|
||||
|
||||
for (int tries = 0;tries < MAX_RAND_TRIES_PER_WORD && !wordPlaced;tries++) { //Das Wort wird entweder in eine Zeile oder Spalte random plaziert
|
||||
int row = rand() % searchFieldLen;
|
||||
int col = rand() % searchFieldLen;
|
||||
|
||||
|
||||
//for (int w = 0,w < wordCount, w++) {
|
||||
// const char *words = words[w];
|
||||
//int wordlen = strlen (words);
|
||||
//}
|
||||
if (horizontal) {
|
||||
if (col + wordLen > searchFieldLen) //erst wird überprüft, ob das Wort überlappt
|
||||
continue;
|
||||
for (int i = 0;i < wordLen; i++) { //Wort wird in Spalte geschrieben
|
||||
salad[row][col + i] = word[i];
|
||||
}
|
||||
wordPlaced = 1;
|
||||
}
|
||||
else {
|
||||
if (row + wordLen > searchFieldLen) //erst wird überprüft, ob das Wort überlappt
|
||||
continue;
|
||||
for (int i = 0;i < wordLen; i++) { //Wort wird in Zeile geschrieben
|
||||
salad[row + i][col] = word[i];
|
||||
}
|
||||
wordPlaced = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Prints the word salad to console
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user