117 lines
3.4 KiB
C
117 lines
3.4 KiB
C
#include "game.h"
|
|
#include <time.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define MAX_RAND_TRIES_PER_WORD 10
|
|
#define EMPTY_CHAR 0
|
|
|
|
//Position beinhaltet x, y und Richtung
|
|
//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)
|
|
{
|
|
Position position[1520]; //Positionsarray, 1520, weil 2 Richtungen, minimalwort größe
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
// Prints the word salad to console
|
|
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
|
{
|
|
|
|
}
|
|
//Logik für createWordSalad: Ein Wort nach dem anderen bis entweder alle Wörter drinnen,
|
|
//Funktion dafür den gesammten Salat mit . zu befüllen.
|
|
void clearWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
|
{
|
|
for(unsigned int zeile = 0; zeile < searchFieldLen; zeile++)
|
|
{
|
|
for(unsigned int spalte = 0; spalte < searchFieldLen; spalte++)
|
|
{
|
|
salad[zeile][spalte] = '.'; // salad wird mit Punkten befüllt.
|
|
}
|
|
}
|
|
}
|
|
//Funktion für den Schluss: Übrige leere stellen werden random befüllt.
|
|
void fillWordsaladRand(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
|
{
|
|
srand(time(NULL));
|
|
for(int i = 0; i < searchFieldLen; i++)
|
|
{
|
|
for(int k = 0; k < searchFieldLen; k++)
|
|
{
|
|
if(salad[i][k] == '.')
|
|
{
|
|
salad[i][k] = 'A' + rand() % 26;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int findPossiblePositions(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], int wordidx, Position positions[])
|
|
{
|
|
char *word = words[wordidx];
|
|
int wordlen = strlen(word);
|
|
int positionamount = 0;
|
|
int rechtsfrei = 1;
|
|
int untenfrei = 1;
|
|
for(int i = 0; i < searchFieldLen; i++)
|
|
{
|
|
for(int k = 0; k < searchFieldLen; k++)
|
|
{
|
|
rechtsfrei = 1;
|
|
untenfrei = 1;
|
|
if(salad[i][k] == '.')
|
|
{
|
|
//nach rechts prüfen
|
|
if(searchFieldLen - k >= wordlen)
|
|
{
|
|
for(int p = k +1; p < k+ wordlen; p++)
|
|
{
|
|
if(salad[i][p] != '.')
|
|
{
|
|
rechtsfrei = 0;
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
//nach unten prüfen
|
|
if(searchFieldLen - i >= wordlen)
|
|
{
|
|
for(int q = i+1; q < i+ wordlen; q++)
|
|
{
|
|
if(salad[q][k] != '.')
|
|
{
|
|
untenfrei = 0;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if(rechtsfrei)
|
|
{
|
|
positions[positionamount].x = k;
|
|
positions[positionamount].y = i;
|
|
positions[positionamount].richt = RECHTS;
|
|
positionamount++;
|
|
}
|
|
if(untenfrei)
|
|
{
|
|
positions[positionamount].x = k;
|
|
positions[positionamount].y = i;
|
|
positions[positionamount].richt = UNTEN;
|
|
positionamount++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return positionamount;
|
|
|
|
} |