Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eaa16ed84c | |||
| 32a6133d18 | |||
| 39e8380916 | |||
| ffaed665b9 | |||
| e20bf82c19 | |||
| 1ed03a3444 | |||
| 6b435cf82d | |||
| 92c0ab2c28 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"folders": [
|
|
||||||
{
|
|
||||||
"path": "../../../Documents/Wichtiges/Arbeit/Kalenderjahr 2025/Trainingscenter/4.Woche/VSS Code"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "../../../VSS"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"settings": {}
|
|
||||||
}
|
|
||||||
@ -6,116 +6,18 @@
|
|||||||
#define MAX_RAND_TRIES_PER_WORD 10
|
#define MAX_RAND_TRIES_PER_WORD 10
|
||||||
#define EMPTY_CHAR 0
|
#define EMPTY_CHAR 0
|
||||||
|
|
||||||
// TODO: Spiellogik implementieren:
|
//TODO: Spiellogik implementieren:
|
||||||
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||||
|
|
||||||
// Creates the word salad by placing words randomly and filling empty spaces
|
// Creates the word salad by placing words randomly and filling empty spaces
|
||||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
||||||
{
|
{
|
||||||
srand(time(NULL));
|
|
||||||
// wipe field
|
|
||||||
int placedWords = 0;
|
|
||||||
for (int i = 0; i < searchFieldLen; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < searchFieldLen ; j++)
|
|
||||||
salad[i][j] = EMPTY_CHAR;
|
|
||||||
}
|
|
||||||
// place Words
|
|
||||||
for (int wordNumber = 0; wordNumber < wordCount; wordNumber++)
|
|
||||||
{
|
|
||||||
int wordlength = strlen(words[wordNumber]);
|
|
||||||
|
|
||||||
int placed = 0;
|
|
||||||
|
|
||||||
for (int try = 0; (try < MAX_RAND_TRIES_PER_WORD) && !placed; try++)
|
|
||||||
{
|
|
||||||
int horizontal = rand() % 2; // 0 vertikal --> 1 horizontal
|
|
||||||
|
|
||||||
int x = rand() % searchFieldLen;
|
|
||||||
int y = rand() % searchFieldLen;
|
|
||||||
|
|
||||||
if (horizontal)
|
|
||||||
{
|
|
||||||
if (x + wordlength > searchFieldLen) // word does not fit
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fits = 1;
|
|
||||||
|
|
||||||
for (int i = 0; i < wordlength; i++) // position already occupied by other word
|
|
||||||
{
|
|
||||||
if (salad[y][x + i] != EMPTY_CHAR)
|
|
||||||
{
|
|
||||||
fits = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fits)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < wordlength; i++)
|
|
||||||
{
|
|
||||||
salad[y][x + i] = words[wordNumber][i];
|
|
||||||
}
|
|
||||||
placed = 1;
|
|
||||||
placedWords++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ((y + wordlength) > searchFieldLen)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fits = 1;
|
|
||||||
|
|
||||||
for (int i = 0; i < wordlength; i++) // position already occupied by other word
|
|
||||||
{
|
|
||||||
if (salad[y + i][x] != EMPTY_CHAR)
|
|
||||||
{
|
|
||||||
fits = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fits)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < wordlength; i++)
|
|
||||||
{
|
|
||||||
salad[y + i][x] = words[wordNumber][i];
|
|
||||||
}
|
|
||||||
placed = 1;
|
|
||||||
placedWords++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// fill rest with random characters
|
|
||||||
|
|
||||||
for (int i = 0; i < searchFieldLen; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < searchFieldLen; j++)
|
|
||||||
{
|
|
||||||
if (salad[i][j] == EMPTY_CHAR)
|
|
||||||
{
|
|
||||||
salad[i][j] = rand() % ('Z' - 'A' + 1) + 'A'; // 90 ist Z in ASCII und A ist 65
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return placedWords;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the word salad to console
|
// Prints the word salad to console
|
||||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < searchFieldLen; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < searchFieldLen; j++)
|
|
||||||
{
|
|
||||||
printf("%c", salad[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@ -8,35 +8,5 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
//kein fopen und fclose nötig, weil dies schon in der main passiert und mit *file übergeben wird//
|
|
||||||
|
|
||||||
|
}
|
||||||
if (file == NULL)
|
|
||||||
{
|
|
||||||
perror("Error invalid pointer to file");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char line[1024];
|
|
||||||
unsigned int count = 0;
|
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), file) && (count < maxWordCount))
|
|
||||||
{
|
|
||||||
line[strcspn(line, "\n")] = '\0';
|
|
||||||
|
|
||||||
char *token = strtok(line, " ;,");
|
|
||||||
while (token && (count < maxWordCount))
|
|
||||||
{
|
|
||||||
for (int i = 0; token[i] != '\0'; i++)
|
|
||||||
{
|
|
||||||
token[i] = toupper(token[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(words[count], token);
|
|
||||||
count++;
|
|
||||||
token = strtok(NULL, " ;,");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -12,7 +12,7 @@ int main(int argc, char *argv[])
|
|||||||
int exitCode = EXIT_SUCCESS;
|
int exitCode = EXIT_SUCCESS;
|
||||||
|
|
||||||
// Check if the correct number of arguments is provided
|
// Check if the correct number of arguments is provided
|
||||||
if (argc != 2)
|
if(argc != 2)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
|
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
|
||||||
exitCode = EXIT_FAILURE;
|
exitCode = EXIT_FAILURE;
|
||||||
@ -24,7 +24,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
FILE *file = fopen(argv[1], "r");
|
FILE *file = fopen(argv[1], "r");
|
||||||
|
|
||||||
if (file != NULL)
|
if(file != NULL)
|
||||||
{
|
{
|
||||||
unsigned int placedWords = 0;
|
unsigned int placedWords = 0;
|
||||||
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
|
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
|
||||||
@ -40,14 +40,7 @@ int main(int argc, char *argv[])
|
|||||||
// Check if all words were successfully placed
|
// Check if all words were successfully placed
|
||||||
// Start the game if successful
|
// Start the game if successful
|
||||||
// error message if some words couldn't be placed
|
// error message if some words couldn't be placed
|
||||||
if (wordCount != placedWords)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Error: %u out of %u were placed\n", placedWords, wordCount);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
startGame(wordSalad, SALAD_SIZE, words, placedWords, 1024);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Binary file not shown.
@ -6,12 +6,6 @@ BINARIES = ./windows
|
|||||||
raylibfolder = ./raylib
|
raylibfolder = ./raylib
|
||||||
unityfolder = ./unity
|
unityfolder = ./unity
|
||||||
|
|
||||||
# --------------------------
|
|
||||||
# my version
|
|
||||||
# --------------------------
|
|
||||||
wordsalad_myversion: main.o graphicalGame.o
|
|
||||||
$(CC) main.o graphicalGame.o -o wordsalad_myversion $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# initiales Spiel bauen
|
# initiales Spiel bauen
|
||||||
# --------------------------
|
# --------------------------
|
||||||
@ -23,7 +17,7 @@ wordsalad_initial:
|
|||||||
# --------------------------
|
# --------------------------
|
||||||
all: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
|
all: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
|
||||||
$(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)
|
$(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
main.o: main.c
|
main.o: main.c
|
||||||
$(CC) -c $(CFLAGS) main.c
|
$(CC) -c $(CFLAGS) main.c
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@ -1,3 +1,5 @@
|
|||||||
Multiplikation, Division, Addition, Subtraktion, Term
|
Yeti,Nessie Werwolf; Vampir
|
||||||
Bruch
|
Monster
|
||||||
Nenner, Zaehler, Daten, Saeulendiagramm
|
Hydra;Frankenstein
|
||||||
|
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
|
||||||
|
Gespenst, Oger
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user