Compare commits
8
Commits
chris
...
a5e963f2a6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5e963f2a6 | ||
|
|
356bb5cb9e | ||
|
|
fd89a1e5f7 | ||
|
|
b9fd1b3553 | ||
|
|
86bf0775f8 | ||
|
|
30c53ce8b9 | ||
|
|
61c60ebffd | ||
|
|
59f222f3c1 |
No files matched your search
@@ -13,5 +13,98 @@
|
|||||||
// 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));
|
||||||
|
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
int placedWords = 0;
|
||||||
|
int i = 0;
|
||||||
|
int nichtPlatziert =0;
|
||||||
|
typedef enum {vertikal, horizontal} Platzierungsrichtung;
|
||||||
|
|
||||||
|
for(int i =0; i < MAX_SEARCH_FIELD_LEN; i++) //Array Salad mit 0 füllen um es nachher als vergleichsoperator zu nutzen
|
||||||
|
{
|
||||||
|
for( int j = 0; j < MAX_SEARCH_FIELD_LEN; j++)
|
||||||
|
{
|
||||||
|
salad[i][j] = '0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while(placedWords < wordCount)
|
||||||
|
{
|
||||||
|
x = rand() % 20 +1;
|
||||||
|
y = rand() % 20 +1;
|
||||||
|
|
||||||
|
Platzierungsrichtung zufaellige_richtung = rand() % 2;
|
||||||
|
|
||||||
|
if(zufaellige_richtung == 0 && salad[y][x] == '0')
|
||||||
|
{
|
||||||
|
|
||||||
|
if(sizeof(words[i]-1) <= (MAX_SEARCH_FIELD_LEN-y)) // -1, da Nullzeichen sowieso weg muss
|
||||||
|
{
|
||||||
|
for(int j = 0; j < sizeof(words[i]-1); j++)
|
||||||
|
{
|
||||||
|
if(salad[(y+j)][x] == '0')
|
||||||
|
{
|
||||||
|
strncpy(&salad[(y+j)][x], &words[i][j], 1);
|
||||||
|
}
|
||||||
|
else if(&salad[(y+j)][x] == &words[i][j])
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nichtPlatziert = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(nichtPlatziert == 0)
|
||||||
|
{
|
||||||
|
placedWords++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if( zufaellige_richtung == 1 && salad[y][x] == '0')
|
||||||
|
{
|
||||||
|
if(sizeof(words[i]-1) <= (MAX_SEARCH_FIELD_LEN-x)) // -1, da Nullzeichen sowieso weg muss
|
||||||
|
{
|
||||||
|
for(int j = 0; j < sizeof(words[i]-1); j++)
|
||||||
|
{
|
||||||
|
if(salad[y][(x+j)] == '0')
|
||||||
|
{
|
||||||
|
strncpy(&salad[y][(x+j)], &words[i][j], 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(&salad[y][(x+j)] == &words[i][j])
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nichtPlatziert = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(nichtPlatziert == 0)
|
||||||
|
{
|
||||||
|
placedWords++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i =0; i < MAX_SEARCH_FIELD_LEN; i++) //Array Salad mit 0 füllen um es nachher als vergleichsoperator zu nutzen
|
||||||
|
{
|
||||||
|
for( int j = 0; j < MAX_SEARCH_FIELD_LEN; j++)
|
||||||
|
{
|
||||||
|
if(salad[i][j] == '0')
|
||||||
|
{
|
||||||
|
salad[i][j] = rand() % (90-65+1)+ 65;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return placedWords;
|
||||||
}
|
}
|
||||||
+17
-13
@@ -9,26 +9,30 @@
|
|||||||
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 puffer[MAX_LINE_LEN];
|
char puffer[MAX_LINE_LEN];
|
||||||
char *teiler = " ,;\n";
|
char *teiler = "\n ,;";
|
||||||
char *token;
|
char *token;
|
||||||
FILE *words_txt_speicherort; //Zeiger auf den Speicherort der word.txt Datei
|
unsigned int wordCount = 0;
|
||||||
|
|
||||||
words_txt_speicherort = fopen("words.txt","r"); //word.txt öffnen
|
while(fgets(puffer, MAX_LINE_LEN, file) != NULL) //Liest die zeilenweise Wörter aus der file in einen Zwischenpuffer bis das Dateiende erreicht ist returnwert der file == NULL
|
||||||
|
|
||||||
if(words_txt_speicherort == NULL) //Abbruch falls words.txt nicht existieren würde
|
|
||||||
{
|
{
|
||||||
return -1;
|
token = strtok(puffer, teiler); // Holt sich per Teilerbedingung das erste Wort aus dem puffer
|
||||||
|
|
||||||
|
while(token != NULL && wordCount < maxWordCount)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < MAX_WORD_LEN; i++) //Verwandelt jeden Buchstaben in einen Großbuchstaben
|
||||||
|
{
|
||||||
|
token[i] = toupper(token[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fgets(puffer, MAX_LINE_LEN, words_txt_speicherort); //speichert alle Zeichen der words.txt datei in den speicher
|
strncpy(words[wordCount], token, MAX_WORD_LEN -1); //speichert einzelnes Wort in das gegeben word array ab und holt sich das nächste im Puffer, bis array leer token == NULL
|
||||||
|
//words[wordCount][MAX_WORD_LEN - 1] = '\0';
|
||||||
|
|
||||||
token = strtok(puffer, teiler); //Trennt das erste Wort der Zeichenkette, abhängig von den Teilerbedingungen
|
wordCount++;
|
||||||
|
|
||||||
while(token != NULL)
|
token = strtok(NULL, teiler);
|
||||||
|
}
|
||||||
words = token; //speichert nur das einzelne Word in das words array; Problem: Laufindex der global gespeichert werden müsste; wie springe ich beim 2ten Funktionsaufruf zum nächsten Wort
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return wordCount;
|
||||||
int fclose(words_txt_speicherort);
|
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#define MAX_WORD_LEN 100
|
#define MAX_WORD_LEN 100
|
||||||
#define MAX_LINE_LEN 1024
|
#define MAX_LINE_LEN 1024
|
||||||
|
#define MAX_LINE_NUMBER 100 //Selbst hinzugefügt
|
||||||
|
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount);
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount);
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -36,10 +36,11 @@ 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
|
if(placedWords == wordCount)
|
||||||
// Start the game if successful
|
{
|
||||||
// error message if some words couldn't be placed
|
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -25,6 +25,13 @@ wordsalad_initial:
|
|||||||
# --------------------------
|
# --------------------------
|
||||||
# Normales Spiel bauen
|
# Normales Spiel bauen
|
||||||
# --------------------------
|
# --------------------------
|
||||||
|
|
||||||
|
wordsalad_myversion: input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a
|
||||||
|
$(CC) $(CFLAGS) -o wordsalad_myversion input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
|
wordsalad_final: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
|
||||||
|
$(CC) $(CFLAGS) -o wordsalad_final main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
wordsalad: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
|
wordsalad: 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)
|
||||||
|
|
||||||
|
|||||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,46 @@
|
|||||||
|
# TO-DO
|
||||||
|
|
||||||
|
## Wörterplatzieren
|
||||||
|
|
||||||
|
### Step-by-Step
|
||||||
|
1. Spawning Grid Logik implementieren
|
||||||
|
1. Grid größe wählen
|
||||||
|
2. Grid mit "leeren" Werten initialisieren
|
||||||
|
3. Wörter einlesen und platzieren
|
||||||
|
1. Wort nach definierten Trennzeichen einlesen
|
||||||
|
2. Füller wie Leerzeichen und \n entfernen
|
||||||
|
3. Capitalisation fixen: gleichmäßig groß oder klein schreiben.
|
||||||
|
4. Spawn Ort finden
|
||||||
|
1. Randomly Horizontal oder Vertikal wählen
|
||||||
|
2. möglicher Bereich zum spawnen = Grid Breite bzw Höhe - Len(Wort)
|
||||||
|
5. Wort platzieren
|
||||||
|
1. Temp Duplikat des Grid anlegen
|
||||||
|
2. Ist der Spawn Ort frei ODER mit gleichen Buchstaben besetzt?
|
||||||
|
3. Buchstabe Platzieren (oder bereits vorhandenen Buchstaben lassen)
|
||||||
|
4. In Reihenfolge des Wortes vertikal oder horizontal wiederholen.
|
||||||
|
5. Bei Fehler:
|
||||||
|
1. 1.3.4. Neuen Spawn Ort finden.
|
||||||
|
2. Temp Duplikat Grid leeren
|
||||||
|
3. FehlerCounter++
|
||||||
|
1. Falls FehlerCounter >= MAX_ERLAUBTE_FEHLER
|
||||||
|
2. EXIT
|
||||||
|
6. Wort Fertig geschrieben
|
||||||
|
1. Game Grid = Temp Duplikat Grid
|
||||||
|
2. Wort in eine Liste der "platzierten Wörter" legen? Ums später zu checken?
|
||||||
|
6. Nächstes Wort einlesen
|
||||||
|
4. DONE
|
||||||
|
|
||||||
|
### Requirements
|
||||||
|
* Eine .txt Datei kann eingelesen werden
|
||||||
|
* Es wird nach den Trennzeichen: , ; . : - gefiltert um zu trennen
|
||||||
|
* Es sind nur Buchstaben erlaubt, keine Zahlen, Sonderzeichen, etc.
|
||||||
|
* Es werden beliebig viele Füller entfernt bis keine mehr enthalten sind.
|
||||||
|
* Füller sind Leading oder Trailing:
|
||||||
|
* " " (Leerzeichen)
|
||||||
|
* /n
|
||||||
|
* Füller im Wort müssen erkannt werden und Programm beenden.
|
||||||
|
* Wörter werden gleichmäßig klein ODER großgeschrieben werden und so weiterhin gespeichert werden.
|
||||||
|
* Wenn ein eingelesenes Wort länger als das Grid in Horizontal oder Vertikal ist, bricht das Programm ab
|
||||||
|
* Der Spawn Bereich wird durch die Länge des eingelesenen Wortes eingeschränkt, abhängig von Platzierungs Richtung
|
||||||
|
* Es werden nur
|
||||||
|
* Nach 20 gescheiterten Platzierungen bricht das Programm ab
|
||||||
Reference in new issue
Block a user