Template
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
acc2a77b74 | ||
|
|
b62d4a7b8c | ||
|
|
74e6535320 | ||
|
|
8d2a60eaa9 | ||
|
|
26d80b65af | ||
|
|
2e24fdcec3 |
No files matched your search
+2
-1
@@ -35,9 +35,10 @@
|
|||||||
*.i*86
|
*.i*86
|
||||||
*.x86_64
|
*.x86_64
|
||||||
*.hex
|
*.hex
|
||||||
|
Startcode/wordsalad_myversion
|
||||||
Startcode/wordsalad_initial
|
Startcode/wordsalad_initial
|
||||||
Startcode/wordsalad
|
Startcode/wordsalad
|
||||||
test
|
runtest
|
||||||
|
|
||||||
# Debug files
|
# Debug files
|
||||||
*.dSYM/
|
*.dSYM/
|
||||||
|
|||||||
@@ -6,12 +6,120 @@
|
|||||||
#define MAX_RAND_TRIES_PER_WORD 10
|
#define MAX_RAND_TRIES_PER_WORD 10
|
||||||
#define EMPTY_CHAR 0
|
#define EMPTY_CHAR 0
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
HORIZONTAL,
|
||||||
|
VERTICAL
|
||||||
|
} Richtung;
|
||||||
|
|
||||||
//TODO: Spiellogik implementieren:
|
//TODO: Spiellogik implementieren:
|
||||||
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||||
|
|
||||||
// Creates the word salad by placing words randomly and filling empty spaces
|
// Creates the word salad by placing words randomly and filling empty spaces
|
||||||
|
// Buchstabengitter Koordinaten Seitenlänge die Wörter, der Buchstabe Anzahl der Wörter
|
||||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
for(int i = 0; i < searchFieldLen; i++) // jeden Platz erstmal mit EMTPY_CHAR ausfüllen
|
||||||
|
{
|
||||||
|
for(int j = 0; j < searchFieldLen; j++)
|
||||||
|
{
|
||||||
|
salad[i][j] = EMPTY_CHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int placeWords = 0;
|
||||||
|
|
||||||
|
for(int i = 0; i < wordCount; i++)
|
||||||
|
{
|
||||||
|
int Spalte;
|
||||||
|
int Zeile;
|
||||||
|
int WORD_LEN = strlen(words[i]); //Buchstaben zählen
|
||||||
|
int platziert = 0;
|
||||||
|
|
||||||
|
for(int try = 0; try < MAX_RAND_TRIES_PER_WORD; try++) // Max 10 Versuche pro Wort
|
||||||
|
{
|
||||||
|
Richtung dir = rand() % 2;
|
||||||
|
int passt = 1;
|
||||||
|
|
||||||
|
if(dir == HORIZONTAL)
|
||||||
|
{
|
||||||
|
|
||||||
|
Spalte = rand() % searchFieldLen;
|
||||||
|
Zeile = rand() % searchFieldLen;
|
||||||
|
|
||||||
|
if(Spalte + WORD_LEN <= searchFieldLen) // Prüft auf Border
|
||||||
|
{
|
||||||
|
|
||||||
|
for(int k = 0; k < WORD_LEN; k++)
|
||||||
|
{
|
||||||
|
if(salad[Zeile][Spalte+k] != EMPTY_CHAR) // Koalisionsprüfung
|
||||||
|
{
|
||||||
|
passt = 0; //Kollision gefunden
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(passt == 1)
|
||||||
|
{
|
||||||
|
for(int s = 0; s < WORD_LEN; s++)
|
||||||
|
{
|
||||||
|
salad[Zeile][Spalte + s] = words[i][s]; // Das Wort eintragen in einer Zeile
|
||||||
|
}
|
||||||
|
platziert = 1;
|
||||||
|
break; // Das Wort kann eingetragen werden, keine Kollision
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
else // Vertikal
|
||||||
|
{
|
||||||
|
|
||||||
|
Spalte = rand() % searchFieldLen;
|
||||||
|
Zeile = rand() % searchFieldLen;
|
||||||
|
if(Zeile + WORD_LEN <= searchFieldLen)
|
||||||
|
{
|
||||||
|
int passt = 1;
|
||||||
|
for(int k = 0; k < WORD_LEN; k++)
|
||||||
|
{
|
||||||
|
if(salad[Zeile+k][Spalte] != EMPTY_CHAR)
|
||||||
|
{
|
||||||
|
passt = 0; //Kollision gefunden
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(passt == 1)
|
||||||
|
{
|
||||||
|
for(int z = 0; z < WORD_LEN; z++)
|
||||||
|
{
|
||||||
|
salad[Zeile + z][Spalte] = words[i][z]; // // Das Wort eintragen in einer Spalte
|
||||||
|
}
|
||||||
|
platziert = 1;
|
||||||
|
break; // Das Wort kann eingetragen werden, keine Kollision
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(platziert == 1)
|
||||||
|
{
|
||||||
|
placeWords++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(int i = 0; i < searchFieldLen; i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < searchFieldLen; j++)
|
||||||
|
{
|
||||||
|
if(salad[i][j] == EMPTY_CHAR) // Nur wenn Feld noch frei ist, dann mit random Buchstaben belegen
|
||||||
|
{
|
||||||
|
salad[i][j] = 'A' + (rand() % 26);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return placeWords;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7,4 +7,5 @@
|
|||||||
|
|
||||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount);
|
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -4,9 +4,46 @@
|
|||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
||||||
|
int leseEinWort(FILE *file, char zielWort[])
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
int i = 0;
|
||||||
|
while((c = fgetc(file)) != EOF) // liest aus Textdatei und überprüft ob End Of File ist. fgetc liest exakt ein einzelnes Zeichen. fgetc komplette Zeile
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if(isalpha(c) != 0)
|
||||||
|
{
|
||||||
|
if(i < MAX_WORD_LEN - 1) // -1 wegen '\0'
|
||||||
|
{
|
||||||
|
zielWort[i] = (char)toupper(c); // Für Großbuchstaben
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(i > 0)
|
||||||
|
{
|
||||||
|
zielWort[i] = '\0';
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(i > 0) // Datei endet direkt nach ein WOrt ohne folgendes Leerzeichen oder so
|
||||||
|
{
|
||||||
|
zielWort[i] = '\0';
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
// Read words from file and store in 'words' array
|
// 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)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
int anzahl = 0;
|
||||||
|
while((anzahl < maxWordCount && leseEinWort(file, words[anzahl])) == 1)
|
||||||
|
{
|
||||||
|
anzahl++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return anzahl;
|
||||||
|
|
||||||
}
|
}
|
||||||
+12
-1
@@ -3,12 +3,14 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "graphicalGame.h"
|
#include "graphicalGame.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#define MAX_NUMBER_OF_WORDS 100
|
#define MAX_NUMBER_OF_WORDS 100
|
||||||
#define SALAD_SIZE 20
|
#define SALAD_SIZE 20
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
srand(time(NULL));
|
||||||
int exitCode = EXIT_SUCCESS;
|
int exitCode = EXIT_SUCCESS;
|
||||||
|
|
||||||
// Check if the correct number of arguments is provided
|
// Check if the correct number of arguments is provided
|
||||||
@@ -40,7 +42,16 @@ int main(int argc, char *argv[])
|
|||||||
// Check if all words were successfully placed
|
// Check if all words were successfully placed
|
||||||
// Start the game if successful
|
// Start the game if successful
|
||||||
// error message if some words couldn't be placed
|
// error message if some words couldn't be placed
|
||||||
|
if (placedWords == wordCount) // WEnn alle WÖrter reinpassen, rufe das grafische Fenster auf
|
||||||
|
{
|
||||||
|
// Start the graphical game with the generated word salad
|
||||||
|
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Could not place all words!\n");
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ codefolder = .
|
|||||||
# --------------------------
|
# --------------------------
|
||||||
wordsalad_initial:
|
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_myversion: main.o game.o graphicalGame.o
|
||||||
|
$(CC) $(CFLAGS) -o wordsalad_myversion main.o game.o graphicalGame.o -L. $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Normales Spiel bauen
|
# Normales Spiel bauen
|
||||||
|
|||||||
Reference in new issue
Block a user