Compare commits

..
21 Commits
Author SHA1 Message Date
sengpielto106561 4079cb02bf final fix 2026-10-29 15:27:06 +01:00
sengpielto106561 547fc13e0f Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/kohlerma104069/Wortsalat 2026-10-29 15:24:46 +01:00
scheuerleinni103793 c114b40e7e Upsi dupsi 2026-10-29 16:02:36 +01:00
scheuerleinni103793 3e56933d1b Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/kohlerma104069/Wortsalat 2026-10-29 16:00:23 +01:00
scheuerleinni103793 96ecac9e4c Prüfe in main.c die input.c und game.c, Target in Makefile hinzugefügt 2026-10-29 15:59:08 +01:00
sengpielto106561 a48f1b961e fixed spielfeldgröße und groß/kleinschreibung 2026-10-29 15:21:43 +01:00
KohlerMaxi 61221a5b8d Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/kohlerma104069/Wortsalat 2026-10-29 14:46:31 +01:00
KohlerMaxi 327332b4a2 tabs geslöscht 2026-10-29 14:40:17 +01:00
sengpielto106561 b664c6dc5c setze Startgame pixelgröße auf etwas sinnvolles 2026-10-29 14:40:02 +01:00
sengpielto106561 d9ac9f27e1 added forgotten <sting.h> 2026-10-28 16:44:34 +01:00
sengpielto106561 b2d4ac22a2 input.c klein/großschreibung theoretisch 2026-10-27 16:09:13 +01:00
sengpielto106561 281e3ad21b Update game.c 2026-10-27 16:01:39 +01:00
sengpielto106561 7cdcd0e8db test funktion in main.c implementiert (sehr ähnlich der, die in unit_test.c verwendet wird) 2026-10-26 18:15:25 +01:00
sengpielto106561 28c70cf01b glaube jetzt alles gefixed zu haben 2026-10-26 17:56:53 +01:00
sengpielto106561 029eb426ab implemented input.c (fails unit test, wegen Groß/Kleinschreibung) und game.c tests sind jetzt ok 2026-10-26 17:22:23 +01:00
sengpielto106561 ce4be9f902 Tests benutzt und Fehler in game.c behoben 2026-10-25 19:50:29 +01:00
sengpielto106561 ce17403a1b Setze random Buchstaben in die noch leeren Felder (hab bei mir die unit-tests nicht zum laufen bekommen) 2026-10-25 19:43:39 +01:00
sengpielto106561 a02b363e20 implemented return value 2026-10-25 15:44:45 +01:00
sengpielto106561 d61687f8df implemented game.c 2026-10-25 15:13:52 +01:00
sengpielto106561 d368eea2f3 init salad 2026-10-22 11:59:25 +02:00
sengpielto106561 947054bb51 Update game.c 2026-10-22 11:23:38 +02:00
8 changed files with 265 additions and 7 deletions

No files matched your search

+3
View File
@@ -60,3 +60,6 @@ dkms.conf
# macOS
.DS_Store
Startcode/testwords_delims.txt
Startcode/testwords_empty.txt
Startcode/testwords_simple.txt
+86
View File
@@ -1,4 +1,5 @@
#include "game.h"
#include "input.h"
#include <time.h>
#include <stdlib.h>
#include <string.h>
@@ -6,6 +7,8 @@
#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 */
@@ -13,5 +16,88 @@
// 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)
{
//Initialisiert den seed für rand()
srand(time(NULL));
//Initialisiere spielfeld auf '0'
// TODO: memset()
//memset(salad, '0', MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN);
for(int i = 0; i < MAX_SEARCH_FIELD_LEN; i++){
for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++){
salad[i][j] = '0';
}
}
int placedWords = 0;
//Iterate over words
for(int counter = 0; counter < wordCount; counter++){
size_t len = strlen(words[counter]);
//try to place a word
for(int try = 0; try < 10; try++){
int x = rand() % MAX_SEARCH_FIELD_LEN;
int y = rand() % MAX_SEARCH_FIELD_LEN;
int dir = rand() % 2;
// cant place vertically
if(dir == 1 && MAX_SEARCH_FIELD_LEN < (y + (int) len)){
dir = 0;
}
//cant place horizontally
if((x + (int) len) > MAX_SEARCH_FIELD_LEN){
continue;
}
//place word vertically
if(dir == 1){
//see if all neccessary spaces are empty
bool cont = false;
for (int i = 0; i < (int)len; i++){
if(salad[x][y+i] != '0'){
cont = true;
break;
}
}
//if not all spaces are empty try again
if(cont) continue;
//insert currentWord into playing field
for (int i = 0; i < (int)len; i++){
salad[x][y+i] = words[counter][i];
}
placedWords++;
break;
}else{
//place currentWord horizontally
//see if all neccessary spaces are emtry
bool cont = false;
for (int i = 0; i < (int)len; i++){
if(salad[x+1][y] != '0'){
cont = true;
break;
}
}
//if not all spaces are empty try again
if(cont) continue;
//place currentWord
for (int i = 0; i < (int)len; i++){
salad[x+1][y] = words[counter][i];
}
placedWords++;
break;
}
}
}
for (int i = 0; i < MAX_SEARCH_FIELD_LEN; i++){
for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++){
if(salad[i][j] == '0'){
char c = 'A' + (rand() % 26);
salad[i][j] = c;
}
}
}
return placedWords;
}
+1 -1
View File
@@ -3,7 +3,7 @@
#include "input.h"
#define MAX_SEARCH_FIELD_LEN 100
#define MAX_SEARCH_FIELD_LEN 20
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount);
+71
View File
@@ -0,0 +1,71 @@
//Torbens Kopie zum Testen
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include "game.h"
#include "graphicalGame.h"
#define MAX_NUMBER_OF_WORDS 100
#define MAX_WORD_LEN 100
#define MAX_LINE_LEN 1024
#define SALAD_SIZE 20
// TODO:
// 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)
{
char *tmp;
int counter = 0;
char delimiters[] = ",!.;:? \n";
char *token;
while(fgets(tmp, MAX_LINE_LEN, file)){
printf("Input Line: %s\n", tmp);
token = strtok (tmp, delimiters);
while(token != NULL){
printf("Token:%s\n", token);
size_t len = strlen(token);
char copy[len+1];
strncpy(copy, token, len+1);
copy[len] = '\0';
strncpy(words[counter+1], copy, len);
words[counter+1][len] = '\0';
printf("Word: %s\n", words[counter+1]);
token = strtok (NULL, delimiters);
counter++;
}
}
return counter;
}
int main(void){
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game
unsigned int wordCount = 0;
FILE *file = fopen("words.txt", "r");
if(file != NULL)
{
unsigned int placedWords = 0;
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word sala
// Read words from file and store in 'words' array
printf("readWords start\n");
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
printf("%d", wordCount);
fclose(file);
// Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// TODO:
// Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed
}
return EXIT_SUCCESS;
}
+33
View File
@@ -1,6 +1,7 @@
#include "input.h"
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
@@ -8,5 +9,37 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
int count = 0;
char *line = calloc(MAX_LINE_LEN, sizeof(char));
char delimit[] = ",.;:!? \n";
while(fgets(line, MAX_LINE_LEN, file) != NULL && (count < maxWordCount)){
char *token = strtok(line, delimit);
while(token != NULL){
size_t len = strlen(token);
token[len] = '\0';
char copy[MAX_LINE_LEN];
strncpy(copy, token, len);
copy[len] = '\0';
strncpy(words[count], copy, len);
words[count][len] = '\0';
//schaue ob auch alles groß geschrieben ist
for(int i = 0; i < len; i++){
if(words[count][i] <= 122 && words[count][i] >= 97){
//mache Kleinbuchstaben zu Großbuchstaben //ASCII A = 65, a = 97, z = 122
words[count][i] -= 32;
}
}
count++;
token = strtok(NULL, delimit);
}
}
return count;
}
+1 -1
View File
@@ -3,7 +3,7 @@
#include <stdio.h>
#define MAX_WORD_LEN 100
#define MAX_WORD_LEN 20
#define MAX_LINE_LEN 1024
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount);
+58 -4
View File
@@ -1,11 +1,49 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "input.h"
#include "game.h"
#include "graphicalGame.h"
#define MAX_NUMBER_OF_WORDS 100
#define SALAD_SIZE 20
#define SALAD_SIZE 36
int checkSalad(char words[][MAX_WORD_LEN], char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], int placedWords, int wordCount){
//Iteriere über alle verfügbaren Wörter
int foundWords = 0;
//suche horizontal
for(int i = 0; i < wordCount; i++){
for(int h = 0; h < MAX_SEARCH_FIELD_LEN; h++){
if(strstr(wordSalad[h], words[i]) != NULL){
foundWords++;
break;
}
}
}
//flip Board
char copySalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
for (int i = 0; i< MAX_SEARCH_FIELD_LEN; i++){
for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++){
copySalad[i][j] = wordSalad[j][i];
}
}
// sucher vertikal
for(int i = 0; i < wordCount; i++){
for(int h = 0; h < MAX_SEARCH_FIELD_LEN; h++){
if(strstr(copySalad[h], words[i]) != NULL){
foundWords++;
break;
}
}
}
if(foundWords == placedWords) return 0;
return -1;
}
int main(int argc, char *argv[])
{
@@ -17,10 +55,11 @@ int main(int argc, char *argv[])
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
exitCode = EXIT_FAILURE;
}
else
{
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game
unsigned int wordCount = 0;
int wordCount = 0;
FILE *file = fopen(argv[1], "r");
@@ -39,8 +78,23 @@ int main(int argc, char *argv[])
// TODO:
// Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed
// error message if some words couldn't be placed (return input.c / game.c <=0)
// Prüfen, ob input.c (readWords) einen Fehler oder 0 Wörter zurückgegeben hat
if (wordCount <= 0)
{
fprintf(stderr, "Fehler: Es konnten keine Wörter eingelesen werden (input.c Rückgabewert <= 0).\n");
exitCode = EXIT_FAILURE;
}
// Prüfen, ob game.c (createWordSalad) einen Fehler zurückgegeben hat (<= 0) oder ob nicht alle eingelesenen Wörter platziert werden konnten
else if (placedWords <= 0 || placedWords < wordCount)
{
fprintf(stderr, "Fehler: Nicht alle Wörter konnten im Wortsalat platziert werden (game.c Rückgabewert <= 0).\n");
exitCode = EXIT_FAILURE;
}
//keine Ahnung wiegroß pixelSize sein soll
startGame(wordSalad, MAX_SEARCH_FIELD_LEN, words, placedWords, MAX_SEARCH_FIELD_LEN * SALAD_SIZE);
}
else
{
@@ -51,4 +105,4 @@ int main(int argc, char *argv[])
}
return exitCode;
}
}
+12 -1
View File
@@ -16,12 +16,14 @@ raylibfolder = ./raylib
unityfolder = ./unity
codefolder = .
# --------------------------
# initiales Spiel bauen
# --------------------------
wordsalad_initial:
$(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
# --------------------------
# Normales Spiel bauen
# --------------------------
@@ -48,6 +50,8 @@ TEST_BIN = runTests
test: input.o game.o $(codefolder)/unit_tests.c $(unityfolder)/unity.c
$(CC) -Wall -I$(unityfolder) -o $(TEST_BIN) input.o game.o $(codefolder)/unit_tests.c $(unityfolder)/unity.c
# --------------------------
# Clean
# --------------------------
@@ -56,4 +60,11 @@ ifeq ($(OS),Windows_NT)
del /f *.o *.exe
else
rm -f *.o wordsalad $(TEST_BIN)
endif
endif
# --------------------------
# Eigene Version bauen (Deine main.c + libwordsalad.a)
# --------------------------
wordsalad_TMN: main.o graphicalGame.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad_TMN main.o graphicalGame.o -L$(BINARIES) -lwordsalad $(BINARIES)/libraylib.a $(LDFLAGS)