Template
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2d35dfe89 | ||
|
|
6340b63273 | ||
|
|
f81b98bc1c | ||
|
|
2368d5aa38 | ||
|
|
cbfd7d5071 | ||
|
|
b55d0a22e6 | ||
|
|
9e22ee3299 | ||
|
|
54d2b81fae | ||
|
|
ae1adadfee | ||
|
|
7bd095a2bb | ||
|
|
96082d1781 | ||
|
|
8bf87d00ed | ||
|
|
a39f7748de |
No files matched your search
+85
-1
@@ -2,16 +2,100 @@
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#define MAX_RAND_TRIES_PER_WORD 10
|
||||
#define EMPTY_CHAR 0
|
||||
#define MAX_ATTEMPTS 42 //Die Antwort auf das Leben, das Universum, alles
|
||||
#define FEHLER_LAENGE_WORT -1
|
||||
#define FEHLER_SETZEN -2
|
||||
#define ERFOLG 1
|
||||
|
||||
//TODO: Spiellogik implementieren:
|
||||
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||
|
||||
// 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)
|
||||
{
|
||||
//befüllen des Arrays mit '\0'
|
||||
for(unsigned int i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for(unsigned int j = 0; j < searchFieldLen; j++)
|
||||
{
|
||||
salad[i][j] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
//erstellen von Richtungsvektoren
|
||||
int dx[] = {1, 0};
|
||||
int dy[] = {0, 1};
|
||||
//befüllen mit den Wörtern
|
||||
for(unsigned int w = 0; w < wordCount; w++)
|
||||
{
|
||||
int laenge = strlen(words[w]);
|
||||
//test ob Wort theoretisch reinpasst; was machen wir aber wenn ein Wort fast genauso lang ist wie das Feld? Wenn am Ende noch ein riesiges Wort eingesetzt werden soll, wird es nie reinpassen
|
||||
if(laenge > searchFieldLen)
|
||||
{
|
||||
return FEHLER_LAENGE_WORT;
|
||||
}
|
||||
|
||||
int placed = 0;
|
||||
int attempts = 0;
|
||||
|
||||
while(!placed && attempts < MAX_ATTEMPTS)
|
||||
{
|
||||
attempts =+ 1;
|
||||
int dir = rand() % 2; //Richtung: 0 = vertikal; 1 = horizontal
|
||||
int zeile = rand() % searchFieldLen;
|
||||
int spalte = rand() % searchFieldLen;
|
||||
|
||||
if ((dir == 0 && (zeile + laenge > searchFieldLen)) ||
|
||||
(dir == 1 && (spalte + laenge > searchFieldLen)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int kollision = 0;
|
||||
for(int i = 0; i < laenge; i++) //Kollision mit anderen Wörtern vermeiden
|
||||
{
|
||||
int z = zeile + dy[dir] * i;
|
||||
int s = spalte + dx[dir] * i;
|
||||
if(salad[z][s] != '\0' && salad[z][s] != words[w][i])
|
||||
{
|
||||
kollision = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!kollision) // keine kollision, also setzten der buchstaben
|
||||
{
|
||||
for(int i = 0; i < laenge; i++)
|
||||
{
|
||||
int z = zeile + dy[dir] * i;
|
||||
int s = spalte + dx[dir] * i;
|
||||
salad[z][s] = words[w][i];
|
||||
}
|
||||
placed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(!placed) //überprüft ob das Wort gesetzt wurde, wenn nicht Fehlerausgabe
|
||||
{
|
||||
return FEHLER_SETZEN;
|
||||
}
|
||||
}
|
||||
|
||||
//befüllen mit zufälligen Buchstaben
|
||||
for(unsigned int i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for(unsigned int j = 0; j < searchFieldLen; j++)
|
||||
{
|
||||
if(salad[i][j] == '\0')
|
||||
{
|
||||
salad[i][j] = 'A' + rand() % 26;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (int)wordCount;
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
#define MAX_MESSAGE_LEN 256
|
||||
#define MAX_SOLUTION_WORD_LEN 16
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Vector2 startPosition;
|
||||
|
||||
+37
-3
@@ -5,8 +5,42 @@
|
||||
// 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)
|
||||
{
|
||||
// Read words from file and store in 'words'
|
||||
|
||||
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN],
|
||||
unsigned int maxWordCount)
|
||||
{
|
||||
if (file == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char line[MAX_LINE_LEN];
|
||||
unsigned int wordCount = 0;
|
||||
|
||||
while (wordCount < maxWordCount &&
|
||||
fgets(line, sizeof(line), file) != NULL) {
|
||||
|
||||
char *word = strtok(line, " ,;\n\t\r");
|
||||
|
||||
while (word != NULL && wordCount < maxWordCount)
|
||||
{
|
||||
strncpy(words[wordCount], word, MAX_WORD_LEN - 1);
|
||||
words[wordCount][MAX_WORD_LEN - 1] = '\0';
|
||||
|
||||
unsigned int i = 0;
|
||||
|
||||
while (words[wordCount][i] != '\0') {
|
||||
words[wordCount][i] =
|
||||
(char)toupper((unsigned char)words[wordCount][i]);// char davor da toupper einen int wert liefert und einen unsigned char bekommt
|
||||
i++;
|
||||
}
|
||||
|
||||
wordCount++;
|
||||
|
||||
word = strtok(NULL, " ,;\n\t\r");
|
||||
}
|
||||
}
|
||||
|
||||
return (int)wordCount;
|
||||
}
|
||||
+19
-17
@@ -1,24 +1,26 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "input.h"
|
||||
#include "game.h"
|
||||
#include <time.h>
|
||||
#include "graphicalGame.h"
|
||||
|
||||
#define MAX_NUMBER_OF_WORDS 100
|
||||
#define SALAD_SIZE 20
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
int exitCode = EXIT_SUCCESS;
|
||||
|
||||
srand(time(NULL)); //Seed für Zufallszahlen
|
||||
|
||||
// Check if the correct number of arguments is provided
|
||||
if(argc != 2)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game
|
||||
unsigned int wordCount = 0;
|
||||
|
||||
@@ -36,19 +38,19 @@ int main(int argc, char *argv[])
|
||||
// Create the word salad by placing words into grid
|
||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
||||
|
||||
// TODO:
|
||||
// Check if all words were successfully placed
|
||||
// Start the game if successful
|
||||
// error message if some words couldn't be placed
|
||||
if (placedWords == (int)wordCount)
|
||||
{
|
||||
// Alle Wörter wurden erfolgreich platziert
|
||||
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Print error message if file couldn't be opened
|
||||
fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]);
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Print error message if file couldn't be opened
|
||||
fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]);
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Hund,Katze; Maus
|
||||
Whitespace-only changes.
@@ -0,0 +1,3 @@
|
||||
Apfel
|
||||
Banane
|
||||
Kiwi
|
||||
Reference in new issue
Block a user