Initial commit - Original Version
This commit is contained in:
parent
66a8931695
commit
42739dc5cc
@ -4,9 +4,42 @@
|
|||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
||||||
|
string readWord(FILE *file)
|
||||||
|
{
|
||||||
|
char word[MAX_WORD_LEN]; // Puffer für Wort
|
||||||
|
int index = 0; // Position im Puffer
|
||||||
|
int c; // Variablefür jedes gelesene Zeichen
|
||||||
|
|
||||||
|
// Whitespace überspringen
|
||||||
|
while(isspace(c = fgetc(file))); //isspace checkt ob gelesenes Zeichen whitespace ist, wenn ja 1 wenn nein 0
|
||||||
|
|
||||||
|
// Buchstaben einlesen bis nächstes whitespace/EOF
|
||||||
|
while(c != EOF && !isspace(c) && index < MAX_WORD_LEN - 1) // -1 wegen Nullterminator
|
||||||
|
{
|
||||||
|
word[index++] = (char)c;
|
||||||
|
c = fgetc(file);
|
||||||
|
}
|
||||||
|
word[index] = '\0'; // Nullterminator (= Ende String)
|
||||||
|
|
||||||
|
return strdup(word); // Rückgabe string, dynamisch allokiert da Zeiger auf lokalen Puffer zurückgegeben
|
||||||
|
}
|
||||||
|
|
||||||
// Read words from file and store in 'words' array
|
// Read words from file and store in 'words' array
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
{
|
{
|
||||||
|
unsigned int count = 0;
|
||||||
|
|
||||||
|
while(count < maxWordCount && !feof(file))
|
||||||
|
{
|
||||||
|
char *word = readWord(file);
|
||||||
|
if(word != NULL)
|
||||||
|
{
|
||||||
|
strncpy(words[count], word, MAX_WORD_LEN - 1); // Wort in Array kopieren
|
||||||
|
words[count][MAX_WORD_LEN - 1] = '\0'; // Sicherstellen, dass String nullterminiert ist
|
||||||
|
free(word); // Dynamisch allokierten Speicher freigeben
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count; // Anzahl der gelesenen Wörter zurückgeben
|
||||||
}
|
}
|
||||||
BIN
Start_Linux/input.o
Normal file
BIN
Start_Linux/input.o
Normal file
Binary file not shown.
@ -31,16 +31,25 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Read words from file and store in 'words' array
|
// Read words from file and store in 'words' array
|
||||||
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
|
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
|
||||||
fclose(file);
|
fclose(file); // TODO:
|
||||||
|
// Check if all words were successfully placed
|
||||||
|
// Start the game if successful
|
||||||
|
// error message if some words couldn't be placed
|
||||||
|
|
||||||
|
|
||||||
// Create the word salad by placing words into grid
|
// Create the word salad by placing words into grid
|
||||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
||||||
|
|
||||||
// TODO:
|
if(placedWords==wordCount)
|
||||||
// Check if all words were successfully placed
|
{
|
||||||
// Start the game if successful
|
// Start the graphical game with the created word salad and the list of words
|
||||||
// error message if some words couldn't be placed
|
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Could not place all words in the word salad. Placed %u out of %u words.\n", placedWords, wordCount);
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
BIN
Start_Linux/main.o
Normal file
BIN
Start_Linux/main.o
Normal file
Binary file not shown.
BIN
Start_Linux/wordsalad_initial
Executable file
BIN
Start_Linux/wordsalad_initial
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user