Compare commits

...

2 Commits

Author SHA1 Message Date
6027c2a061 ausbesserungen aus stunde 2025-11-04 11:20:21 +01:00
ed22736f68 debugging, placeWord noch fehlerhaft 2025-11-04 10:42:35 +01:00
7 changed files with 43 additions and 15 deletions

View File

@ -31,12 +31,28 @@ typedef struct
} wordPosition;
void initializeWordsalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
{
int i = 0;
int j = 0;
for (i = 0; i < searchFieldLen; i++)
{
for (j = 0; j < searchFieldLen; j++)
{
salad[i][j] = '=';
}
}
}
// Choses a random Position for the current Word
wordPosition choserandomPosition(unsigned int searchFieldLen, unsigned int wordLength)
{
wordPosition position = {0, 0, 0};
srand(time(NULL));
//srand(time(NULL));
position.alignment = rand()%(VERTIKAL - HORIZONTAL + 1) + HORIZONTAL;
position.rowOrColumn = rand()%(searchFieldLen);
position.startingCell = rand()%(searchFieldLen - wordLength);
@ -91,22 +107,26 @@ int checkIfPositionIsFree(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]
int placeWord(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], wordPosition position, const char currentWord[], unsigned int currentWordLen, unsigned int serchFieldLen)
{
int i = 0;
int j = 0;
if (position.alignment == HORIZONTAL)
{
for (i = position.startingCell; (i < serchFieldLen) && (i < currentWordLen); i++)
for (i = position.startingCell; (i < serchFieldLen) || (j < currentWordLen); i++)
{
salad[position.rowOrColumn][i] = currentWord[i];
salad[position.rowOrColumn][i] = currentWord[j];
printf("%c",currentWord[j]);
j++;
}
salad[position.rowOrColumn][i] = '\0';
}
else if (position.alignment == VERTIKAL)
{
for (i = position.startingCell; (i < serchFieldLen) && (i < currentWordLen); i++)
for (i = position.startingCell; (i < serchFieldLen) || (j < currentWordLen); i++)
{
salad[i][position.rowOrColumn] = currentWord[i];
salad[i][position.rowOrColumn] = currentWord[j];
printf("%c",currentWord[j]);
j++;
}
salad[i][position.rowOrColumn] = '\0';
}
@ -123,11 +143,9 @@ void placeRandomLetters(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
int j = 0;
srand(time(NULL));
for (i = 0; i < searchFieldLen; i++)
{
for (j = 0; i < searchFieldLen; j++)
for (j = 0; j < searchFieldLen; j++)
{
if ((salad[i][j] < 'A') || (salad[i][j] > 'z') || ((salad[i][j] < 'a') && (salad[i][j] > 'Z')))
{
@ -149,9 +167,13 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
char currentWord[MAX_WORD_LEN];
wordPosition currentWordPosition = {0,0,0};
srand(time(NULL));
initializeWordsalad(salad, searchFieldLen);
showWordSalad(salad, searchFieldLen);
for (i = 1; i <= wordCount; i++)
{
j = 0;
do
{
currentWordPosition = choserandomPosition(searchFieldLen, strlen(words[i]));
@ -161,11 +183,15 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
if (positionFound)
{
strcpy(currentWord, "\0");
strcpy(currentWord, words[i-1]);
printf("%d, %d, %d \n", currentWordPosition.alignment, currentWordPosition.rowOrColumn, currentWordPosition.startingCell);
printf("%s\n", currentWord);
placedWords += placeWord(salad, currentWordPosition, currentWord, strlen(currentWord), searchFieldLen);
}
}
showWordSalad(salad, searchFieldLen);
placeRandomLetters(salad, searchFieldLen);
@ -182,7 +208,7 @@ void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
for (i = 0; i < searchFieldLen; i++)
{
for (j = 0; i < searchFieldLen; j++)
for (j = 0; j < searchFieldLen; j++)
{
printf("%c", salad[i][j]);
}

Binary file not shown.

View File

@ -62,8 +62,8 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
currentlyInWord = 0;
}
} while ((currentChar != EOF) && (word < maxWordCount));
} while (((currentChar != EOF) && (word <= maxWordCount)));
printf("wortzahl: %d\n", word);
return word;
}

Binary file not shown.

View File

@ -43,6 +43,8 @@ int main(int argc, char *argv[])
// Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
printf("placed Words: %d\n", placedWords);
printf("wordCount = %d\n", wordCount);
// DONE:
// Check if all words were successfully placed
// Start the game if successful

Binary file not shown.