Prüfe in main.c die input.c und game.c, Target in Makefile hinzugefügt
This commit is contained in:
1 parent
d9ac9f27e1
commit
96ecac9e4c
2 files changed
+37
-47
No files matched your search
+25
-46
@@ -1,6 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "input.h"
|
||||
#include "game.h"
|
||||
#include "graphicalGame.h"
|
||||
@@ -8,42 +7,6 @@
|
||||
#define MAX_NUMBER_OF_WORDS 100
|
||||
#define SALAD_SIZE 20
|
||||
|
||||
int checkSalad(char words[][MAX_WORD_LEN], char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], int placedWords, int wordCount){
|
||||
//Iteriere über alle verfügbaren Wörter
|
||||
int foundWords = 0;
|
||||
|
||||
//suche horizontal
|
||||
for(int i = 0; i < wordCount; i++){
|
||||
for(int h = 0; h < MAX_SEARCH_FIELD_LEN; h++){
|
||||
if(strstr(wordSalad[h], words[i]) != NULL){
|
||||
foundWords++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//flip Board
|
||||
char copySalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
||||
for (int i = 0; i< MAX_SEARCH_FIELD_LEN; i++){
|
||||
for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++){
|
||||
copySalad[i][j] = wordSalad[j][i];
|
||||
}
|
||||
}
|
||||
|
||||
// sucher vertikal
|
||||
for(int i = 0; i < wordCount; i++){
|
||||
for(int h = 0; h < MAX_SEARCH_FIELD_LEN; h++){
|
||||
if(strstr(copySalad[h], words[i]) != NULL){
|
||||
foundWords++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(foundWords == placedWords) return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int exitCode = EXIT_SUCCESS;
|
||||
@@ -54,10 +17,11 @@ int main(int argc, char *argv[])
|
||||
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game
|
||||
unsigned int wordCount = 0;
|
||||
int wordCount = 0;
|
||||
|
||||
FILE *file = fopen(argv[1], "r");
|
||||
|
||||
@@ -76,17 +40,32 @@ int main(int argc, char *argv[])
|
||||
// TODO:
|
||||
// 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 (return input.c / game.c <=0)
|
||||
|
||||
int check = checkSalad(words, wordSalad, placedWords, wordCount);
|
||||
//Fehlerfall
|
||||
if(check != 0){
|
||||
fprintf(stderr, "Not all words could be placed!\n");
|
||||
// Prüfen, ob input.c (readWords) einen Fehler oder 0 Wörter zurückgegeben hat
|
||||
if (wordCount <= 0)
|
||||
{
|
||||
fprintf(stderr, "Fehler: Es konnten keine Wörter eingelesen werden (input.c Rückgabewert <= 0).\n");
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
//keine Ahnung wiegroß pixelSize sein soll
|
||||
startGame(wordSalad, MAX_SEARCH_FIELD_LEN, words, placedWords, MAX_SEARCH_FIELD_LEN * SALAD_SIZE);
|
||||
|
||||
// Prüfen, ob game.c (createWordSalad) einen Fehler zurückgegeben hat (<= 0) oder ob nicht alle eingelesenen Wörter platziert werden konnten
|
||||
else if (placedWords <= 0 || placedWords < wordCount)
|
||||
{
|
||||
fprintf(stderr, "Fehler: Nicht alle Wörter konnten im Wortsalat platziert werden (game.c Rückgabewert <= 0).\n");
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Wenn alles erfolgreich war, wird das Spiel gestartet.
|
||||
else
|
||||
{
|
||||
printf("Alle Wörter erfolgreich platziert! Starte das Spiel...\n");
|
||||
|
||||
// Übergabe an graphicalGame.c via startGame:
|
||||
startGame(wordSalad, MAX_SEARCH_FIELD_LEN, words, placedWords, 400); // Parameter: (wordSalad, searchFieldSize, words, numberOfWords, windowSize)
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// Print error message if file couldn't be opened
|
||||
@@ -96,4 +75,4 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user