Compare commits

...
21 Commits
Author SHA1 Message Date
kegelmannni100026 d5587ef787 kommentare bei mac 2025-10-27 14:27:18 +01:00
stammjo100588 d61e703a42 Actual final commit? :> 2025-10-27 14:20:25 +01:00
starksa100587 5d8f68558e Target makefile 2025-10-27 14:17:42 +01:00
stammjo100588 00e3a50e8e One final Comment. And Goodbye World! 2025-10-27 14:05:58 +01:00
starksa100587 6ecb30fdfe Updated comments 2025-10-26 20:30:30 +01:00
stammjo100588 69decc037a |WORKING| All Test OK and Game runs! 2025-10-24 22:29:03 +02:00
stammjo100588 a1cb0f9626 Changed Input.c to solve All Remaining Tests 2025-10-24 22:16:55 +02:00
stammjo100588 000bc1ebdf Changed Input.c to solve Test 2 & 3 Aswell 2025-10-24 22:09:30 +02:00
kegelmannni100026 713355b1ac Game und input bei mac geändert
input bei win geändert

unittests: 3 SUCCESS 2 FAIL
2025-10-24 22:01:21 +02:00
stammjo100588 2a71e61f96 in game.c Version des CODES im Kommentar 2025-10-24 20:34:36 +02:00
stammjo100588 423506b80d revert 0a627137fa
revert in game.c steht jetzt bei TODO welche version der Code ist und welche Test er schafft
2025-10-24 18:31:43 +00:00
stammjo100588 0a627137fa in game.c steht jetzt bei TODO welche version der Code ist und welche Test er schafft 2025-10-24 20:26:16 +02:00
stammjo100588 22996a3363 Merge remote-tracking branch 'origin/main' 2025-10-24 20:17:47 +02:00
stammjo100588 5499bbcf2a Added fixes and new Mechanics to game.c to also Pass Test 4.
Also I killed the comments and wrote worse new ones
2025-10-24 20:17:00 +02:00
kegelmannni100026 14f6dd37f5 paar updates gemacht 2025-10-24 17:40:03 +02:00
stammjo100588 6b5ea6b989 Additional Changes to clean up 2025-10-22 21:43:13 +02:00
stammjo100588 a845fd7000 Added Schröder Changes to makefiles 2025-10-22 21:41:46 +02:00
stammjo100588 83f2ff4ec5 revert 8dc8b060f2
revert Added Schröder Changes to makefiles and 49 other files
2025-10-22 19:30:41 +00:00
stammjo100588 8a9bb66d8a revert 93da8ea94d
revert Added Schröder Changes to makefiles and 49 other files
2025-10-22 19:29:43 +00:00
stammjo100588 8dc8b060f2 Added Schröder Changes to makefiles and 49 other files 2025-10-22 21:14:37 +02:00
stammjo100588 93da8ea94d Added Schröder Changes to makefiles and 49 other files 2025-10-22 21:11:46 +02:00
12 changed files with 223 additions and 49 deletions

No files matched your search

+86 -2
View File
@@ -2,22 +2,106 @@
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.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: | VERSION: Erfolgreicher Test 4 & 5 I
/* * 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)
{ {
//Random Zeit initialisieren
srand(time(NULL));
for (unsigned int i = 0; i < searchFieldLen; i++)
{
for (unsigned int j = 0; j < searchFieldLen; j++)
{
salad[i][j] = EMPTY_CHAR;
} }
}
int placed = 0; //Anzahl der Erfolgreich platzierten Worte
//Platzieren
for (unsigned int w = 0; w < wordCount; w++)
{
const char *word = words[w];
unsigned int wordLen = strlen(word);
for (int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD; attempt++)
{
int row = rand() % searchFieldLen;
int col = rand() % searchFieldLen;
int direction = rand() % 2;
int canPlace = 1;
//Ob EIN Wort platziert werden kann (wird noch nicht platziert!)
for (unsigned int k = 0; k < wordLen; k++)
{
int r = row + (direction == 1 ? k : 0);
int c = col + (direction == 0 ? k : 0);
//Ränder des Spielfeldes beachten
if (r >= (int)searchFieldLen || c >= (int)searchFieldLen)
{
canPlace = 0;
break;
}
//Ist die Stelle nicht leer und passt Die stelle nicht zum passenden Buchstaben des Wortes
if (salad[r][c] != EMPTY_CHAR && salad[r][c] != word[k])
{
canPlace = 0;
break;
}
}
if (canPlace) //Wenn geprüft wurde ob ein Wort erfolgreich platziert werden kann.
{
for (unsigned int k = 0; k < wordLen; k++)
{
int r = row + (direction == 1 ? k : 0);
int c = col + (direction == 0 ? k : 0);
if (r < (int)searchFieldLen && c < (int)searchFieldLen)
salad[r][c] = word[k];
}
placed++;
break; //Beim Nächsten Wort weiter machen
}
}
}
//Mit Zufälligen Buchstaben füllen
for (unsigned int i = 0; i < searchFieldLen; i++)
{
for (unsigned int j = 0; j < searchFieldLen; j++)
{
if (salad[i][j] == EMPTY_CHAR)
{
salad[i][j] = 'A' + (rand() % 26);
}
}
}
return placed;
}
// 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 (unsigned int i = 0; i < searchFieldLen; i++)
{
for (unsigned int j = 0; j < searchFieldLen; j++)
{
printf("%c ", salad[i][j]);
} }
printf("\n");
}
}
BIN
View File
Binary file not shown.
+32 -1
View File
@@ -1,12 +1,43 @@
#include "input.h" #include "input.h"
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <stdio.h>
// TODO: // TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt. // eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{ {
unsigned int count = 0;
int c;
unsigned int idx = 0;
if (!file) return 0;
while ((c = fgetc(file)) != EOF && count < maxWordCount) {
if (isalpha((unsigned char)c)) {
if (idx < MAX_WORD_LEN - 1) {
words[count][idx++] = (char) toupper((unsigned char)c);
} else {
// word too long: truncate remaining letters until delimiter
idx = MAX_WORD_LEN - 1;
} }
} else {
if (idx > 0) {
words[count][idx] = '\0';
count++;
idx = 0;
}
// skip consecutive delimiters
}
}
// If file ended while reading a word, terminate and count it
if (idx > 0 && count < maxWordCount) {
words[count][idx] = '\0';
count++;
}
return count;
}
BIN
View File
Binary file not shown.
+7 -7
View File
@@ -36,22 +36,22 @@ int main(int argc, char *argv[])
// Create the word salad by placing words into grid // Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// TODO: // TODO: (erledigt von Niklas)
// Check if all words were successfully placed // Check if all words were successfully placed
// Start the game if successful // Start the game if successful
// error message if some words couldn't be placed // error message if some words couldn't be placed
if (placedWords == wordCount) if (placedWords == wordCount) //überprüfung: alle wörter im gitter
{ {
printf("All words have been placed successfully.\n"); printf("All words have been placed successfully.\n");
// Start graphical game
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800); startGame(wordSalad, SALAD_SIZE, words, wordCount, 800); //header datei wird ausgeführt
} }
else else
{ {
fprintf(stderr, "Error: Only %u out of %u words could be placed.\n", placedWords, wordCount); fprintf(stderr, "Error: Only %u out of %u words could be placed.\n", placedWords, wordCount); //fprintf in selbst gewählter ausgabe
fprintf(stderr, "Try reducing the number or length of words.\n"); fprintf(stderr, "Try reducing the number or length of words.\n"); // std err = error
exitCode = EXIT_FAILURE; exitCode = EXIT_FAILURE; //exit_failure von der stdlib eine funktion => fehler beim ausführen; wert = 1
} }
BIN
View File
Binary file not shown.
Binary file not shown.
+30 -29
View File
@@ -7,26 +7,28 @@
#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: | VERSION: Erfolgreicher Test 4 & 5 I
/* * 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)
{ {
// Zufall initialisieren //Random Zeit initialisieren
srand(time(NULL)); srand(time(NULL));
// 1. Spielfeld leeren //Matrix leeren
for (unsigned int i = 0; i < searchFieldLen; i++) for (unsigned int x = 0; x < searchFieldLen; x++)
{ {
for (unsigned int j = 0; j < searchFieldLen; j++) for (unsigned int y = 0; y < searchFieldLen; y++)
{ {
salad[i][j] = EMPTY_CHAR; salad[x][y] = EMPTY_CHAR;
} }
} }
// 2. Wörter platzieren int placed = 0; //Anzahl der Erfolgreich platzierten Worte
//Platzieren
for (unsigned int w = 0; w < wordCount; w++) for (unsigned int w = 0; w < wordCount; w++)
{ {
const char *word = words[w]; const char *word = words[w];
@@ -34,29 +36,26 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
for (int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD; attempt++) for (int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD; attempt++)
{ {
// zufällige Startposition //random kästchen in der matrix auswählen zwischen 0 und searchfieldlen (row,col)
int row = rand() % searchFieldLen; int row = rand() % searchFieldLen;
int col = rand() % searchFieldLen; int col = rand() % searchFieldLen;
int direction = rand() % 2; //0 = horizontal; 1 = vertikal
// zufällige Richtung: 0 = horizontal, 1 = vertikal
int direction = rand() % 2;
int canPlace = 1; int canPlace = 1;
// Nur prüfen, ob Buchstaben passen (gleiche erlaubt, leer erlaubt) //Ob EIN Wort platziert werden kann (wird noch nicht platziert!)
for (unsigned int k = 0; k < wordLen; k++) for (unsigned int k = 0; k < wordLen; k++)
{ {
int r = row + (direction == 1 ? k : 0); int r = row + (direction == 1 ? k : 0); //buchstaben werden vertikal darunter gestzt wenn direction = 1 (neue zeile)
int c = col + (direction == 0 ? k : 0); int c = col + (direction == 0 ? k : 0); //buchstaben werden horizontal rechts daneben gesetzt wenn direction = 0 (neue spalte)
// Wenn außerhalb des Feldes -> abbrechen //Ränder des Spielfeldes beachten
if (r >= (int)searchFieldLen || c >= (int)searchFieldLen) if (r >= (int)searchFieldLen || c >= (int)searchFieldLen)
{ {
canPlace = 0; canPlace = 0;
break; break;
} }
// Wenn belegt mit anderem Buchstaben -> abbrechen //Ist die Stelle schon besetzt und passt Die stelle nicht zum passenden Buchstaben des Wortes
if (salad[r][c] != EMPTY_CHAR && salad[r][c] != word[k]) if (salad[r][c] != EMPTY_CHAR && salad[r][c] != word[k])
{ {
canPlace = 0; canPlace = 0;
@@ -64,9 +63,9 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
} }
} }
// Wenn möglich, das Wort setzen if (canPlace) //Wenn geprüft wurde ob ein Wort erfolgreich platziert werden kann.
if (canPlace)
{ {
//platzieren der buchstaben
for (unsigned int k = 0; k < wordLen; k++) for (unsigned int k = 0; k < wordLen; k++)
{ {
int r = row + (direction == 1 ? k : 0); int r = row + (direction == 1 ? k : 0);
@@ -74,34 +73,36 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
if (r < (int)searchFieldLen && c < (int)searchFieldLen) if (r < (int)searchFieldLen && c < (int)searchFieldLen)
salad[r][c] = word[k]; salad[r][c] = word[k];
} }
break; // Wort erfolgreich platziert placed++;
break; //Beim Nächsten Wort weiter machen
} }
} }
} }
// 3. Leere Felder mit Zufallsbuchstaben füllen //Mit Zufälligen Buchstaben füllen
for (unsigned int i = 0; i < searchFieldLen; i++) for (unsigned int x = 0; x < searchFieldLen; x++)
{ {
for (unsigned int j = 0; j < searchFieldLen; j++) for (unsigned int y = 0; y < searchFieldLen; y++)
{ {
if (salad[i][j] == EMPTY_CHAR) if (salad[x][y] == EMPTY_CHAR)
{ {
salad[i][j] = 'A' + (rand() % 26); salad[x][y] = 'A' + (rand() % 26); //random buchstabe zw A und Z platzieren
} }
} }
} }
return 0; return placed;
} }
// 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 (unsigned int i = 0; i < searchFieldLen; i++) for (unsigned int x = 0; x < searchFieldLen; x++)
{ {
for (unsigned int j = 0; j < searchFieldLen; j++) for (unsigned int y = 0; y < searchFieldLen; y++)
{ {
printf("%c ", salad[i][j]); printf("%c ", salad[x][y]);
} }
printf("\n"); printf("\n");
} }
+43 -3
View File
@@ -1,12 +1,52 @@
#include "input.h" #include "input.h"
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <stdio.h>
// TODO: // TODO: | VERSION: Erfolgreicher Test 1,2 & 3
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt. // eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{ {
printf("Hallo"); unsigned int count = 0;
int c;
unsigned int idx = 0;
if (!file) return 0; //Wenn keine file gefunden oder geöffnet wurde
//scannt jedes zeichen in der file durch bis zum end of file oder bis es genug wörter hat
while ((c = fgetc(file)) != EOF && count < maxWordCount)
{
if (isalpha((unsigned char)c))// prüft ob das zeichen ein buchstabe ist (also kein komma oder leerzeichen usw)
{
//macht die buchstaben zu Großbuchstaben und schreibt sie ins array (toupper)
//prüft ob das wort kurz genug ist
if (idx < MAX_WORD_LEN - 1)
{
words[count][idx++] = (char) toupper((unsigned char)c);
} else
{
// word too long: schneidet das ende vom wort ab bis es reinpasst
idx = MAX_WORD_LEN - 1;
} }
} else // bei leerzeichen, komma usw
{
if (idx > 0) //wort endet -> \0 ;stellt den idx wieder auf 0; neues wort beginnt -> count++
{
words[count][idx] = '\0';
count++;
idx = 0;
}
// skip consecutive delimiters
}
}
//Erkennung vom Ende der file wenn das letze wort endet und wort counten
if (idx > 0 && count < maxWordCount) {
words[count][idx] = '\0';
count++;
}
return count;
}
+17 -2
View File
@@ -36,15 +36,30 @@ int main(int argc, char *argv[])
// Create the word salad by placing words into grid // Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// TODO: // TODO: (erledigt von Niklas)
// Check if all words were successfully placed // Check if all words were successfully placed
// Start the game if successful // Start the game if successful
// error message if some words couldn't be placed // error message if some words couldn't be placed
//prüft ob die die anzahl der wörter und der tatsächlich platzierten wörter übereinstimmen
if (placedWords == wordCount)
{
printf("All words have been placed successfully.\n");
// Start graphical game
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
} }
else else
{ {
// Print error message if file couldn't be opened fprintf(stderr, "Error: Only %u out of %u words could be placed.\n", placedWords, wordCount);
fprintf(stderr, "Try reducing the number or length of words.\n");
exitCode = EXIT_FAILURE;
}
}
else
{
//Wenn die file nicht geöffnet werden konnte
fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]); fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]);
exitCode = EXIT_FAILURE; exitCode = EXIT_FAILURE;
} }
+6 -4
View File
@@ -1,9 +1,9 @@
CC = gcc CC = gcc
CFLAGS = -g -Wall -I$(raylibfolder) CFLAGS = -g -Wall
LDFLAGS = -lopengl32 -lgdi32 -lwinmm LDFLAGS = -lopengl32 -lgdi32 -lwinmm
BINARIES = ./windows BINARIES = ./windows
raylib_folder = ./raylib raylibfolder = ./raylib
unityfolder = ./unity unityfolder = ./unity
# -------------------------- # --------------------------
@@ -12,7 +12,6 @@ unityfolder = ./unity
wordsalad_initial: wordsalad_initial:
$(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS) $(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
# -------------------------- # --------------------------
# Normales Spiel bauen # Normales Spiel bauen
# -------------------------- # --------------------------
@@ -29,7 +28,7 @@ game.o: game.c
$(CC) -c $(CFLAGS) game.c $(CC) -c $(CFLAGS) game.c
graphicalGame.o: graphicalGame.c graphicalGame.o: graphicalGame.c
$(CC) -I$(raylib_folder) -c $(CFLAGS) graphicalGame.c $(CC) -I$(raylibfolder) -c $(CFLAGS) graphicalGame.c
# -------------------------- # --------------------------
# Unit Tests # Unit Tests
@@ -44,3 +43,6 @@ test: input.o game.o unit_tests.c
# -------------------------- # --------------------------
clean: clean:
del /f *.o *.exe del /f *.o *.exe
wordsalad_myversion: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad_myversion main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)
+2 -1
View File
@@ -2,4 +2,5 @@ Yeti,Nessie Werwolf; Vampir
Monster Monster
Hydra;Frankenstein Hydra;Frankenstein
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
Gespenst, Ogerp Gespenst, Oger
AHHHHHHH