Compare commits
19 Commits
main
...
Lukas_bran
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce06e43179 | ||
|
|
12ac6ad0ad | ||
|
|
c870728330 | ||
|
|
7073b13605 | ||
|
|
7d48b1d990 | ||
|
|
d5882589c0 | ||
|
|
59bd2faccd | ||
|
|
cb02cbb972 | ||
|
|
190b40468f | ||
|
|
10af0980d3 | ||
|
|
cf577e2a37 | ||
|
|
4ea6b50cf5 | ||
|
|
e8f592c39b | ||
|
|
da8d9fc799 | ||
|
|
20d295ef25 | ||
|
|
63e6a912c6 | ||
|
|
dd257eac8f | ||
| 551d0738ee | |||
|
|
eef02e688f |
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"
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
//Bearbeitet von Lukas Wörner, 02.11.25
|
||||
#include "game.h"
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
@ -6,6 +7,7 @@
|
||||
#define MAX_RAND_TRIES_PER_WORD 10
|
||||
#define EMPTY_CHAR 0
|
||||
|
||||
//Position beinhaltet x, y und Richtung
|
||||
//TODO: Spiellogik implementieren:
|
||||
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||
@ -13,11 +15,179 @@
|
||||
// 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)
|
||||
{
|
||||
|
||||
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 gesetzteWoerter = 0;
|
||||
clearWordSalad(salad, searchFieldLen);
|
||||
gesetzteWoerter = fuelleSalatMitWoertern(salad, searchFieldLen, words, position, wordCount);
|
||||
fillWordsaladRand(salad, searchFieldLen);
|
||||
return gesetzteWoerter;
|
||||
}
|
||||
|
||||
// Prints the word salad to console
|
||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||
{
|
||||
for(int i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for(int k = 0; k < searchFieldLen; k++)
|
||||
{
|
||||
printf("%c", salad[i][k]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
}
|
||||
//Logik für createWordSalad:
|
||||
/* Salat ist das Wortsalat Array.
|
||||
1. Salat wird mit "." befüllt. Diese "." symbolisieren leere noch nicht befüllte Stellen
|
||||
2. Für jedes Wort aus dem Wort - Array werden nacheinander mögliche Punkte gesucht, welche als Start um dieses Wort
|
||||
ins Array zu schreiben funktionieren. Diese Positionen werden in einer struct gespeichert.
|
||||
3. Für das Wort wird dann per Zufall aus den möglichen Positionen eine ausgewählt
|
||||
4. Das Wort wird an der ausgewählten Position in den Salat geschrieben.
|
||||
5. Dies passiert für alle Wörter. Gibt es keinen Platz mehr wird das Wort nicht in den Salat geschrieben
|
||||
6. Restliche leere "." Stellen des Salats werden mit zufälligen Buchstaben befüllt
|
||||
*/
|
||||
|
||||
//Funktion dafür den gesammten Salat mit . zu befüllen.
|
||||
void clearWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||
{
|
||||
for(unsigned int zeile = 0; zeile < searchFieldLen; zeile++)
|
||||
{
|
||||
for(unsigned int spalte = 0; spalte < searchFieldLen; spalte++)
|
||||
{
|
||||
salad[zeile][spalte] = '.'; // salad wird mit Punkten befüllt.
|
||||
}
|
||||
}
|
||||
}
|
||||
//Funktion für den Schluss: Übrige leere stellen werden random befüllt.
|
||||
void fillWordsaladRand(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||
{
|
||||
for(int i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for(int k = 0; k < searchFieldLen; k++)
|
||||
{
|
||||
if(salad[i][k] == '.')
|
||||
{
|
||||
salad[i][k] = 'A' + rand() % 26;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//hierbei: alle Positionen werden zunächst geprüft ob leer (.) danach wird nach rechts und nach unten geschaut ob:
|
||||
//a.) genügend Platz wäre, dass nicht aus dem array herausgeschrieben wird und
|
||||
//b.) alle zu besetzenden Felder leer sind (.).
|
||||
//Positionamount gibt aus wie viele mögliche Positionen es für dieses Wort gibt.
|
||||
//Wird mit 0 initialisiert. Wenns null bleibt, bedeutet dies es gibt keine verfügbaren Positionen.
|
||||
//rechtsfrei und untenfrei werden für jeden Position neu auf 1 initialisiert. Trifft a.) oder b.) nicht zu auf null gesetzt
|
||||
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[])
|
||||
{
|
||||
const char *word = words[wordidx];
|
||||
int wordlen = strlen(word);
|
||||
int positionamount = 0;
|
||||
int rechtsfrei = 1;
|
||||
int untenfrei = 1;
|
||||
for(int i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for(int k = 0; k < searchFieldLen; k++)
|
||||
{
|
||||
rechtsfrei = 1;
|
||||
untenfrei = 1;
|
||||
if(salad[i][k] == '.')
|
||||
{
|
||||
//nach rechts prüfen
|
||||
if(searchFieldLen - k >= wordlen)
|
||||
{
|
||||
for(int p = k +1; p < k+ wordlen; p++)
|
||||
{
|
||||
if(salad[i][p] != '.')
|
||||
{
|
||||
rechtsfrei = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
rechtsfrei = 0;
|
||||
}
|
||||
//nach unten prüfen
|
||||
if(searchFieldLen - i >= wordlen)
|
||||
{
|
||||
for(int q = i+1; q < i+ wordlen; q++)
|
||||
{
|
||||
if(salad[q][k] != '.')
|
||||
{
|
||||
untenfrei = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
untenfrei = 0;
|
||||
}
|
||||
if(rechtsfrei) //Positions array wird mit gültigen Positionen und Richtung befüllt.
|
||||
{
|
||||
positions[positionamount].x = k;
|
||||
positions[positionamount].y = i;
|
||||
positions[positionamount].richtung = RECHTS;
|
||||
positionamount++;
|
||||
}
|
||||
if(untenfrei)
|
||||
{
|
||||
positions[positionamount].x = k;
|
||||
positions[positionamount].y = i;
|
||||
positions[positionamount].richtung = UNTEN;
|
||||
positionamount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return positionamount;
|
||||
|
||||
}
|
||||
|
||||
//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 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 gesetzteWoerter = 0;
|
||||
int positionsamount;
|
||||
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
|
||||
{
|
||||
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[positiongewaehlt].x;
|
||||
int t = 0;
|
||||
for(int k = p; k < p + strlen(word); k++)
|
||||
{
|
||||
salad[position[positiongewaehlt].y][k] = word[t];
|
||||
t++;
|
||||
}
|
||||
}
|
||||
if(position[positiongewaehlt].richtung == UNTEN)
|
||||
{
|
||||
word = words[i];
|
||||
int up = position[positiongewaehlt].y;
|
||||
int ut = 0;
|
||||
for(int uk = up; uk < up +strlen(word); uk++)
|
||||
{
|
||||
salad[uk][position[positiongewaehlt].x] = word[ut];
|
||||
ut++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return gesetzteWoerter;
|
||||
|
||||
}
|
||||
@ -1,11 +1,26 @@
|
||||
//Bearbeitet von Lukas Wörner, 02.11.25
|
||||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
|
||||
#include "input.h"
|
||||
|
||||
#define MAX_SEARCH_FIELD_LEN 100
|
||||
#define MIN_WORD_LEN 2
|
||||
|
||||
typedef enum {RECHTS, UNTEN} RICHTUNG;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x, y;
|
||||
RICHTUNG richtung;
|
||||
}Position;
|
||||
|
||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount);
|
||||
void showWordSalad(const 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);
|
||||
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 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
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 <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
BIN
Start_Linux/input.o
Normal file
Binary file not shown.
@ -5,7 +5,7 @@
|
||||
#include "graphicalGame.h"
|
||||
|
||||
#define MAX_NUMBER_OF_WORDS 100
|
||||
#define SALAD_SIZE 20
|
||||
#define SALAD_SIZE 20 //20 Buchstaben breit und lang
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -22,7 +22,7 @@ int main(int argc, char *argv[])
|
||||
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(argv[1], "r");
|
||||
FILE *file = fopen(argv[1], "r"); //FILE ZEIGER, öffne cmd zweites Wort: Zweites Wort ist ja words.txt also Wort file
|
||||
|
||||
if(file != NULL)
|
||||
{
|
||||
@ -36,6 +36,15 @@ int main(int argc, char *argv[])
|
||||
// Create the word salad by placing words into grid
|
||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
||||
|
||||
if(placedWords == wordCount) //Checks if all words were placed
|
||||
{
|
||||
startGame(wordSalad, SALAD_SIZE, words, placedWords, 800); }
|
||||
else
|
||||
{
|
||||
printf("Error. Out of %d words just %d words could be placed.\n", wordCount, placedWords);
|
||||
}
|
||||
|
||||
|
||||
// TODO:
|
||||
// Check if all words were successfully placed
|
||||
// Start the game if successful
|
||||
|
||||
BIN
Start_Linux/main.o
Normal file
BIN
Start_Linux/main.o
Normal file
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
CC = gcc
|
||||
CFLAGS = -g -Wall -I$(raylibfolder)
|
||||
LDFLAGS = -lGL -lX11 -lm
|
||||
CFLAGS = -g -Wall -I$(raylib_folder) # <- KORRIGIERT
|
||||
LDFLAGS = -lGL -lX11 -lm #Linker Flags binden verschiedene Bibliotheken ein. Include "bib_name" -> -l"bib_name"
|
||||
BINARIES = ./linux
|
||||
|
||||
raylib_folder = ./raylib
|
||||
@ -19,27 +19,45 @@ 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
|
||||
|
||||
input.o: input.c
|
||||
$(CC) $(CFLAGS) -c input.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@ # <- KORRIGIERT
|
||||
#bedeutung: $< erste Abhängigkeit (in diesem Fall main.c), %@ erstelle daraus eine main.o Datei.
|
||||
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
|
||||
$(CC) -o wordsalad_myversion main.o $(BINARIES)/libwordsalad.a
|
||||
|
||||
clean:
|
||||
rm -f *.o wordsalad $(TEST_BIN)
|
||||
# Tests starten mit ./runTests
|
||||
#Erklärung der veränderungen im Vergleich zu davor <- Korrigiert;
|
||||
#Das war nötig, weil make deinen alten Befehl ignoriert hat.
|
||||
|
||||
# Das Problem mit dem alten Befehl: make hat deine Regel input.o: ... gesehen und wollte input.o erstellen. Es hat sich deinen Befehl $(CC) $(CFLAGS) -c input.c angesehen.
|
||||
# Für make war dieser Befehl "unvollständig". Es stand dort nicht explizit, dass dieser Befehl die Datei input.o erstellt (obwohl gcc das automatisch tun würde).
|
||||
# make ignoriert den Befehl: Weil make deinen Befehl als unzureichend ansah, verwarf es ihn stillschweigend.
|
||||
# make nutzt seine eingebaute Regel: Stattdessen griff make auf seine eigene, eingebaute (implizite) Regel zurück, um eine .o-Datei zu erstellen.
|
||||
# Diese eingebaute Regel ist jedoch falsch für uns: Sie versucht, die .c-Datei zu linken, nicht nur zu kompilieren.
|
||||
# Der Fehler: Diese (falsche) eingebaute Regel von make war es, die den Linker aufrief und den Fehler undefined reference to 'main' verursachte.
|
||||
BIN
Start_Linux/wordsalad
Executable file
BIN
Start_Linux/wordsalad
Executable file
Binary file not shown.
BIN
Start_Linux/wordsalad_initial
Executable file
BIN
Start_Linux/wordsalad_initial
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user