Compare commits
No commits in common. "ebb886ae9e2ee09cdea397078dc5802e5629249a" and "bda3c2b1047a3a2c7759095f80e615f9050072a7" have entirely different histories.
ebb886ae9e
...
bda3c2b104
@ -6,20 +6,19 @@
|
||||
#define MAX_RAND_TRIES_PER_WORD 10
|
||||
#define EMPTY_CHAR 0
|
||||
|
||||
void emptyArray();
|
||||
int placeWord();
|
||||
void fillEmptySpots();
|
||||
|
||||
//TODO: Spiellogik implementieren:
|
||||
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||
void emptyArray();
|
||||
int placeWord();
|
||||
void fillEmptySpots();
|
||||
// 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)
|
||||
{
|
||||
srand(time(NULL));
|
||||
emptyArray(salad,MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN);
|
||||
placeWord(salad,words);
|
||||
fillEmptySpots(salad, MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN);
|
||||
fillEmptySpots(salad);
|
||||
}
|
||||
|
||||
// Prints the word salad to console
|
||||
@ -47,35 +46,10 @@ void emptyArray(char array[][], int arrayLength)
|
||||
|
||||
int placeWord(char intoArray[][], char insertedWord[][])
|
||||
{
|
||||
int numberWord;
|
||||
int tries;
|
||||
while(tries <= MAX_RAND_TRIES_PER_WORD)
|
||||
{
|
||||
int xCord = rand() % MAX_SEARCH_FIELD_LEN;
|
||||
int yCord = rand() % MAX_SEARCH_FIELD_LEN;
|
||||
int isHorizontal = rand() % 2;
|
||||
|
||||
if(isHorizontal)
|
||||
{
|
||||
if(xCord + sizeof(insertedWord[numberWord][0]) <= MAX_SEARCH_FIELD_LEN)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void fillEmptySpots(char array[][], int arrayLength)
|
||||
void fillEmptySpots(char useArray[][])
|
||||
{
|
||||
char* element = (char*) &array;
|
||||
for(int i = 0; i < arrayLength; i++ )
|
||||
{
|
||||
if(*element == EMPTY_CHAR)
|
||||
{
|
||||
*element == rand() % ('Z' - 'A' + 1) + 'A';
|
||||
}
|
||||
element++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -2,26 +2,28 @@
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
// TODO:
|
||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei
|
||||
// (words.txt) einliest und als C-String zurückgibt.
|
||||
|
||||
// Read words from file and store in 'words' array
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN],unsigned int maxWordCount)
|
||||
{
|
||||
char puffer[MAX_WORD_LEN];
|
||||
file = fopen("words.txt", "r");
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
return -1;
|
||||
perror("File couldn't be opened");
|
||||
}
|
||||
|
||||
char teiler[] = " ;,.\n";
|
||||
char fehlerhafterString[MAX_LINE_LEN];
|
||||
char *teiler = " ;,.\n";
|
||||
char *aktuellesWort;
|
||||
int wortAnzahl = 0;
|
||||
|
||||
while (fgets(puffer, MAX_WORD_LEN, file) != NULL)
|
||||
while (fgets(fehlerhafterString, sizeof(fehlerhafterString), file) != NULL && wortAnzahl < maxWordCount)
|
||||
{
|
||||
|
||||
aktuellesWort = strtok(puffer, teiler);
|
||||
aktuellesWort = strtok(fehlerhafterString, teiler);
|
||||
|
||||
while (aktuellesWort != NULL && wortAnzahl < maxWordCount)
|
||||
{
|
||||
@ -31,6 +33,6 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN],unsigned int maxWordCount)
|
||||
aktuellesWort = strtok(NULL, teiler); // Nächstes Token
|
||||
}
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
return wortAnzahl; // Anzahl der eingelesenen Wörter
|
||||
}
|
||||
@ -38,17 +38,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
// TODO:
|
||||
// Check if all words were successfully placed
|
||||
if(placedWords == wordCount)
|
||||
{
|
||||
// Start the game if successful
|
||||
}
|
||||
else
|
||||
{
|
||||
// error message if some words couldn't be placed
|
||||
fprintf(stderr, "Could not place every word \n");
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Start the game if successful
|
||||
// error message if some words couldn't be placed
|
||||
|
||||
}
|
||||
else
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user