Merge remote-tracking branch 'origin/main'
# Conflicts: # Start_Windows/game.c # Start_Windows/input.c
This commit is contained in:
commit
1eca104cd9
@ -22,7 +22,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
{
|
{
|
||||||
for (unsigned int j = 0; j < searchFieldLen; ++j)
|
for (unsigned int j = 0; j < searchFieldLen; ++j)
|
||||||
{
|
{
|
||||||
salad[i][j] = EMPTY_CHAR;
|
salad[i][j] = ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
{
|
{
|
||||||
if (salad[i][j] == EMPTY_CHAR)
|
if (salad[i][j] == EMPTY_CHAR)
|
||||||
{
|
{
|
||||||
salad[i][j] = 'A' + (rand() % 26);
|
salad[i][j] = 'A' + rand() % 26;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Start_Windows/game.o
Normal file
BIN
Start_Windows/game.o
Normal file
Binary file not shown.
@ -1,39 +1,43 @@
|
|||||||
#include <stdio.h>
|
#include "input.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#define MAX_WORD_LEN 100
|
|
||||||
|
|
||||||
void capitalletters(char *str) {
|
void capitalletters(char *str){
|
||||||
while (*str) {
|
while (*str) {
|
||||||
*str = toupper((unsigned char)*str);
|
*str = toupper((unsigned char) *str);
|
||||||
str++;
|
str++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
// Liest Wörter aus Datei und speichert sie sicher im 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)
|
||||||
{
|
{
|
||||||
char buffer[1024]; // größerer Puffer für ganze Zeile
|
char buffer[MAX_WORD_LEN];
|
||||||
unsigned int count_word = 0;
|
unsigned int count_word = 0;
|
||||||
|
|
||||||
|
|
||||||
while (count_word < maxWordCount && fgets(buffer, sizeof(buffer), file) != NULL)
|
while (count_word < maxWordCount && fgets(buffer, sizeof(buffer), file) != NULL)
|
||||||
{
|
{
|
||||||
// Zeilenumbruch entfernen
|
|
||||||
buffer[strcspn(buffer, "\r\n")] = '\0';
|
|
||||||
|
|
||||||
// Zerlege Zeile in Wörter anhand von Leerzeichen, Komma und Semikolon
|
// Zeilenumbruch manuell entfernen
|
||||||
char *token = strtok(buffer, " ,;");
|
for (int i = 0; i < MAX_WORD_LEN; i++)
|
||||||
|
|
||||||
while (token != NULL && count_word < maxWordCount)
|
|
||||||
{
|
{
|
||||||
capitalletters(token); // Großschreiben
|
if (buffer[i] == '\n' || buffer[i] == '\r')
|
||||||
strncpy(words[count_word], token, MAX_WORD_LEN - 1);
|
{
|
||||||
words[count_word][MAX_WORD_LEN - 1] = '\0'; // Nullterminierung
|
buffer[i] = '\0';
|
||||||
count_word++;
|
break;
|
||||||
|
|
||||||
token = strtok(NULL, " ,;");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
capitalletters(buffer);
|
||||||
|
|
||||||
|
// Sicheres Kopieren in das Zielarray
|
||||||
|
strncpy(words[count_word], buffer, MAX_WORD_LEN - 1);
|
||||||
|
words[count_word][MAX_WORD_LEN - 1] = '\0'; // Nullterminierung sicherstellen
|
||||||
|
|
||||||
|
count_word++;
|
||||||
|
}
|
||||||
|
|
||||||
return count_word;
|
return count_word;
|
||||||
}
|
}
|
||||||
BIN
Start_Windows/input.o
Normal file
BIN
Start_Windows/input.o
Normal file
Binary file not shown.
@ -36,16 +36,10 @@ int main(int argc, char *argv[])
|
|||||||
// 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:
|
|
||||||
// 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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (placedWords == wordCount)
|
if (placedWords == wordCount)
|
||||||
{
|
{
|
||||||
// Start the game
|
// Start the game if successful
|
||||||
unsigned int windowSize = 900; //FRAGE: Programm so programmieren, dass man das weglassen kann
|
unsigned int windowSize = 900; //FRAGE: Programm so programmieren, dass man das weglassen kann
|
||||||
startGame(wordSalad, SALAD_SIZE, words, wordCount, windowSize);
|
startGame(wordSalad, SALAD_SIZE, words, wordCount, windowSize);
|
||||||
}
|
}
|
||||||
@ -56,7 +50,6 @@ int main(int argc, char *argv[])
|
|||||||
exitCode = EXIT_FAILURE;
|
exitCode = EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
BIN
Start_Windows/runTests.exe
Normal file
BIN
Start_Windows/runTests.exe
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user