Template
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0bd8b46ea | ||
|
|
f8ca49c9c6 | ||
|
|
689456bbba | ||
|
|
01b1660858 | ||
|
|
0ee1c4e689 | ||
|
|
c93dd9a734 |
No files matched your search
+2
-1
@@ -35,9 +35,10 @@
|
|||||||
*.i*86
|
*.i*86
|
||||||
*.x86_64
|
*.x86_64
|
||||||
*.hex
|
*.hex
|
||||||
|
Startcode/wordsalad_myversion
|
||||||
Startcode/wordsalad_initial
|
Startcode/wordsalad_initial
|
||||||
Startcode/wordsalad
|
Startcode/wordsalad
|
||||||
test
|
runtest
|
||||||
|
|
||||||
# Debug files
|
# Debug files
|
||||||
*.dSYM/
|
*.dSYM/
|
||||||
|
|||||||
+61
-5
@@ -6,12 +6,68 @@
|
|||||||
#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:
|
|
||||||
/* * 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 searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
||||||
{
|
{
|
||||||
|
int row, col, word, startcol=0, startrow=0, placedWord=0;
|
||||||
|
srand(time(NULL));
|
||||||
|
for(row=0; row<MAX_SEARCH_FIELD_LEN; row++)
|
||||||
|
{
|
||||||
|
for(col=0; col<MAX_SEARCH_FIELD_LEN; col++)
|
||||||
|
{
|
||||||
|
salad[row][col] = EMPTY_CHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (word=0; word<wordCount; word++)
|
||||||
|
{
|
||||||
|
if (rand() % 2 == 0) //horizontal
|
||||||
|
{
|
||||||
|
startcol = rand() % (MAX_SEARCH_FIELD_LEN - strlen(words[word])+1);
|
||||||
|
startrow = rand() % MAX_SEARCH_FIELD_LEN;
|
||||||
|
for (int i=0; i<strlen(words[word]); i++)
|
||||||
|
{
|
||||||
|
salad[startrow][startcol+i] = words[word][i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else //vertikal
|
||||||
|
{
|
||||||
|
startrow = rand() % (MAX_SEARCH_FIELD_LEN - strlen(words[word])+1);
|
||||||
|
startcol = rand() % MAX_SEARCH_FIELD_LEN;
|
||||||
|
for (int j=0; j<strlen(words[word]); j++)
|
||||||
|
{
|
||||||
|
salad[startrow+j][startcol] = words[word][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
placedWord++;
|
||||||
|
if (rand()%26 !=0)
|
||||||
|
{
|
||||||
|
printf("%c",EMPTY_CHAR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (row=0; row<MAX_SEARCH_FIELD_LEN; row++)
|
||||||
|
{
|
||||||
|
for (col=0; col<MAX_SEARCH_FIELD_LEN; col++)
|
||||||
|
{
|
||||||
|
if (salad[row][col] == EMPTY_CHAR)
|
||||||
|
{
|
||||||
|
salad[row][col] = rand()%26+'A';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (row=0; row<MAX_SEARCH_FIELD_LEN; row++)
|
||||||
|
{
|
||||||
|
for (col=0; col<MAX_SEARCH_FIELD_LEN; col++)
|
||||||
|
{
|
||||||
|
printf("%c", salad[row][col]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
printf("\n\nPlatzierung abgeschlossen\n\n");
|
||||||
|
|
||||||
|
if(placedWord==word)
|
||||||
|
{
|
||||||
|
return placedWord;
|
||||||
|
} else return 0;
|
||||||
}
|
}
|
||||||
@@ -8,5 +8,26 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
|
if (file == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
char line[MAX_LINE_LEN];
|
||||||
|
unsigned int count = 0;
|
||||||
|
|
||||||
|
while (fgets(line, sizeof(line), file) != NULL && count < maxWordCount) {
|
||||||
|
char *token = strtok(line, " ,;\n\r\t");
|
||||||
|
while (token != NULL & count < maxWordCount) {
|
||||||
|
if (strlen(token) > 0) {
|
||||||
|
strncpy(words[count], token, MAX_WORD_LEN - 1);
|
||||||
|
words[count][MAX_WORD_LEN - 1] = '\0';
|
||||||
|
for (int i= 0; words[count][i] != '\0'; i++) {
|
||||||
|
words[count][i] = toupper((unsigned char)words[count][i]);
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
token = strtok(NULL, " ,;\n\r\t");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
|
||||||
}
|
}
|
||||||
+12
-3
@@ -38,9 +38,18 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// Check if all words were successfully placed
|
// Check if all words were successfully placed
|
||||||
// Start the game if successful
|
if (placedWords == wordCount)
|
||||||
// error message if some words couldn't be placed
|
{
|
||||||
|
// Start the game if successful
|
||||||
|
startGame(wordSalad, SALAD_SIZE, words, wordCount, 600);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// error message if some words couldn't be placed
|
||||||
|
fprintf(stderr, "Fehler. Es konnten nicht alle Wörter Platziert werden.");
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
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)
|
||||||
|
|
||||||
|
# Eigenes Target
|
||||||
|
|
||||||
|
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
|
||||||
# --------------------------
|
# --------------------------
|
||||||
|
|||||||
Reference in new issue
Block a user