Last commits of tonight
This commit is contained in:
parent
1ca4567185
commit
ebb886ae9e
@ -6,19 +6,20 @@
|
|||||||
#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 */
|
|
||||||
void emptyArray();
|
void emptyArray();
|
||||||
int placeWord();
|
int placeWord();
|
||||||
void fillEmptySpots();
|
void fillEmptySpots();
|
||||||
|
|
||||||
|
//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
|
// 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));
|
srand(time(NULL));
|
||||||
emptyArray(salad,MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN);
|
emptyArray(salad,MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN);
|
||||||
placeWord(salad,words);
|
placeWord(salad,words);
|
||||||
fillEmptySpots(salad);
|
fillEmptySpots(salad, MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the word salad to console
|
// Prints the word salad to console
|
||||||
@ -46,10 +47,35 @@ void emptyArray(char array[][], int arrayLength)
|
|||||||
|
|
||||||
int placeWord(char intoArray[][], char insertedWord[][])
|
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 useArray[][])
|
void fillEmptySpots(char array[][], int arrayLength)
|
||||||
{
|
{
|
||||||
|
char* element = (char*) &array;
|
||||||
|
for(int i = 0; i < arrayLength; i++ )
|
||||||
|
{
|
||||||
|
if(*element == EMPTY_CHAR)
|
||||||
|
{
|
||||||
|
*element == rand() % ('Z' - 'A' + 1) + 'A';
|
||||||
|
}
|
||||||
|
element++;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -2,7 +2,6 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei
|
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei
|
||||||
// (words.txt) einliest und als C-String zurückgibt.
|
// (words.txt) einliest und als C-String zurückgibt.
|
||||||
|
|
||||||
@ -12,7 +11,7 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN],unsigned int maxWordCount)
|
|||||||
file = fopen("words.txt", "r");
|
file = fopen("words.txt", "r");
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char teiler[] = " ;,.\n";
|
char teiler[] = " ;,.\n";
|
||||||
@ -32,6 +31,6 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN],unsigned int maxWordCount)
|
|||||||
aktuellesWort = strtok(NULL, teiler); // Nächstes Token
|
aktuellesWort = strtok(NULL, teiler); // Nächstes Token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fclose(file);
|
||||||
return wortAnzahl; // Anzahl der eingelesenen Wörter
|
return wortAnzahl; // Anzahl der eingelesenen Wörter
|
||||||
}
|
}
|
||||||
@ -38,8 +38,17 @@ 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
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// error message if some words couldn't be placed
|
||||||
|
fprintf(stderr, "Could not place every word \n");
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user