Compare commits

..

25 Commits
Alexei ... main

Author SHA1 Message Date
maxgrf
e551a025be main updated 2025-11-10 12:39:33 +01:00
maxgrf
b427e8e547 update 2 2025-11-10 11:57:39 +01:00
maxgrf
5f567fa968 update game.c 2025-11-10 11:55:24 +01:00
maxgrf
36bfbcb156 update makefile 2025-11-10 11:53:21 +01:00
maxgrf
a78c1e2ea2 testphrases deleted + all test for input passed 2025-11-07 17:25:34 +01:00
maxgrf
c18b6a4529 test12! 2025-11-07 17:17:54 +01:00
maxgrf
013eba7b3d test13 2025-11-06 16:44:13 +01:00
maxgrf
cd3dd0a4d6 test12 2025-11-06 16:43:06 +01:00
maxgrf
b9138e2097 test11 2025-11-06 16:41:45 +01:00
maxgrf
28a2aa1ea1 test10 2025-11-06 16:35:30 +01:00
maxgrf
cddbfb3029 test9 2025-11-06 16:23:36 +01:00
maxgrf
5c1aea7a88 test8 2025-11-06 16:18:53 +01:00
maxgrf
f47f3aef7c test7 2025-11-06 16:17:55 +01:00
maxgrf
b34074233d test5 2025-11-06 16:15:25 +01:00
maxgrf
bbad6afd45 test4 2025-11-06 16:12:26 +01:00
maxgrf
9e172b664f update 2025-11-06 15:59:21 +01:00
maxgrf
c26a55f965 endloschleife2 2025-11-06 15:50:21 +01:00
maxgrf
16b0b9a450 endlosschleife behoben 2025-11-06 15:43:10 +01:00
maxgrf
85a79e9235 test2 2025-11-06 15:35:37 +01:00
maxgrf
506c091bf6 test1 2025-11-06 15:31:01 +01:00
maxgrf
4fea2c9f7b input 2025-11-06 11:30:49 +01:00
maxgrf
817f35a154 input bugfix 2025-11-06 11:26:13 +01:00
maxgrf
19787739a7 input fix strtok 2025-11-04 22:25:36 +01:00
maxgrf
3657ee5ff7 input filled with logic 2025-11-03 22:24:46 +01:00
maxgrf
099243b5e2 makefile reload 2025-11-03 21:44:04 +01:00
14 changed files with 101 additions and 102 deletions

View File

@ -2,125 +2,123 @@
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#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: //TODO: Spiellogik implementieren:
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren /* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
* restliche Felder mit zufälligen Buchstaben füllen */ * 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)
{
int addedWords = 0;
int attempts = 0;
int added = 0; // = 1 wäre Wort hinzugefügt
int space = 0; // = 1 wäre Wort zu lang für diese Stelle
unsigned long long wordLength = 0;
srand(time(NULL)); srand(time(NULL));
int placedWords = 0;
for (int i = 0; i < searchFieldLen; i++) // Array mit . füllen
{ for (int r = 0; r < searchFieldLen; r++){
for (int j = 0; j < searchFieldLen; j++) for(int s = 0; s < searchFieldLen; s++){
{ salad[r][s] = '.';
salad[i][j] = '.'; //Füllen des gesamten Arrays mit '.'
} }
} }
for (int i=0; i < wordCount; i++)
{
wordLength = strlen(words[i]);
while (attempts <= MAX_RAND_TRIES_PER_WORD && added != 1)
{
int direction = rand() % 2;// 0 = Horizontal, 1 = Vertikal
if (direction == 0) //Horizontal
{
int spalte = rand() % searchFieldLen;
int reihe = rand() % searchFieldLen;
for (int j = 0; j < wordLength; j++)
{
if (salad[reihe][spalte+j] != '.') //Prüfen das Wort mit einem anderem Wort überlappen würde
{
space = 1;
break;
}
} // -> erst wenn die ganze Länge des Wortes frei ist, array hinzufügen
if ((spalte + wordLength >= searchFieldLen-1) || (space == 1)) // überprüfung, ob das Wort an der Stelle ins Array passt // MAX Versuche das Wort zu platzieren == 10
{
attempts++;
}
else // Wörter in salad einsortieren
{ for (int num_words = 0; num_words < wordCount; num_words++){
for (int j = 0; j < wordLength; j++)
{ int laenge = strlen(words[num_words]);
salad[reihe][spalte+j] = words[i][j]; //Einfügen er Chars des Wortes
} // muss noch prüfen, ob in der Zeile schon was ist
added=1; // 1 ist horizontal, 0 ist vertikal
addedWords++; // isalpha == 0 -> kein Buchstabe
}
} for(int versuch = 0; versuch < MAX_RAND_TRIES_PER_WORD; versuch++){
else if (direction == 1) // Vertikal int richtung = rand()% 2;
{ int belegt = 0;
int spalte = rand() % searchFieldLen;
int reihe = rand() % searchFieldLen; // horizontale Eingabe
for (int j = 0; j < wordLength; j++) if (richtung == 1){
{ int zeile = rand()% searchFieldLen;
if (salad[reihe+j][spalte] != '.') int spalte = rand()% (searchFieldLen- laenge +1);
{
space = 1; //prüft, ob die herausgesuchte Zeile noch frei ist
// belegt == 1 -> Zeile nicht frei
for (int o = spalte; o < spalte + laenge; o++){
if(salad[zeile][o] != '.'){
belegt = 1;
break; break;
} }
} }
if ((reihe + wordLength >= searchFieldLen-1) || (space == 1)) // setzt in das Array ein, wenn frei oder erhöht die Versuchsanzahl
{ if (belegt == 0){
attempts++; for(int k = 0; k < laenge; k++){
salad[zeile][spalte + k] = words[num_words][k];
}
placedWords++;
break;
}
}
// vertikale Eingabe
else if (richtung == 0){
int zeile = rand()% (searchFieldLen - laenge +1);
int spalte = rand()% searchFieldLen;
//prüft, ob die herausgesuchte Zeile noch frei ist
for (int n = zeile; n < zeile + laenge; n++){
if(salad[n][spalte] != '.'){
belegt = 1;
break;
}
}
// setzt in das Array ein, wenn frei oder erhöht die Versuchsanzahl
if (belegt == 0){
for(int j = 0; j < laenge; j++){
salad[zeile + j][spalte] = words[num_words][j];
}
placedWords++;
break;
}
}
else{
break;
}
} }
}
else // fügt zufällige Buchstaben ein
{ for(int l = 0; l < searchFieldLen; l++){
for (int j = 0; j < wordLength; j++) for(int m = 0; m < searchFieldLen; m++ ){
{ if(isalpha(salad[l][m]) == 0 ){
salad[reihe+j][spalte] = words[i][j]; // zufällige Buchstaben erzeugen
} char alphabet [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
added=1; int laenge = strlen(alphabet);
addedWords++; int zufallszahl = rand()% laenge;
} char zufallsbuchstabe = alphabet[zufallszahl];
} // zufällige Buchstaben einfügen
space = 0; salad[l][m] = zufallsbuchstabe;
}
attempts = 0;
added = 0;
}
for (int i = 0; i < searchFieldLen; i++)
{
for (int j = 0; j < searchFieldLen; j++)
{
if (salad[i][j] == '.')
{
salad[i][j] = rand()%('Z'-'A'+1)+'A';//Zufällige Befüllung der noch nicht befüllten Felder
} }
} }
} }
return addedWords;
return placedWords;
} }
// Prints the word salad to console // Prints the word salad to console
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
{ {
for(int i = 0; i < searchFieldLen; i++) for(int p = 0; p < searchFieldLen; p++){
{ for(int q = 0; q < searchFieldLen; q++){
for(int j = 0; j < searchFieldLen; j++) printf("%c", salad[p][q]);
{ }
printf("%c", salad[i][j]);//Ausgabe des Arrays auf die Konsole printf("\n");
}
} }
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -38,18 +38,16 @@ int main(int argc, char *argv[])
// TODO: // TODO:
// Check if all words were successfully placed // Check if all words were successfully placed
if(wordCount == placedWords) // Start the game if successful
{ // error message if some words couldn't be placed
exitCode = EXIT_SUCCESS; if (placedWords == wordCount){
startGame(wordSalad,SALAD_SIZE,words, wordCount,750); startGame(wordSalad,SALAD_SIZE,words, wordCount,750);
} }
else else
{ {
exitCode = EXIT_FAILURE;
printf("Error. The words couldn't be placed.\n"); printf("Error. The words couldn't be placed.\n");
return -1;
} }
// Start the game if successful
// error message if some words couldn't be placed
} }
else else

Binary file not shown.

View File

@ -47,4 +47,3 @@ clean:
wordsalad_myversion: main.o input.o game.o graphicalGame.o wordsalad_myversion: main.o input.o game.o graphicalGame.o
$(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS) $(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)

BIN
Start_Windows/runTests2.exe Normal file

Binary file not shown.

View File

@ -0,0 +1 @@
Hund,Katze; Maus

View File

View File

@ -0,0 +1,3 @@
Apfel
Banane
Kiwi

Binary file not shown.

Binary file not shown.

Binary file not shown.