main geändert, makefile geändert

This commit is contained in:
LukVal54 2025-11-02 17:09:44 +01:00
parent c870728330
commit 12ac6ad0ad
12 changed files with 83 additions and 37 deletions

5
Start_Linux/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"files.associations": {
"input.h": "c"
}
}

View File

@ -17,11 +17,11 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
{
srand(time(NULL));
Position position[(2 * MAX_SEARCH_FIELD_LEN * (MAX_SEARCH_FIELD_LEN - MIN_WORD_LEN + 1))]; //Positionsarray Größe: Formel max. nötige Größe (für minimal großes wort)
int gesetzteWörter = 0;
int gesetzteWoerter = 0;
clearWordSalad(salad, searchFieldLen);
gesetzteWörter = fuelleSalatMitWörtern(salad, searchFieldLen, words, position, wordCount);
gesetzteWoerter = fuelleSalatMitWoertern(salad, searchFieldLen, words, position, wordCount);
fillWordsaladRand(salad, searchFieldLen);
return gesetzteWörter;
return gesetzteWoerter;
}
// Prints the word salad to console
@ -140,43 +140,43 @@ int findPossiblePositions(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]
//Nun muss für jedes Wort per zufall ausgesucht werden Wo es beginnt und welche richtung aus
//den ganzen möglichen fällen und dann das wort ins grid gezeichnet werden.
int fuelleSalatMitWörtern(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], Position position[], unsigned int wordcount)
int fuelleSalatMitWoertern(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], Position position[], unsigned int wordcount)
{
int gesetzteWörter = 0;
int gesetzteWoerter = 0;
int positionsamount;
int positiongewählt;
int positiongewaehlt;
const char *word;
for(int i = 0; i < wordcount; i++) //jedes Wort.
{
positionsamount = findPossiblePositions(salad, searchFieldLen, words, i, position); //für dieses Wort werden die Positionen gefunden
if(positionsamount > 0)//es gibt Positionen
{
gesetzteWörter++;
positiongewählt = rand() % positionsamount; //die wie vielte Position des Positionsarrays für dieses Wort wir nehmen
if(position[positiongewählt].richtung == RECHTS)
gesetzteWoerter++;
positiongewaehlt = rand() % positionsamount; //die wie vielte Position des Positionsarrays für dieses Wort wir nehmen
if(position[positiongewaehlt].richtung == RECHTS)
{
word = words[i];
int p = position[positiongewählt].x;
int p = position[positiongewaehlt].x;
int t = 0;
for(int k = p; k < p + strlen(word); k++)
{
salad[position[positiongewählt].y][k] = word[t];
salad[position[positiongewaehlt].y][k] = word[t];
t++;
}
}
if(position[positiongewählt].richtung == UNTEN)
if(position[positiongewaehlt].richtung == UNTEN)
{
word = words[i];
int up = position[positiongewählt].y;
int up = position[positiongewaehlt].y;
int ut = 0;
for(int uk = up; uk < up +strlen(word); uk++)
{
salad[uk][position[positiongewählt].x] = word[ut];
salad[uk][position[positiongewaehlt].x] = word[ut];
ut++;
}
}
}
}
return gesetzteWörter;
return gesetzteWoerter;
}

View File

@ -20,7 +20,7 @@ void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
void clearWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen);
void fillWordsaladRand(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen);
int findPossiblePositions(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], int wordidx, Position positions[]);
int fuelleSalatMitWörtern(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], Position position[], unsigned int wordcount);
int fuelleSalatMitWoertern(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], Position position[], unsigned int wordcount);
#endif

BIN
Start_Linux/game.o Normal file

Binary file not shown.

View File

@ -0,0 +1,2 @@
dartgoblin, haughrida, royal_knight, larry,
larry_king, heheheha, huhui, schere, grrrrrr

BIN
Start_Linux/graphicalGame.o Normal file

Binary file not shown.

View File

@ -1,12 +1,45 @@
//erstellt von Harun Faizi am 01.11.2025
#include "input.h"
#include <string.h>
#include <ctype.h>
#include <ctype.h> // Wichtig für toupper()
#include <stdio.h>
// 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)
{
if (file == NULL)
return 0; // Sicherheitsprüfung, also wurde ein File gefunden
char line[MAX_LINE_LEN]; // Puffer für eine Zeile aus Datei
unsigned int wordCount = 0; // zählt die gefundenen Wörter
// Lese Datei Zeile für Zeile
while(fgets(line, sizeof(line), file) != NULL)
{
// Zerlege die Zeile in Wörter anhand der Trennzeichen
char *token = strtok(line, ".,; \t\n");
while (token != NULL && wordCount < maxWordCount)
{
// Kopiere das aktuelle Token ins Array und sichere Nullterminierung
strncpy(words[wordCount], token, MAX_WORD_LEN - 1);
words[wordCount][MAX_WORD_LEN - 1] = '\0';
// --- HINZUGEFÜGT ---
// Wandle das gesamte Wort in Großbuchstaben um
for(int i = 0; words[wordCount][i] != '\0'; i++)
{
words[wordCount][i] = toupper(words[wordCount][i]);
}
// --- ENDE HINZUGEFÜGT ---
wordCount++;
token = strtok(NULL, ".,; \t\n"); // nächstes Token
}
if (wordCount >= maxWordCount)
break;
}
return wordCount;
}

BIN
Start_Linux/input.o Normal file

Binary file not shown.

View File

@ -38,8 +38,7 @@ int main(int argc, char *argv[])
if(placedWords == wordCount) //Checks if all words were placed
{
startGame(wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], SALAD_SIZE, words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN], placedWords, 800);
}
startGame(wordSalad, SALAD_SIZE, words, placedWords, 800); }
else
{
printf("Error. Out of %d words just %d words could be placed.\n", wordCount, placedWords);

BIN
Start_Linux/main.o Normal file

Binary file not shown.

View File

@ -1,17 +1,17 @@
CC = gcc # Compiler-Variable: welcher C-Compiler genutzt wird (hier gcc)
CFLAGS = -g -Wall -I$(raylibfolder) # -Wall -> alle wichtigen Warnungen aktivieren, -I : suche dort (raylibfolder) nach datei.
LDFLAGS = -lGL -lX11 -lm # Linker-Flags: Bibliotheken, die an das Linker-Kommando übergeben werden
CC = gcc
CFLAGS = -g -Wall -I$(raylib_folder) # <- KORRIGIERT
LDFLAGS = -lGL -lX11 -lm
BINARIES = ./linux
raylib_folder = ./raylib #Pfade zu raylib_folder und unityfolder
raylib_folder = ./raylib
unityfolder = ./unity
# --------------------------
# initiales Spiel bauen
# --------------------------
wordsalad_initial: #hier kommen normalerweise Abhängikeiten hin. Z.b die Datei game.o muss vorhanden sein.
wordsalad_initial:
$(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
#wordsalad_initial linkt nur bibliotheken. Deshalb hat es keine Abhängigkeiten.
# --------------------------
# Normales Spiel bauen
# --------------------------
@ -19,29 +19,36 @@ wordsalad: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)
main.o: main.c
$(CC) $(CFLAGS) -c main.c
$(CC) $(CFLAGS) -c $< -o $@ # <- KORRIGIERT
input.o: input.c
$(CC) $(CFLAGS) -c input.c
input.o: input.c input.h
$(CC) $(CFLAGS) -c $< -o $@ # <- KORRIGIERT (Zeile 25/26)
game.o: game.c
$(CC) $(CFLAGS) -c game.c
$(CC) $(CFLAGS) -c $< -o $@ # <- KORRIGIERT
graphicalGame.o: graphicalGame.c
$(CC) $(CFLAGS) -c graphicalGame.c
$(CC) $(CFLAGS) -c $< -o $@ # <- KORRIGIERT
# --------------------------
# Unit Tests
# --------------------------
TEST_BIN = runTests
test: input.o game.o unit_tests.c
$(CC) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a
# KORRIGIERTE Test-Regel (umbenannt von neuer_test)
test: input.o game.o unit_tests.o
$(CC) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.o $(BINARIES)/libunity.a
# KORRIGIERTE unit_tests.o Regel
unit_tests.o: unit_tests.c input.h game.h
$(CC) $(CFLAGS) -I$(unityfolder) -c $< -o $@
# --------------------------
# Clean
# --------------------------
wordsalad_myversion: main.o $(BINARIES)/libwordsalad.a #eigenes Programm erstellen.
wordsalad_myversion: main.o $(BINARIES)/libwordsalad.a
$(CC) -o wordsalad_myversion main.o $(BINARIES)/libwordsalad.a
clean:
rm -f *.o wordsalad $(TEST_BIN)
# Tests starten mit ./runTests

BIN
Start_Linux/wordsalad Executable file

Binary file not shown.