Compare commits

..

37 Commits
main ... Alexei

Author SHA1 Message Date
195ce39698 final changes to game.c 2025-11-10 15:03:49 +01:00
8bff068cee changes to game.c 2025-11-10 15:01:36 +01:00
ff8384e9ee changes to game.c 2025-11-10 14:54:06 +01:00
cbf834ab76 changes to game.c 2025-11-10 14:53:23 +01:00
249298afc6 changes to game.c 2025-11-10 14:52:05 +01:00
6d8371d487 test 23 2025-11-10 14:13:31 +01:00
20465e1dc2 test 22 2025-11-10 13:52:14 +01:00
80dac61be4 test 21 2025-11-10 13:50:48 +01:00
99a0600fd2 test 20 2025-11-10 12:54:14 +01:00
e8ba3293a6 test 19 2025-11-10 12:49:50 +01:00
16134abad0 test 18 2025-11-10 12:34:10 +01:00
9ab08b84f6 test 17 2025-11-10 12:12:25 +01:00
36b117b57e test 16 2025-11-10 12:09:41 +01:00
71db293343 Finale Version 2025-11-07 23:20:36 +01:00
256be70364 Final Version 2025-11-07 23:18:58 +01:00
c316d20fa1 test 15 2025-11-07 19:01:01 +01:00
31ed3191de test 14 2025-11-07 18:35:39 +01:00
80e6bd2b05 test 13 2025-11-07 18:31:31 +01:00
983d35c825 test 12 2025-11-07 18:30:34 +01:00
17f86eeb71 test 11 2025-11-07 18:27:36 +01:00
aaa6721f1c test 10 2025-11-07 18:23:15 +01:00
0be4a141c7 test 9 2025-11-07 14:16:54 +01:00
2b8775fdda test 8.2 2025-11-07 14:14:45 +01:00
650917b365 test 8 2025-11-07 14:08:25 +01:00
b8f395aedb test 7 2025-11-06 16:46:58 +01:00
aa61e44a0e test6 2025-11-06 16:39:16 +01:00
994ec48f9e test 5 2025-11-06 16:37:42 +01:00
d0dd0b0892 test 4 2025-11-06 16:36:34 +01:00
60f27b7db7 test3 2025-11-06 16:35:17 +01:00
e19dddf91d test 2 2025-11-06 16:33:49 +01:00
51b54badda test main 2025-11-06 16:32:17 +01:00
6adbaf539e trying to bugfix 2025-11-06 15:28:37 +01:00
f3b58a6150 included ctype.h 2025-11-06 15:26:29 +01:00
0b1aa615e7 changes to isalpha l104 2025-11-06 15:22:27 +01:00
328931806c Bugfix 2025-11-06 15:20:03 +01:00
111d1ce238 Test 2025-11-06 15:17:28 +01:00
1fb5db8a4f input bearbeitet 2025-11-06 11:47:49 +01:00
14 changed files with 101 additions and 100 deletions

View File

@ -2,123 +2,125 @@
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#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)
{
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));
int placedWords = 0;
// Array mit . füllen
for (int r = 0; r < searchFieldLen; r++){
for(int s = 0; s < searchFieldLen; s++){
salad[r][s] = '.';
for (int i = 0; i < searchFieldLen; i++)
{
for (int j = 0; j < searchFieldLen; j++)
{
salad[i][j] = '.'; //Füllen des gesamten Arrays mit '.'
}
}
// -> erst wenn die ganze Länge des Wortes frei ist, array hinzufügen
// MAX Versuche das Wort zu platzieren == 10
for (int i=0; i < wordCount; i++)
{
// Wörter in salad einsortieren
for (int num_words = 0; num_words < wordCount; num_words++){
int laenge = strlen(words[num_words]);
// muss noch prüfen, ob in der Zeile schon was ist
// 1 ist horizontal, 0 ist vertikal
// isalpha == 0 -> kein Buchstabe
wordLength = strlen(words[i]);
for(int versuch = 0; versuch < MAX_RAND_TRIES_PER_WORD; versuch++){
int richtung = rand()% 2;
int belegt = 0;
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;
}
}
if ((spalte + wordLength >= searchFieldLen-1) || (space == 1)) // überprüfung, ob das Wort an der Stelle ins Array passt
{
attempts++;
}
// horizontale Eingabe
if (richtung == 1){
int zeile = rand()% searchFieldLen;
int spalte = rand()% (searchFieldLen- laenge +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;
else
{
for (int j = 0; j < wordLength; j++)
{
salad[reihe][spalte+j] = words[i][j]; //Einfügen er Chars des Wortes
}
added=1;
addedWords++;
}
}
else if (direction == 1) // Vertikal
{
int spalte = rand() % searchFieldLen;
int reihe = rand() % searchFieldLen;
for (int j = 0; j < wordLength; j++)
{
if (salad[reihe+j][spalte] != '.')
{
space = 1;
break;
}
}
// setzt in das Array ein, wenn frei oder erhöht die Versuchsanzahl
if (belegt == 0){
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;
}
if ((reihe + wordLength >= searchFieldLen-1) || (space == 1))
{
attempts++;
}
// 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];
else
{
for (int j = 0; j < wordLength; j++)
{
salad[reihe+j][spalte] = words[i][j];
}
placedWords++;
break;
}
}
else{
break;
added=1;
addedWords++;
}
}
space = 0;
}
attempts = 0;
added = 0;
}
// fügt zufällige Buchstaben ein
for(int l = 0; l < searchFieldLen; l++){
for(int m = 0; m < searchFieldLen; m++ ){
if(isalpha(salad[l][m]) == 0 ){
// zufällige Buchstaben erzeugen
char alphabet [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int laenge = strlen(alphabet);
int zufallszahl = rand()% laenge;
char zufallsbuchstabe = alphabet[zufallszahl];
// zufällige Buchstaben einfügen
salad[l][m] = zufallsbuchstabe;
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 placedWords;
}
return addedWords;
}
// Prints the word salad to console
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
{
for(int p = 0; p < searchFieldLen; p++){
for(int q = 0; q < searchFieldLen; q++){
printf("%c", salad[p][q]);
for(int i = 0; i < searchFieldLen; i++)
{
for(int j = 0; j < searchFieldLen; j++)
{
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,17 +38,19 @@ int main(int argc, char *argv[])
// TODO:
// Check if all words were successfully placed
if(wordCount == placedWords)
{
exitCode = EXIT_SUCCESS;
startGame(wordSalad,SALAD_SIZE, words,wordCount,750);
}
else
{
exitCode = EXIT_FAILURE;
printf("Error. The words couldn't be placed.\n");
}
// Start the game if successful
// error message if some words couldn't be placed
if (placedWords == wordCount){
startGame(wordSalad,SALAD_SIZE,words, wordCount,750);
}
else
{
printf("Error. The words couldn't be placed.\n");
return -1;
}
}
else
{

BIN
Start_Windows/main.o Normal file

Binary file not shown.

View File

@ -46,4 +46,5 @@ clean:
#hier eigene wordsalad kopieren, library rauslassen
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)

Binary file not shown.

View File

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

View File

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

Binary file not shown.

Binary file not shown.

BIN
Start_Windows/wordsalad.exe Normal file

Binary file not shown.