Compare commits
21
Commits
bda856b9db
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5587ef787 | ||
|
|
d61e703a42 | ||
|
|
5d8f68558e | ||
|
|
00e3a50e8e | ||
|
|
6ecb30fdfe | ||
|
|
69decc037a | ||
|
|
a1cb0f9626 | ||
|
|
000bc1ebdf | ||
|
|
713355b1ac | ||
|
|
2a71e61f96 | ||
|
|
423506b80d | ||
|
|
0a627137fa | ||
|
|
22996a3363 | ||
|
|
5499bbcf2a | ||
|
|
14f6dd37f5 | ||
|
|
6b5ea6b989 | ||
|
|
a845fd7000 | ||
|
|
83f2ff4ec5 | ||
|
|
8a9bb66d8a | ||
|
|
8dc8b060f2 | ||
|
|
93da8ea94d |
No files matched your search
+86
-2
@@ -2,22 +2,106 @@
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX_RAND_TRIES_PER_WORD 10
|
||||
#define EMPTY_CHAR 0
|
||||
|
||||
//TODO: Spiellogik implementieren:
|
||||
//TODO: Spiellogik implementieren: | VERSION: Erfolgreicher Test 4 & 5 I
|
||||
/* * 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)
|
||||
{
|
||||
//Random Zeit initialisieren
|
||||
srand(time(NULL));
|
||||
|
||||
for (unsigned int i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for (unsigned int j = 0; j < searchFieldLen; j++)
|
||||
{
|
||||
salad[i][j] = EMPTY_CHAR;
|
||||
}
|
||||
}
|
||||
|
||||
int placed = 0; //Anzahl der Erfolgreich platzierten Worte
|
||||
|
||||
//Platzieren
|
||||
for (unsigned int w = 0; w < wordCount; w++)
|
||||
{
|
||||
const char *word = words[w];
|
||||
unsigned int wordLen = strlen(word);
|
||||
|
||||
for (int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD; attempt++)
|
||||
{
|
||||
int row = rand() % searchFieldLen;
|
||||
int col = rand() % searchFieldLen;
|
||||
int direction = rand() % 2;
|
||||
int canPlace = 1;
|
||||
|
||||
//Ob EIN Wort platziert werden kann (wird noch nicht platziert!)
|
||||
for (unsigned int k = 0; k < wordLen; k++)
|
||||
{
|
||||
int r = row + (direction == 1 ? k : 0);
|
||||
int c = col + (direction == 0 ? k : 0);
|
||||
|
||||
//Ränder des Spielfeldes beachten
|
||||
if (r >= (int)searchFieldLen || c >= (int)searchFieldLen)
|
||||
{
|
||||
canPlace = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
//Ist die Stelle nicht leer und passt Die stelle nicht zum passenden Buchstaben des Wortes
|
||||
if (salad[r][c] != EMPTY_CHAR && salad[r][c] != word[k])
|
||||
{
|
||||
canPlace = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (canPlace) //Wenn geprüft wurde ob ein Wort erfolgreich platziert werden kann.
|
||||
{
|
||||
for (unsigned int k = 0; k < wordLen; k++)
|
||||
{
|
||||
int r = row + (direction == 1 ? k : 0);
|
||||
int c = col + (direction == 0 ? k : 0);
|
||||
if (r < (int)searchFieldLen && c < (int)searchFieldLen)
|
||||
salad[r][c] = word[k];
|
||||
}
|
||||
placed++;
|
||||
break; //Beim Nächsten Wort weiter machen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Mit Zufälligen Buchstaben füllen
|
||||
for (unsigned int i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for (unsigned int j = 0; j < searchFieldLen; j++)
|
||||
{
|
||||
if (salad[i][j] == EMPTY_CHAR)
|
||||
{
|
||||
salad[i][j] = 'A' + (rand() % 26);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return placed;
|
||||
}
|
||||
|
||||
|
||||
// Prints the word salad to console
|
||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||
{
|
||||
|
||||
for (unsigned int i = 0; i < searchFieldLen; i++)
|
||||
{
|
||||
for (unsigned int j = 0; j < searchFieldLen; j++)
|
||||
{
|
||||
printf("%c ", salad[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
+33
-2
@@ -1,12 +1,43 @@
|
||||
#include "input.h"
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#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)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
int c;
|
||||
unsigned int idx = 0;
|
||||
|
||||
if (!file) return 0;
|
||||
|
||||
while ((c = fgetc(file)) != EOF && count < maxWordCount) {
|
||||
if (isalpha((unsigned char)c)) {
|
||||
if (idx < MAX_WORD_LEN - 1) {
|
||||
words[count][idx++] = (char) toupper((unsigned char)c);
|
||||
} else {
|
||||
// word too long: truncate remaining letters until delimiter
|
||||
idx = MAX_WORD_LEN - 1;
|
||||
}
|
||||
} else {
|
||||
if (idx > 0) {
|
||||
words[count][idx] = '\0';
|
||||
count++;
|
||||
idx = 0;
|
||||
}
|
||||
// skip consecutive delimiters
|
||||
}
|
||||
}
|
||||
|
||||
// If file ended while reading a word, terminate and count it
|
||||
if (idx > 0 && count < maxWordCount) {
|
||||
words[count][idx] = '\0';
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
+7
-7
@@ -36,22 +36,22 @@ int main(int argc, char *argv[])
|
||||
// Create the word salad by placing words into grid
|
||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
||||
|
||||
// TODO:
|
||||
// TODO: (erledigt von Niklas)
|
||||
// Check if all words were successfully placed
|
||||
// Start the game if successful
|
||||
// error message if some words couldn't be placed
|
||||
|
||||
if (placedWords == wordCount)
|
||||
if (placedWords == wordCount) //überprüfung: alle wörter im gitter
|
||||
{
|
||||
printf("All words have been placed successfully.\n");
|
||||
// Start graphical game
|
||||
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
|
||||
|
||||
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800); //header datei wird ausgeführt
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Error: Only %u out of %u words could be placed.\n", placedWords, wordCount);
|
||||
fprintf(stderr, "Try reducing the number or length of words.\n");
|
||||
exitCode = EXIT_FAILURE;
|
||||
fprintf(stderr, "Error: Only %u out of %u words could be placed.\n", placedWords, wordCount); //fprintf in selbst gewählter ausgabe
|
||||
fprintf(stderr, "Try reducing the number or length of words.\n"); // std err = error
|
||||
exitCode = EXIT_FAILURE; //exit_failure von der stdlib eine funktion => fehler beim ausführen; wert = 1
|
||||
}
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+30
-29
@@ -7,26 +7,28 @@
|
||||
#define MAX_RAND_TRIES_PER_WORD 10
|
||||
#define EMPTY_CHAR 0
|
||||
|
||||
//TODO: Spiellogik implementieren:
|
||||
//TODO: Spiellogik implementieren: | VERSION: Erfolgreicher Test 4 & 5 I
|
||||
/* * 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)
|
||||
{
|
||||
// Zufall initialisieren
|
||||
//Random Zeit initialisieren
|
||||
srand(time(NULL));
|
||||
|
||||
// 1. Spielfeld leeren
|
||||
for (unsigned int i = 0; i < searchFieldLen; i++)
|
||||
//Matrix leeren
|
||||
for (unsigned int x = 0; x < searchFieldLen; x++)
|
||||
{
|
||||
for (unsigned int j = 0; j < searchFieldLen; j++)
|
||||
for (unsigned int y = 0; y < searchFieldLen; y++)
|
||||
{
|
||||
salad[i][j] = EMPTY_CHAR;
|
||||
salad[x][y] = EMPTY_CHAR;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Wörter platzieren
|
||||
int placed = 0; //Anzahl der Erfolgreich platzierten Worte
|
||||
|
||||
//Platzieren
|
||||
for (unsigned int w = 0; w < wordCount; w++)
|
||||
{
|
||||
const char *word = words[w];
|
||||
@@ -34,29 +36,26 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
|
||||
for (int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD; attempt++)
|
||||
{
|
||||
// zufällige Startposition
|
||||
//random kästchen in der matrix auswählen zwischen 0 und searchfieldlen (row,col)
|
||||
int row = rand() % searchFieldLen;
|
||||
int col = rand() % searchFieldLen;
|
||||
|
||||
// zufällige Richtung: 0 = horizontal, 1 = vertikal
|
||||
int direction = rand() % 2;
|
||||
|
||||
int direction = rand() % 2; //0 = horizontal; 1 = vertikal
|
||||
int canPlace = 1;
|
||||
|
||||
// Nur prüfen, ob Buchstaben passen (gleiche erlaubt, leer erlaubt)
|
||||
//Ob EIN Wort platziert werden kann (wird noch nicht platziert!)
|
||||
for (unsigned int k = 0; k < wordLen; k++)
|
||||
{
|
||||
int r = row + (direction == 1 ? k : 0);
|
||||
int c = col + (direction == 0 ? k : 0);
|
||||
int r = row + (direction == 1 ? k : 0); //buchstaben werden vertikal darunter gestzt wenn direction = 1 (neue zeile)
|
||||
int c = col + (direction == 0 ? k : 0); //buchstaben werden horizontal rechts daneben gesetzt wenn direction = 0 (neue spalte)
|
||||
|
||||
// Wenn außerhalb des Feldes -> abbrechen
|
||||
//Ränder des Spielfeldes beachten
|
||||
if (r >= (int)searchFieldLen || c >= (int)searchFieldLen)
|
||||
{
|
||||
canPlace = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// Wenn belegt mit anderem Buchstaben -> abbrechen
|
||||
//Ist die Stelle schon besetzt und passt Die stelle nicht zum passenden Buchstaben des Wortes
|
||||
if (salad[r][c] != EMPTY_CHAR && salad[r][c] != word[k])
|
||||
{
|
||||
canPlace = 0;
|
||||
@@ -64,9 +63,9 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
}
|
||||
}
|
||||
|
||||
// Wenn möglich, das Wort setzen
|
||||
if (canPlace)
|
||||
if (canPlace) //Wenn geprüft wurde ob ein Wort erfolgreich platziert werden kann.
|
||||
{
|
||||
//platzieren der buchstaben
|
||||
for (unsigned int k = 0; k < wordLen; k++)
|
||||
{
|
||||
int r = row + (direction == 1 ? k : 0);
|
||||
@@ -74,34 +73,36 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
if (r < (int)searchFieldLen && c < (int)searchFieldLen)
|
||||
salad[r][c] = word[k];
|
||||
}
|
||||
break; // Wort erfolgreich platziert
|
||||
placed++;
|
||||
break; //Beim Nächsten Wort weiter machen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Leere Felder mit Zufallsbuchstaben füllen
|
||||
for (unsigned int i = 0; i < searchFieldLen; i++)
|
||||
//Mit Zufälligen Buchstaben füllen
|
||||
for (unsigned int x = 0; x < searchFieldLen; x++)
|
||||
{
|
||||
for (unsigned int j = 0; j < searchFieldLen; j++)
|
||||
for (unsigned int y = 0; y < searchFieldLen; y++)
|
||||
{
|
||||
if (salad[i][j] == EMPTY_CHAR)
|
||||
if (salad[x][y] == EMPTY_CHAR)
|
||||
{
|
||||
salad[i][j] = 'A' + (rand() % 26);
|
||||
salad[x][y] = 'A' + (rand() % 26); //random buchstabe zw A und Z platzieren
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return placed;
|
||||
}
|
||||
|
||||
|
||||
// Prints the word salad to console
|
||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||
{
|
||||
for (unsigned int i = 0; i < searchFieldLen; i++)
|
||||
for (unsigned int x = 0; x < searchFieldLen; x++)
|
||||
{
|
||||
for (unsigned int j = 0; j < searchFieldLen; j++)
|
||||
for (unsigned int y = 0; y < searchFieldLen; y++)
|
||||
{
|
||||
printf("%c ", salad[i][j]);
|
||||
printf("%c ", salad[x][y]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
+44
-4
@@ -1,12 +1,52 @@
|
||||
#include "input.h"
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// TODO:
|
||||
// TODO: | VERSION: Erfolgreicher Test 1,2 & 3
|
||||
// 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)
|
||||
{
|
||||
printf("Hallo");
|
||||
}
|
||||
unsigned int count = 0;
|
||||
int c;
|
||||
unsigned int idx = 0;
|
||||
|
||||
if (!file) return 0; //Wenn keine file gefunden oder geöffnet wurde
|
||||
|
||||
//scannt jedes zeichen in der file durch bis zum end of file oder bis es genug wörter hat
|
||||
while ((c = fgetc(file)) != EOF && count < maxWordCount)
|
||||
{
|
||||
if (isalpha((unsigned char)c))// prüft ob das zeichen ein buchstabe ist (also kein komma oder leerzeichen usw)
|
||||
{
|
||||
//macht die buchstaben zu Großbuchstaben und schreibt sie ins array (toupper)
|
||||
//prüft ob das wort kurz genug ist
|
||||
if (idx < MAX_WORD_LEN - 1)
|
||||
{
|
||||
words[count][idx++] = (char) toupper((unsigned char)c);
|
||||
} else
|
||||
{
|
||||
// word too long: schneidet das ende vom wort ab bis es reinpasst
|
||||
idx = MAX_WORD_LEN - 1;
|
||||
}
|
||||
} else // bei leerzeichen, komma usw
|
||||
{
|
||||
if (idx > 0) //wort endet -> \0 ;stellt den idx wieder auf 0; neues wort beginnt -> count++
|
||||
{
|
||||
words[count][idx] = '\0';
|
||||
count++;
|
||||
idx = 0;
|
||||
}
|
||||
// skip consecutive delimiters
|
||||
}
|
||||
}
|
||||
|
||||
//Erkennung vom Ende der file wenn das letze wort endet und wort counten
|
||||
if (idx > 0 && count < maxWordCount) {
|
||||
words[count][idx] = '\0';
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
+17
-2
@@ -36,15 +36,30 @@ int main(int argc, char *argv[])
|
||||
// Create the word salad by placing words into grid
|
||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
||||
|
||||
// TODO:
|
||||
// TODO: (erledigt von Niklas)
|
||||
// Check if all words were successfully placed
|
||||
// Start the game if successful
|
||||
// error message if some words couldn't be placed
|
||||
|
||||
|
||||
//prüft ob die die anzahl der wörter und der tatsächlich platzierten wörter übereinstimmen
|
||||
if (placedWords == wordCount)
|
||||
{
|
||||
printf("All words have been placed successfully.\n");
|
||||
// Start graphical game
|
||||
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Error: Only %u out of %u words could be placed.\n", placedWords, wordCount);
|
||||
fprintf(stderr, "Try reducing the number or length of words.\n");
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Print error message if file couldn't be opened
|
||||
//Wenn die file nicht geöffnet werden konnte
|
||||
fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]);
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
CC = gcc
|
||||
CFLAGS = -g -Wall -I$(raylibfolder)
|
||||
CFLAGS = -g -Wall
|
||||
LDFLAGS = -lopengl32 -lgdi32 -lwinmm
|
||||
BINARIES = ./windows
|
||||
|
||||
raylib_folder = ./raylib
|
||||
raylibfolder = ./raylib
|
||||
unityfolder = ./unity
|
||||
|
||||
# --------------------------
|
||||
@@ -12,7 +12,6 @@ unityfolder = ./unity
|
||||
wordsalad_initial:
|
||||
$(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||
|
||||
|
||||
# --------------------------
|
||||
# Normales Spiel bauen
|
||||
# --------------------------
|
||||
@@ -23,13 +22,13 @@ main.o: main.c
|
||||
$(CC) -c $(CFLAGS) main.c
|
||||
|
||||
input.o: input.c
|
||||
$(CC) -c $(CFLAGS)input.c
|
||||
$(CC) -c $(CFLAGS) input.c
|
||||
|
||||
game.o: game.c
|
||||
$(CC) -c $(CFLAGS) game.c
|
||||
|
||||
graphicalGame.o: graphicalGame.c
|
||||
$(CC) -I$(raylib_folder) -c $(CFLAGS) graphicalGame.c
|
||||
$(CC) -I$(raylibfolder) -c $(CFLAGS) graphicalGame.c
|
||||
|
||||
# --------------------------
|
||||
# Unit Tests
|
||||
@@ -44,3 +43,6 @@ test: input.o game.o unit_tests.c
|
||||
# --------------------------
|
||||
clean:
|
||||
del /f *.o *.exe
|
||||
|
||||
wordsalad_myversion: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
|
||||
$(CC) $(CFLAGS) -o wordsalad_myversion main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||
@@ -2,4 +2,5 @@ Yeti,Nessie Werwolf; Vampir
|
||||
Monster
|
||||
Hydra;Frankenstein
|
||||
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
|
||||
Gespenst, Ogerp
|
||||
Gespenst, Oger
|
||||
AHHHHHHH
|
||||
Reference in new issue
Block a user