Compare commits
29
Commits
93db739464
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
825aa17877 | ||
|
|
fd8b643197 | ||
|
|
ebd16cedec | ||
|
|
408e58205a | ||
|
|
464c7ff1ad | ||
|
|
b78f7ac560 | ||
|
|
2ef856d08a | ||
|
|
ad2984a808 | ||
|
|
0d0ab8ab7e | ||
|
|
4c76932472 | ||
|
|
ef95895501 | ||
|
|
6c5710f2f1 | ||
|
|
def3034ede | ||
|
|
fb4211872e | ||
|
|
70c6635991 | ||
|
|
213103dad0 | ||
|
|
c3e875f493 | ||
|
|
fbd986c66f | ||
|
|
2100c8da2c | ||
|
|
1ae5e39309 | ||
|
|
a297e25d94 | ||
|
|
df5c3e2ed0 | ||
|
|
49e4f22a22 | ||
|
|
f1fad264c8 | ||
|
|
977f80eb24 | ||
|
|
450697aac9 | ||
|
|
302c684558 | ||
|
|
5ef39bbddd | ||
|
|
2869474747 |
No files matched your search
+52
-6
@@ -6,12 +6,58 @@
|
|||||||
#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:
|
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int wordCount, char words[][100], unsigned int gridSize)
|
||||||
/* * 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)
|
|
||||||
{
|
{
|
||||||
|
// 1. Komplettes Array sicherheitshalber mit EMPTY_CHAR leeren
|
||||||
|
memset(salad, EMPTY_CHAR, MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN);
|
||||||
|
|
||||||
|
int placedWordsCount = 0;
|
||||||
|
|
||||||
|
// 2. Wörter platzieren
|
||||||
|
for (unsigned int i = 0; i < wordCount; i++) {
|
||||||
|
int len = (int)strlen(words[i]);
|
||||||
|
|
||||||
|
// WICHTIG: Wenn das Wort länger ist als das eigentliche Spielfeld (gridSize), direkt überspringen!
|
||||||
|
if (len == 0 || len > gridSize) continue;
|
||||||
|
|
||||||
|
// Versuche eine freie Position zu finden
|
||||||
|
for (int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD; attempt++) {
|
||||||
|
|
||||||
|
int is_vert = rand() % 2;
|
||||||
|
int dr = is_vert;
|
||||||
|
int dc = !is_vert;
|
||||||
|
|
||||||
|
// Zufällige Position INNERHALB der gridSize wählen (nicht mehr 100x100!)
|
||||||
|
int row = rand() % (gridSize - (is_vert ? len - 1 : 0));
|
||||||
|
int col = rand() % (gridSize - (is_vert ? 0 : len - 1));
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (nur innerhalb der gridSize!) mit Zufallsbuchstaben 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;
|
||||||
}
|
}
|
||||||
+2
-1
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#define MAX_SEARCH_FIELD_LEN 100
|
#define MAX_SEARCH_FIELD_LEN 100
|
||||||
|
|
||||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount);
|
// 4. Parameter ist die gridSize!
|
||||||
|
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int wordCount, char words[][100], unsigned int gridSize);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -4,6 +4,20 @@
|
|||||||
|
|
||||||
// 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.
|
||||||
|
char* readSingleWord(FILE *file, char *destination, int maxLen)
|
||||||
|
{
|
||||||
|
char buffer[256]; // Zwischenspeicher zum einlesen
|
||||||
|
if (fgets(buffer, sizeof(buffer), file) != NULL)
|
||||||
|
{
|
||||||
|
buffer[strcspn(buffer, "\r\n")] = '\0'; // Entfernt Umbrüche
|
||||||
|
|
||||||
|
strncpy(destination, buffer, maxLen - 1);
|
||||||
|
destination[maxLen - 1] = '\0'; // Zwingendes Ende des C-Strings setzen, verhindert Pufferüberlauf
|
||||||
|
|
||||||
|
return destination; //Rückgabe bei Erfolg
|
||||||
|
}
|
||||||
|
return NULL; //Rückgabe nur bei Dateiende
|
||||||
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
|
|||||||
+10
-1
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#define MAX_NUMBER_OF_WORDS 100
|
#define MAX_NUMBER_OF_WORDS 100
|
||||||
#define SALAD_SIZE 20
|
#define SALAD_SIZE 20
|
||||||
|
#define WINDOW_WIDTH 800 //Breite Spielfenster 800 Pixel
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
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
|
// Create the word salad by placing words into grid
|
||||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
||||||
|
|
||||||
// TODO:
|
// TODO: erledigt
|
||||||
// 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 (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
|
else
|
||||||
|
|||||||
@@ -22,6 +22,13 @@ codefolder = .
|
|||||||
wordsalad_initial:
|
wordsalad_initial:
|
||||||
$(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
$(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
|
# Normales Spiel bauen
|
||||||
# --------------------------
|
# --------------------------
|
||||||
|
|||||||
Executable
BIN
Binary file not shown.
Reference in new issue
Block a user