Compare commits

..

3 Commits

Author SHA1 Message Date
c95c264a3a
don't exit if some words couldn't be placed 2025-10-31 12:45:15 +01:00
Fabrice
147fc502eb kleine Änderungen 2025-10-31 09:29:12 +01:00
27eafd14cc Merge pull request 'simon' (#3) from simon into main
Reviewed-on: #3
2025-10-31 08:05:56 +00:00
3 changed files with 24 additions and 16 deletions

View File

@ -37,17 +37,21 @@ int main(int argc, char *argv[])
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// Check if all words were successfully placed // Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed // error message if some words couldn't be placed
if (placedWords < wordCount) if (placedWords < wordCount)
{ {
fprintf(stderr, "some words couldn't be placed\n"); int notPlacedNum = wordCount - placedWords;
exitCode = EXIT_FAILURE; fprintf(stderr, "%d word(s) couldn't be placed\n", notPlacedNum);
} }
// TODO: // TODO:
// Start the game if successful // correct parameters for startGame
// Start the game if at least 1 word has been successfully placed
else if (placedWords >= 1)
{
startGame(wordSalad, 80, words, placedWords, 800);
}
} }
else else
{ {

View File

@ -16,9 +16,9 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
// set seed for random number generator // set seed for random number generator
srand(time(NULL)); srand(time(NULL));
int r, c; int r, c, placedWords=0;
//Gesamtes Feld auf 0 setzen //Gesamtes Feld auf 0 setzen, am besten in eigene Fkt, dann aber extra Tests dafür erstellen
for (r=0; r < searchFieldLen; r++) { for (r=0; r < searchFieldLen; r++) {
for (c=0; c < searchFieldLen; c++) { for (c=0; c < searchFieldLen; c++) {
salad [r][c] = EMPTY_CHAR; salad [r][c] = EMPTY_CHAR;
@ -33,7 +33,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
//Prüfen, ob das Wort von der Länge her ins Feld passt //Prüfen, ob das Wort von der Länge her ins Feld passt
//Felder, in denen keine Wörter stehen, werden mit zufälligen Buchstaben befüllt //Felder, in denen keine Wörter stehen, werden mit zufälligen Buchstaben befüllt, am besten in eigene Fkt, dann aber extra Tests dafür erstellen
for (r=0; r < searchFieldLen; r++) { for (r=0; r < searchFieldLen; r++) {
for (c=0; c < searchFieldLen; c++) { for (c=0; c < searchFieldLen; c++) {
if (salad[r][c] == EMPTY_CHAR) { if (salad[r][c] == EMPTY_CHAR) {
@ -41,8 +41,8 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
} }
} }
} }
//return "Anzahl platzierter Wörter", wird in Main dann mit soll verglichen
return 0; return placedWords;
} }
// Prints the word salad to console // Prints the word salad to console

View File

@ -37,17 +37,21 @@ int main(int argc, char *argv[])
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// Check if all words were successfully placed // Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed // error message if some words couldn't be placed
if (placedWords < wordCount) if (placedWords < wordCount)
{ {
fprintf(stderr, "some words couldn't be placed\n"); int notPlacedNum = wordCount - placedWords;
exitCode = EXIT_FAILURE; fprintf(stderr, "%d word(s) couldn't be placed\n", notPlacedNum);
} }
// TODO: // TODO:
// Start the game if successful // correct parameters for startGame
// Start the game if at least 1 word has been successfully placed
else if (placedWords >= 1)
{
startGame(wordSalad, 80, words, placedWords, 800);
}
} }
else else
{ {