diff --git a/.idea/editor.xml b/.idea/editor.xml
index ead1d8a..963c96f 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -244,5 +244,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Start_Windows/game.c b/Start_Windows/game.c
index 1952fc3..b7a19a2 100644
--- a/Start_Windows/game.c
+++ b/Start_Windows/game.c
@@ -17,11 +17,12 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
//Random Zeit initialisieren
srand(time(NULL));
- for (unsigned int i = 0; i < searchFieldLen; i++)
+ //Matrix leeren
+ for (unsigned int x = 0; x < searchFieldLen; x++)
{
- for (unsigned int j = 0; j < searchFieldLen; j++)
+ for (unsigned int y = 0; y < searchFieldLen; y++)
{
- salad[i][j] = EMPTY_CHAR;
+ salad[x][y] = EMPTY_CHAR;
}
}
@@ -35,16 +36,17 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
for (int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD; attempt++)
{
+ //random kästchen in der matrix auswählen zwischen 0 und searchfieldlen (row,col)
int row = rand() % searchFieldLen;
int col = rand() % searchFieldLen;
- int direction = rand() % 2;
+ int direction = rand() % 2; //0 = horizontal; 1 = vertikal
int canPlace = 1;
//Ob EIN Wort platziert werden kann (wird noch nicht platziert!)
for (unsigned int k = 0; k < wordLen; k++)
{
- int r = row + (direction == 1 ? k : 0);
- int c = col + (direction == 0 ? k : 0);
+ int r = row + (direction == 1 ? k : 0); //buchstaben werden vertikal darunter gestzt wenn direction = 1 (neue zeile)
+ int c = col + (direction == 0 ? k : 0); //buchstaben werden horizontal rechts daneben gesetzt wenn direction = 0 (neue spalte)
//Ränder des Spielfeldes beachten
if (r >= (int)searchFieldLen || c >= (int)searchFieldLen)
@@ -53,7 +55,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
break;
}
- //Ist die Stelle nicht leer und passt Die stelle nicht zum passenden Buchstaben des Wortes
+ //Ist die Stelle schon besetzt und passt Die stelle nicht zum passenden Buchstaben des Wortes
if (salad[r][c] != EMPTY_CHAR && salad[r][c] != word[k])
{
canPlace = 0;
@@ -63,6 +65,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
if (canPlace) //Wenn geprüft wurde ob ein Wort erfolgreich platziert werden kann.
{
+ //platzieren der buchstaben
for (unsigned int k = 0; k < wordLen; k++)
{
int r = row + (direction == 1 ? k : 0);
@@ -77,13 +80,13 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
}
//Mit Zufälligen Buchstaben füllen
- for (unsigned int i = 0; i < searchFieldLen; i++)
+ for (unsigned int x = 0; x < searchFieldLen; x++)
{
- for (unsigned int j = 0; j < searchFieldLen; j++)
+ for (unsigned int y = 0; y < searchFieldLen; y++)
{
- if (salad[i][j] == EMPTY_CHAR)
+ if (salad[x][y] == EMPTY_CHAR)
{
- salad[i][j] = 'A' + (rand() % 26);
+ salad[x][y] = 'A' + (rand() % 26); //random buchstabe zw A und Z platzieren
}
}
}
@@ -95,11 +98,11 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
// Prints the word salad to console
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
{
- for (unsigned int i = 0; i < searchFieldLen; i++)
+ for (unsigned int x = 0; x < searchFieldLen; x++)
{
- for (unsigned int j = 0; j < searchFieldLen; j++)
+ for (unsigned int y = 0; y < searchFieldLen; y++)
{
- printf("%c ", salad[i][j]);
+ printf("%c ", salad[x][y]);
}
printf("\n");
}
diff --git a/Start_Windows/input.c b/Start_Windows/input.c
index f02b8bd..2e67839 100644
--- a/Start_Windows/input.c
+++ b/Start_Windows/input.c
@@ -12,18 +12,27 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
int c;
unsigned int idx = 0;
- if (!file) return 0;
+ if (!file) return 0; //Wenn keine file gefunden oder geöffnet wurde
- while ((c = fgetc(file)) != EOF && count < maxWordCount) {
- if (isalpha((unsigned char)c)) {
- if (idx < MAX_WORD_LEN - 1) {
+ //scannt jedes zeichen in der file durch bis zum end of file oder bis es genug wörter hat
+ while ((c = fgetc(file)) != EOF && count < maxWordCount)
+ {
+ if (isalpha((unsigned char)c))// prüft ob das zeichen ein buchstabe ist (also kein komma oder leerzeichen usw)
+ {
+ //macht die buchstaben zu Großbuchstaben und schreibt sie ins array
+ //prüft ob das wort kurz genug ist
+ if (idx < MAX_WORD_LEN - 1)
+ {
words[count][idx++] = (char) toupper((unsigned char)c);
- } else {
- // word too long: truncate remaining letters until delimiter
+ } else
+ {
+ // word too long: schneidet das ende vom wort ab bis es reinpasst
idx = MAX_WORD_LEN - 1;
}
- } else {
- if (idx > 0) {
+ } else // bei leerzeichen, komma usw
+ {
+ if (idx > 0) //wort endet -> \0 ;stellt den idx wieder auf 0; neues wort beginnt -> count++
+ {
words[count][idx] = '\0';
count++;
idx = 0;
@@ -32,7 +41,7 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
}
}
- // If file ended while reading a word, terminate and count it
+ //Erkennung vom Ende der file wenn das letze wort endet und wort counten
if (idx > 0 && count < maxWordCount) {
words[count][idx] = '\0';
count++;
diff --git a/Start_Windows/main.c b/Start_Windows/main.c
index 527da5e..bb33419 100644
--- a/Start_Windows/main.c
+++ b/Start_Windows/main.c
@@ -41,6 +41,8 @@ int main(int argc, char *argv[])
// Start the game if successful
// error message if some words couldn't be placed
+
+ //prüft ob die die anzahl der wörter und der tatsächlich platzierten wörter übereinstimmen
if (placedWords == wordCount)
{
printf("All words have been placed successfully.\n");
@@ -57,7 +59,7 @@ int main(int argc, char *argv[])
}
else
{
- // Print error message if file couldn't be opened
+ //Wenn die file nicht geöffnet werden konnte
fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]);
exitCode = EXIT_FAILURE;
}