main geändert, makefile geändert
This commit is contained in:
parent
c870728330
commit
12ac6ad0ad
5
Start_Linux/.vscode/settings.json
vendored
Normal file
5
Start_Linux/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"input.h": "c"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -17,11 +17,11 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
{
|
{
|
||||||
srand(time(NULL));
|
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)
|
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);
|
clearWordSalad(salad, searchFieldLen);
|
||||||
gesetzteWörter = fuelleSalatMitWörtern(salad, searchFieldLen, words, position, wordCount);
|
gesetzteWoerter = fuelleSalatMitWoertern(salad, searchFieldLen, words, position, wordCount);
|
||||||
fillWordsaladRand(salad, searchFieldLen);
|
fillWordsaladRand(salad, searchFieldLen);
|
||||||
return gesetzteWörter;
|
return gesetzteWoerter;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the word salad to console
|
// 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
|
//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.
|
//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 positionsamount;
|
||||||
int positiongewählt;
|
int positiongewaehlt;
|
||||||
const char *word;
|
const char *word;
|
||||||
for(int i = 0; i < wordcount; i++) //jedes Wort.
|
for(int i = 0; i < wordcount; i++) //jedes Wort.
|
||||||
{
|
{
|
||||||
positionsamount = findPossiblePositions(salad, searchFieldLen, words, i, position); //für dieses Wort werden die Positionen gefunden
|
positionsamount = findPossiblePositions(salad, searchFieldLen, words, i, position); //für dieses Wort werden die Positionen gefunden
|
||||||
if(positionsamount > 0)//es gibt Positionen
|
if(positionsamount > 0)//es gibt Positionen
|
||||||
{
|
{
|
||||||
gesetzteWörter++;
|
gesetzteWoerter++;
|
||||||
positiongewählt = rand() % positionsamount; //die wie vielte Position des Positionsarrays für dieses Wort wir nehmen
|
positiongewaehlt = rand() % positionsamount; //die wie vielte Position des Positionsarrays für dieses Wort wir nehmen
|
||||||
if(position[positiongewählt].richtung == RECHTS)
|
if(position[positiongewaehlt].richtung == RECHTS)
|
||||||
{
|
{
|
||||||
word = words[i];
|
word = words[i];
|
||||||
int p = position[positiongewählt].x;
|
int p = position[positiongewaehlt].x;
|
||||||
int t = 0;
|
int t = 0;
|
||||||
for(int k = p; k < p + strlen(word); k++)
|
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++;
|
t++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(position[positiongewählt].richtung == UNTEN)
|
if(position[positiongewaehlt].richtung == UNTEN)
|
||||||
{
|
{
|
||||||
word = words[i];
|
word = words[i];
|
||||||
int up = position[positiongewählt].y;
|
int up = position[positiongewaehlt].y;
|
||||||
int ut = 0;
|
int ut = 0;
|
||||||
for(int uk = up; uk < up +strlen(word); uk++)
|
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++;
|
ut++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return gesetzteWörter;
|
return gesetzteWoerter;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -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 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);
|
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 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
|
#endif
|
||||||
|
|||||||
BIN
Start_Linux/game.o
Normal file
BIN
Start_Linux/game.o
Normal file
Binary file not shown.
2
Start_Linux/goofywords.txt
Normal file
2
Start_Linux/goofywords.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
dartgoblin, haughrida, royal_knight, larry,
|
||||||
|
larry_king, heheheha, huhui, schere, grrrrrr
|
||||||
BIN
Start_Linux/graphicalGame.o
Normal file
BIN
Start_Linux/graphicalGame.o
Normal file
Binary file not shown.
@ -1,12 +1,45 @@
|
|||||||
|
|
||||||
|
//erstellt von Harun Faizi am 01.11.2025
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <string.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)
|
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
BIN
Start_Linux/input.o
Normal file
Binary file not shown.
@ -38,8 +38,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if(placedWords == wordCount) //Checks if all words were placed
|
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
|
else
|
||||||
{
|
{
|
||||||
printf("Error. Out of %d words just %d words could be placed.\n", wordCount, placedWords);
|
printf("Error. Out of %d words just %d words could be placed.\n", wordCount, placedWords);
|
||||||
|
|||||||
BIN
Start_Linux/main.o
Normal file
BIN
Start_Linux/main.o
Normal file
Binary file not shown.
@ -1,17 +1,17 @@
|
|||||||
CC = gcc # Compiler-Variable: welcher C-Compiler genutzt wird (hier gcc)
|
CC = gcc
|
||||||
CFLAGS = -g -Wall -I$(raylibfolder) # -Wall -> alle wichtigen Warnungen aktivieren, -I : suche dort (raylibfolder) nach datei.
|
CFLAGS = -g -Wall -I$(raylib_folder) # <- KORRIGIERT
|
||||||
LDFLAGS = -lGL -lX11 -lm # Linker-Flags: Bibliotheken, die an das Linker-Kommando übergeben werden
|
LDFLAGS = -lGL -lX11 -lm
|
||||||
BINARIES = ./linux
|
BINARIES = ./linux
|
||||||
|
|
||||||
raylib_folder = ./raylib #Pfade zu raylib_folder und unityfolder
|
raylib_folder = ./raylib
|
||||||
unityfolder = ./unity
|
unityfolder = ./unity
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# initiales Spiel bauen
|
# 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)
|
$(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
|
# 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)
|
$(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
main.o: main.c
|
main.o: main.c
|
||||||
$(CC) $(CFLAGS) -c main.c
|
$(CC) $(CFLAGS) -c $< -o $@ # <- KORRIGIERT
|
||||||
|
|
||||||
input.o: input.c
|
input.o: input.c input.h
|
||||||
$(CC) $(CFLAGS) -c input.c
|
$(CC) $(CFLAGS) -c $< -o $@ # <- KORRIGIERT (Zeile 25/26)
|
||||||
|
|
||||||
game.o: game.c
|
game.o: game.c
|
||||||
$(CC) $(CFLAGS) -c game.c
|
$(CC) $(CFLAGS) -c $< -o $@ # <- KORRIGIERT
|
||||||
|
|
||||||
graphicalGame.o: graphicalGame.c
|
graphicalGame.o: graphicalGame.c
|
||||||
$(CC) $(CFLAGS) -c graphicalGame.c
|
$(CC) $(CFLAGS) -c $< -o $@ # <- KORRIGIERT
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Unit Tests
|
# Unit Tests
|
||||||
# --------------------------
|
# --------------------------
|
||||||
TEST_BIN = runTests
|
TEST_BIN = runTests
|
||||||
|
|
||||||
test: input.o game.o unit_tests.c
|
# KORRIGIERTE Test-Regel (umbenannt von neuer_test)
|
||||||
$(CC) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a
|
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
|
# 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
|
$(CC) -o wordsalad_myversion main.o $(BINARIES)/libwordsalad.a
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o wordsalad $(TEST_BIN)
|
rm -f *.o wordsalad $(TEST_BIN)
|
||||||
|
# Tests starten mit ./runTests
|
||||||
BIN
Start_Linux/wordsalad
Executable file
BIN
Start_Linux/wordsalad
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user