Compare commits

...
6 Commits
3 changed files with 95 additions and 11 deletions

No files matched your search

+89 -5
View File
@@ -6,12 +6,96 @@
#define MAX_RAND_TRIES_PER_WORD 10
#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)
//salad = Array das als Tabelle dient; searchFieldLEN = tatsächliche Länge des Spielfelds; words = Liste der möglichen Suchwörter; wordCount = Anzahl der Wörter in words
{
//1. Spielfeld salad leeren; (Leeres Feld erstellen)
srand(time(NULL));
for (unsigned int breite = 0; breite < searchFieldLen; breite++)
{
for (unsigned int hoehe = 0; hoehe < searchFieldLen; hoehe++)
{
salad[hoehe][breite] = EMPTY_CHAR;
}
}
//2. Wortliste word durchgehen; (Wortlängen bestimmen)
int plaziert = 0; //Wort plaziert?;
for (unsigned i = 0; i < wordCount; i++)
{
unsigned int wortlaenge = strlen(words[i]); //Strlen gibt die länge der Zeichenkette an
if (wortlaenge == 0) //Leere Listenplätze werden Übersprungen
{
continue;
}
if (wortlaenge > searchFieldLen) //Falls das Wort zu lange ist Überspringe
{
continue;;
}
//3. Startpunkt für Wörter festlegen (Platzierung der Wörter)
for (unsigned int versuch = 0; versuch < MAX_RAND_TRIES_PER_WORD; versuch++)
{
unsigned int x_position = rand() % searchFieldLen; //Startpunkt in x Richtung wählen
unsigned int y_position = rand() % searchFieldLen; //Startpunkt in y Richtung wählen
int richtung = rand() % 2; //Richtung festlegen; 0 = waagerecht; 1 = senkrecht
if (richtung == 0 && wortlaenge > searchFieldLen - x_position) //Waagerecht Platz prüfen
{
continue;
}
if (richtung == 1 && wortlaenge > searchFieldLen - y_position) //Senkrecht Platz prüfen
{
continue;
}
int check = 0; //Wort passt an die ausgewählte Position?; 1 = fail
for (unsigned int j = 0; j < wortlaenge; j++) //Felder auf leere prüfen
{
unsigned int x_positionrest = x_position;
unsigned int y_positionrest = y_position;
if (richtung == 0)
{
x_positionrest += j;
}
else
{
y_positionrest += j;
}
if (salad[y_positionrest][x_positionrest] != EMPTY_CHAR)
{
check = 1;
break;
}
}
//4. Eingabe der Wörter; (Wörter eintragen)
if (!check)
{
for (unsigned int j = 0; j < wortlaenge; j++)
{
if(richtung == 0)
{
salad[y_position][x_position + j] = words[i][j];
}
else
{
salad[y_position + j][x_position] = words[i][j];
}
}
plaziert++;
break;
}
}
}
//5. Freie Felder mit Zufallsbuchstaben befüllen; (leere Felder Füllen)
for (unsigned int x_position = 0; x_position < searchFieldLen; x_position++)
{
for (unsigned int y_position = 0; y_position < searchFieldLen; y_position++)
{
if (salad[y_position][x_position] == EMPTY_CHAR)
{
salad[y_position][x_position] = 'A' + rand() % 26;
}
}
}
//6. Endergebnis zurückgeben; (Rückgabewert)
return plaziert;
}
+1 -1
View File
@@ -38,7 +38,7 @@ int main(int argc, char *argv[])
if (wordCount == placedWords)
{
startGame(wordSalad, SALAD_SIZE, words, wordCount, 1000);
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
}
else
{
+5 -5
View File
@@ -26,11 +26,11 @@ wordsalad_initial:
# Zwischenstände:
# --------------------------
# Only main
wordsalad_mymain: main.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad_mymain main.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
# Main + Input
wordsalad_myinput: main.o input.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad_myinput main.o input.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
wordsalad_mymain: main.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad_mymain main.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
# Input
wordsalad_myinput: input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad_myinput input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
# --------------------------
# Normales Spiel bauen