Compare commits
6
Commits
b9fd1b3553
...
chris3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c30711a9c | ||
|
|
1f5b8ad0a2 | ||
|
|
7eaf6e2f1f | ||
|
|
a5e963f2a6 | ||
|
|
356bb5cb9e | ||
|
|
fd89a1e5f7 |
No files matched your search
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#define MAX_RAND_TRIES_PER_WORD 10
|
#define MAX_RAND_TRIES_PER_WORD 10
|
||||||
#define EMPTY_CHAR 0
|
#define EMPTY_CHAR 0
|
||||||
|
#define WORTLAENGE strlen(words[i])
|
||||||
|
|
||||||
//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
|
||||||
@@ -13,5 +14,90 @@
|
|||||||
// 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;
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < wordCount; i++)
|
||||||
|
{
|
||||||
|
int platziert = 0;
|
||||||
|
int platzierversuche = 0;
|
||||||
|
|
||||||
|
while(platziert == 0 && platzierversuche < MAX_RAND_TRIES_PER_WORD )
|
||||||
|
{
|
||||||
|
platzierversuche++;
|
||||||
|
x = rand() % searchFieldLen;
|
||||||
|
y = rand() % searchFieldLen;
|
||||||
|
|
||||||
|
Platzierungsrichtung zufaellige_richtung = rand() % 2;
|
||||||
|
|
||||||
|
if(zufaellige_richtung == vertikal && (WORTLAENGE <= (searchFieldLen-y)))
|
||||||
|
{
|
||||||
|
int check = 0;
|
||||||
|
for(int k = 0; k < WORTLAENGE; k++)
|
||||||
|
{
|
||||||
|
if(salad[y+k][x] == '0' || salad[y+k][x] == words[i][k])
|
||||||
|
{
|
||||||
|
check ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(check == WORTLAENGE)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < WORTLAENGE; j++)
|
||||||
|
{
|
||||||
|
salad[y+j][x] = words[i][j];
|
||||||
|
}
|
||||||
|
placedWords++;
|
||||||
|
platziert = 1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else if( zufaellige_richtung == horizontal && WORTLAENGE <= (searchFieldLen-x))
|
||||||
|
{
|
||||||
|
int check = 0;
|
||||||
|
for(int k = 0; k < WORTLAENGE; k++)
|
||||||
|
{
|
||||||
|
if(salad[y][x+k] == '0' || salad[y][x+k] == words[i][k])
|
||||||
|
{
|
||||||
|
check ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(check == WORTLAENGE)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < WORTLAENGE; j++)
|
||||||
|
{
|
||||||
|
|
||||||
|
salad[y][x+j] = words[i][j];
|
||||||
|
}
|
||||||
|
placedWords++;
|
||||||
|
platziert = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i =0; i < MAX_SEARCH_FIELD_LEN; i++)
|
||||||
|
{
|
||||||
|
for( int j = 0; j < MAX_SEARCH_FIELD_LEN; j++)
|
||||||
|
{
|
||||||
|
if(salad[i][j] == '0')
|
||||||
|
{
|
||||||
|
salad[i][j] = rand() % (90-65+1)+ 65; //Großbuchstaben
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return placedWords;
|
||||||
|
}
|
||||||
+13
-8
@@ -8,25 +8,30 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
char puffer[MAX_WORD_LEN];
|
char puffer[MAX_LINE_LEN];
|
||||||
char *teiler = " ,;";
|
char *teiler = "\n ,;";
|
||||||
char *token;
|
char *token;
|
||||||
unsigned int wordCount = 0;
|
unsigned int wordCount = 0;
|
||||||
|
|
||||||
fgets(puffer, MAX_LINE_LEN, file);
|
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
|
||||||
|
{
|
||||||
token = strtok(puffer, teiler);
|
token = strtok(puffer, teiler); // Holt sich per Teilerbedingung das erste Wort aus dem puffer
|
||||||
|
|
||||||
while(token != NULL && wordCount < maxWordCount)
|
while(token != NULL && wordCount < maxWordCount)
|
||||||
{
|
{
|
||||||
strncpy(words[wordCount], token, MAX_WORD_LEN -1);
|
for(int i = 0; i < MAX_WORD_LEN; i++) //Verwandelt jeden Buchstaben in einen Großbuchstaben
|
||||||
words[wordCount][MAX_WORD_LEN - 1] = '\0';
|
{
|
||||||
|
token[i] = toupper(token[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
wordCount++;
|
wordCount++;
|
||||||
|
|
||||||
token = strtok(NULL, teiler);
|
token = strtok(NULL, teiler);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return wordCount;
|
return wordCount;
|
||||||
}
|
}
|
||||||
@@ -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
-1
@@ -41,7 +41,11 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
|
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "konnte nicht alle Woerter platzieren %d von %d \n", placedWords, wordCount);
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -29,8 +29,8 @@ wordsalad_initial:
|
|||||||
wordsalad_myversion: input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a
|
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)
|
$(CC) $(CFLAGS) -o wordsalad_myversion input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
wordsalad_2: main.o input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a
|
wordsalad_final: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
|
||||||
$(CC) $(CFLAGS) -o wordsalad_2 main.o input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
$(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)
|
||||||
|
|||||||
Reference in new issue
Block a user