generated from freudenreichan/info2Praktikum-Wortsalat
1.Test game
This commit is contained in:
parent
19787739a7
commit
45fb1f651b
@ -13,6 +13,73 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
wordSalad: char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN] -> bereits definiert
|
||||||
|
searchFieldLen: SALAD_SIZE = 20
|
||||||
|
words: words_array
|
||||||
|
wordcount: Anzahl der eingelesen Wörter
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
// 1. Schritt: Alle Felder mit zufälligen Zahlen befüllen
|
||||||
|
srand(time(NULL)); //Seed zufällig ändern
|
||||||
|
int size_word;
|
||||||
|
int placed_words;
|
||||||
|
|
||||||
|
for(int m = 0; m < searchFieldLen; m++) //m Zeilen
|
||||||
|
{
|
||||||
|
for(int n = 0; n < searchFieldLen; n++) //n Spalte
|
||||||
|
{
|
||||||
|
salad[m][n] = 'A' + rand() % 26; //ASCII-Form
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
// 2. Schritt: Wörter in das Array überschreiben
|
||||||
|
|
||||||
|
for(int i = 0; i < wordCount && i < searchFieldLen; i++) //eingelesen Wörter zählen + Länge des Feldes nicht überschreiten
|
||||||
|
{
|
||||||
|
size_t len = strlen(words[i]); //Größe des Wortes ermitteln
|
||||||
|
|
||||||
|
if (len < searchFieldLen)
|
||||||
|
return -1; //ERROR, falls Wort größer als Größe des Feldes, unnötig, da bei worteingabe bereitsüberprüft
|
||||||
|
|
||||||
|
unsigned int succesfully_placed = 0;
|
||||||
|
unsigned int tries = 0;
|
||||||
|
|
||||||
|
while(succesfully_placed == 0 && tries < MAX_RAND_TRIES_PER_WORD)
|
||||||
|
{
|
||||||
|
// zufälliger Startpunkt
|
||||||
|
int row = rand() % searchFieldLen; // Reihe
|
||||||
|
int col = rand() % searchFieldLen; // Spalte
|
||||||
|
|
||||||
|
// zufällige Richtung auswählen
|
||||||
|
int direction = rand() % 2; // 0 = VERTIKAL, 1 = HORIZONTAL
|
||||||
|
|
||||||
|
// Prüfen der Länge in Richtung, sodass Feld nicht überschritten
|
||||||
|
int fitsin = 1;
|
||||||
|
|
||||||
|
for(int t = 0; t < len; t++)
|
||||||
|
{
|
||||||
|
if(direction = 0)
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prüfen, ob bereits buchstaben in dem Feld sich befinden, bzw. der Buchstabe mit dem anderen übereinstimmt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(xxx)
|
||||||
|
{
|
||||||
|
succesfully_placed = 1; // erfolgreich eingefügt
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return placedWords;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,3 +88,4 @@ void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
BIN
Start_Windows/runTests.exe
Normal file
BIN
Start_Windows/runTests.exe
Normal file
Binary file not shown.
BIN
Start_Windows/unity/unity.o
Normal file
BIN
Start_Windows/unity/unity.o
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user