Compare commits
52
Commits
977f80eb24
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01d27db3fa | ||
|
|
b12784e0fe | ||
|
|
8909443f50 | ||
|
|
aa36943cb2 | ||
|
|
7f58ec3e92 | ||
|
|
a04771cf11 | ||
|
|
49132b1e47 | ||
|
|
f732b3edf9 | ||
|
|
c859d76447 | ||
|
|
561fd213b6 | ||
|
|
3c43aca7b1 | ||
|
|
49f1a06e02 | ||
|
|
2f0857c711 | ||
|
|
b4ee9ae4e4 | ||
|
|
29551521f0 | ||
|
|
b9c4545cc0 | ||
|
|
edf465fd79 | ||
|
|
ae2024266a | ||
|
|
9c29e702e9 | ||
|
|
45a30468f7 | ||
|
|
cb0bbc68de | ||
|
|
580e84491d | ||
|
|
b732b3d526 | ||
|
|
b6f873833d | ||
|
|
852ae19472 | ||
|
|
9e53289322 | ||
|
|
361e5ddaca | ||
|
|
825aa17877 | ||
|
|
fd8b643197 | ||
|
|
ebd16cedec | ||
|
|
408e58205a | ||
|
|
464c7ff1ad | ||
|
|
b78f7ac560 | ||
|
|
2ef856d08a | ||
|
|
ad2984a808 | ||
|
|
0d0ab8ab7e | ||
|
|
4c76932472 | ||
|
|
ef95895501 | ||
|
|
6c5710f2f1 | ||
|
|
def3034ede | ||
|
|
fb4211872e | ||
|
|
70c6635991 | ||
|
|
213103dad0 | ||
|
|
c3e875f493 | ||
|
|
fbd986c66f | ||
|
|
2100c8da2c | ||
|
|
1ae5e39309 | ||
|
|
a297e25d94 | ||
|
|
df5c3e2ed0 | ||
|
|
49e4f22a22 | ||
|
|
f1fad264c8 | ||
|
|
450697aac9 |
No files matched your search
+53
-6
@@ -6,12 +6,59 @@
|
||||
#define MAX_RAND_TRIES_PER_WORD 10
|
||||
#define EMPTY_CHAR 0
|
||||
|
||||
//TODO: Spiellogik implementieren:
|
||||
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||
|
||||
// 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 gridSize, char words[][100], unsigned int wordCount)
|
||||
{
|
||||
// 1. Spielfeld initialisieren
|
||||
memset(salad, EMPTY_CHAR, MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN);
|
||||
|
||||
int placedWordsCount = 0;
|
||||
|
||||
// 2. Wörter im Spielfeld platzieren
|
||||
for (unsigned int i = 0; i < wordCount; i++) {
|
||||
int len = (int)strlen(words[i]);
|
||||
|
||||
// Wörter überspringen, die leer oder zu lang für das Suchfeld (gridSize) sind
|
||||
if (len == 0 || (unsigned int)len > gridSize) continue;
|
||||
|
||||
for (int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD; attempt++) {
|
||||
Direction dir = (rand() % 2 == 0) ? DIR_HORIZONTAL : DIR_VERTICAL;
|
||||
|
||||
int dr = (dir == DIR_VERTICAL) ? 1 : 0; // Zeilensprung
|
||||
int dc = (dir == DIR_HORIZONTAL) ? 1 : 0; // Spaltensprung
|
||||
|
||||
// Startkoordinaten innerhalb der gridSize wählen
|
||||
int row = rand() % (gridSize - (dir == DIR_VERTICAL ? len - 1 : 0));
|
||||
int col = rand() % (gridSize - (dir == DIR_HORIZONTAL ? len - 1 : 0));
|
||||
|
||||
// Kollisionsprüfung
|
||||
int canPlace = 1;
|
||||
for (int k = 0; k < len; k++) {
|
||||
char current = salad[row + k * dr][col + k * dc];
|
||||
if (current != EMPTY_CHAR && current != words[i][k]) {
|
||||
canPlace = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Wort ins Spielfeld eintragen
|
||||
if (canPlace) {
|
||||
for (int k = 0; k < len; k++) {
|
||||
salad[row + k * dr][col + k * dc] = words[i][k];
|
||||
}
|
||||
placedWordsCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Verbleibende leere Felder innerhalb der gridSize auffüllen
|
||||
for (unsigned int r = 0; r < gridSize; r++) {
|
||||
for (unsigned int c = 0; c < gridSize; c++) {
|
||||
if (salad[r][c] == EMPTY_CHAR) {
|
||||
salad[r][c] = 'A' + (rand() % 26);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return placedWordsCount;
|
||||
}
|
||||
+9
-1
@@ -3,8 +3,16 @@
|
||||
|
||||
#include "input.h"
|
||||
|
||||
#ifndef MAX_SEARCH_FIELD_LEN
|
||||
#define MAX_SEARCH_FIELD_LEN 100
|
||||
#endif
|
||||
|
||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount);
|
||||
typedef enum {
|
||||
DIR_HORIZONTAL = 0,
|
||||
DIR_VERTICAL = 1
|
||||
} Direction;
|
||||
|
||||
// Reihenfolge: salad, gridSize, words, wordCount
|
||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int gridSize, char words[][100], unsigned int wordCount);
|
||||
|
||||
#endif
|
||||
+68
-2
@@ -2,11 +2,77 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
// TODO:
|
||||
// TODO: erledigt
|
||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
||||
char* readSingleWord(FILE *file, char *destination, int maxLen)
|
||||
{
|
||||
char buffer[256];
|
||||
int ch;
|
||||
int bufIndex = 0;
|
||||
|
||||
// Alle Trennzeichen überspringen, bis ein echter Buchstabe kommt
|
||||
while ((ch = fgetc(file)) != EOF)
|
||||
{
|
||||
// Prüfen der Buchstaben
|
||||
if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
|
||||
{
|
||||
// Wenn Kleinbuchstabe, in Großbuchstabe umwandeln
|
||||
if (ch >= 'a' && ch <= 'z')
|
||||
{
|
||||
ch = ch - 32;
|
||||
}
|
||||
buffer[bufIndex] = ch;
|
||||
bufIndex++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ch == EOF)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Den Rest des Wortes einlesen (bricht bei Kommas, Leerzeichen etc. ab)
|
||||
while ((ch = fgetc(file)) != EOF && ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')))
|
||||
{
|
||||
if (bufIndex < 255)
|
||||
{
|
||||
if (ch >= 'a' && ch <= 'z')
|
||||
{
|
||||
ch = ch - 32;
|
||||
}
|
||||
buffer[bufIndex] = ch;
|
||||
bufIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
// Zwischenspeicher abschließen
|
||||
buffer[bufIndex] = '\0';
|
||||
|
||||
// Sicheres Kopieren in das Ziel-Array
|
||||
strncpy(destination, buffer, maxLen - 1);
|
||||
destination[maxLen - 1] = '\0';
|
||||
return destination;
|
||||
}
|
||||
|
||||
// Read words from file and store in 'words' array
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
|
||||
unsigned int count = 0;
|
||||
// Schleife läuft, solange noch Platz im Array ist
|
||||
while (count < maxWordCount)
|
||||
{
|
||||
if (readSingleWord(file, words[count], MAX_WORD_LEN) != NULL)
|
||||
{
|
||||
if (strlen(words[count]) > 0) // Prüfen, ob das Wort nicht leer ist
|
||||
{
|
||||
count++; // nächstes Wort
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break; // Bei Dateiende wird die Schleife abgebrochen
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
+10
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
#define MAX_NUMBER_OF_WORDS 100
|
||||
#define SALAD_SIZE 20
|
||||
#define WINDOW_WIDTH 800 //Breite Spielfenster 800 Pixel
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@@ -36,10 +37,18 @@ int main(int argc, char *argv[])
|
||||
// Create the word salad by placing words into grid
|
||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
||||
|
||||
// TODO:
|
||||
// TODO: erledigt
|
||||
// Check if all words were successfully placed
|
||||
// Start the game if successful
|
||||
// error message if some words couldn't be placed
|
||||
if (placedWords == wordCount) //wenn alle Wörter erfolgreicht plaziert sind
|
||||
{
|
||||
startGame(wordSalad, SALAD_SIZE, words, wordCount, WINDOW_WIDTH); //Startet das Spiel
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Fehler: Es konnten nicht alle Wörter plaziert werden\n"); //Gibt Fehlermeldung aus
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
|
||||
@@ -22,6 +22,13 @@ codefolder = .
|
||||
wordsalad_initial:
|
||||
$(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||
|
||||
# --------------------------
|
||||
# meine Version
|
||||
# --------------------------
|
||||
wordsalad_myversion: main.o graphicalGame.o $(BINARIES)/libraylib.a
|
||||
$(CC) $(CFLAGS) -o wordsalad_myversion main.o graphicalGame.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||
|
||||
|
||||
# --------------------------
|
||||
# Normales Spiel bauen
|
||||
# --------------------------
|
||||
|
||||
Executable
BIN
Binary file not shown.
+1
-1
@@ -2,4 +2,4 @@ Yeti,Nessie Werwolf; Vampir
|
||||
Monster
|
||||
Hydra;Frankenstein
|
||||
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
|
||||
Gespenst, Oger, Maus
|
||||
Gespenst, Oger
|
||||
Reference in new issue
Block a user