revert 93da8ea94d7e97cd614705fea32f85ef061c78c8

revert Added Schröder Changes to makefiles and 49 other files
This commit is contained in:
Jonas Stamm 2025-10-22 19:29:43 +00:00
parent 8dc8b060f2
commit 8a9bb66d8a
7 changed files with 115 additions and 11 deletions

View File

@ -1,9 +1,9 @@
CC = gcc
CFLAGS = -g -Wall
CFLAGS = -g -Wall -I$(raylibfolder)
LDFLAGS = -lGL -lX11 -lm
BINARIES = ./linux
raylibfolder = ./raylib
raylib_folder = ./raylib
unityfolder = ./unity
# --------------------------
@ -28,7 +28,7 @@ game.o: game.c
$(CC) $(CFLAGS) -c game.c
graphicalGame.o: graphicalGame.c
$(CC) $(CFLAGS) -I$(raylibfolder) -c graphicalGame.c
$(CC) $(CFLAGS) -c graphicalGame.c
# --------------------------
# Unit Tests

View File

@ -41,6 +41,20 @@ int main(int argc, char *argv[])
// Start the game if successful
// error message if some words couldn't be placed
if (placedWords == wordCount)
{
printf("All words have been placed successfully.\n");
// Start graphical game
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
}
else
{
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
{

View File

@ -13,6 +13,9 @@ unityfolder = ./unity
wordsalad_initial:
$(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
wordsalad_myversion:
$(CC) -o wordsalad_myversion $(BINARIES) main.c $(BINARIES)/libwordsalad.a
# --------------------------
# Normales Spiel bauen
# --------------------------

View File

@ -2,6 +2,7 @@
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0
@ -13,11 +14,96 @@
// 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)
{
// Zufall initialisieren
srand(time(NULL));
// 1. Spielfeld leeren
for (unsigned int i = 0; i < searchFieldLen; i++)
{
for (unsigned int j = 0; j < searchFieldLen; j++)
{
salad[i][j] = EMPTY_CHAR;
}
}
// 2. Wörter 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++)
{
// zufällige Startposition
int row = rand() % searchFieldLen;
int col = rand() % searchFieldLen;
// zufällige Richtung: 0 = horizontal, 1 = vertikal
int direction = rand() % 2;
int canPlace = 1;
// Nur prüfen, ob Buchstaben passen (gleiche erlaubt, leer erlaubt)
for (unsigned int k = 0; k < wordLen; k++)
{
int r = row + (direction == 1 ? k : 0);
int c = col + (direction == 0 ? k : 0);
// Wenn außerhalb des Feldes -> abbrechen
if (r >= (int)searchFieldLen || c >= (int)searchFieldLen)
{
canPlace = 0;
break;
}
// Wenn belegt mit anderem Buchstaben -> abbrechen
if (salad[r][c] != EMPTY_CHAR && salad[r][c] != word[k])
{
canPlace = 0;
break;
}
}
// Wenn möglich, das Wort setzen
if (canPlace)
{
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];
}
break; // Wort erfolgreich platziert
}
}
}
// 3. Leere Felder mit Zufallsbuchstaben 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 0;
}
// Prints the word salad to console
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");
}
}

View File

@ -8,5 +8,5 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
printf("Hallo");
}

View File

@ -1,9 +1,9 @@
CC = gcc
CFLAGS = -g -Wall
CFLAGS = -g -Wall -I$(raylibfolder)
LDFLAGS = -lopengl32 -lgdi32 -lwinmm
BINARIES = ./windows
raylibfolder = ./raylib
raylib_folder = ./raylib
unityfolder = ./unity
# --------------------------
@ -12,6 +12,7 @@ unityfolder = ./unity
wordsalad_initial:
$(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
# --------------------------
# Normales Spiel bauen
# --------------------------
@ -22,13 +23,13 @@ main.o: main.c
$(CC) -c $(CFLAGS) main.c
input.o: input.c
$(CC) -c $(CFLAGS) input.c
$(CC) -c $(CFLAGS)input.c
game.o: game.c
$(CC) -c $(CFLAGS) game.c
graphicalGame.o: graphicalGame.c
$(CC) -I$(raylibfolder) -c $(CFLAGS) graphicalGame.c
$(CC) -I$(raylib_folder) -c $(CFLAGS) graphicalGame.c
# --------------------------
# Unit Tests

View File

@ -2,4 +2,4 @@ Yeti,Nessie Werwolf; Vampir
Monster
Hydra;Frankenstein
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
Gespenst, Oger
Gespenst, Ogerp