Fertiges Programm
This commit is contained in:
parent
81cd68b949
commit
d914e8aebf
Binary file not shown.
@ -1,9 +1,9 @@
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -g -Wall -I$(raylibfolder)
|
CFLAGS = -g -Wall
|
||||||
LDFLAGS = -lGL -lX11 -lm
|
LDFLAGS = -lGL -lX11 -lm
|
||||||
BINARIES = ./linux
|
BINARIES = ./linux
|
||||||
|
|
||||||
raylib_folder = ./raylib
|
raylibfolder = ./raylib
|
||||||
unityfolder = ./unity
|
unityfolder = ./unity
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
@ -28,7 +28,7 @@ game.o: game.c
|
|||||||
$(CC) $(CFLAGS) -c game.c
|
$(CC) $(CFLAGS) -c game.c
|
||||||
|
|
||||||
graphicalGame.o: graphicalGame.c
|
graphicalGame.o: graphicalGame.c
|
||||||
$(CC) $(CFLAGS) -c graphicalGame.c
|
$(CC) $(CFLAGS) -I$(raylibfolder) -c graphicalGame.c
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Unit Tests
|
# Unit Tests
|
||||||
|
|||||||
@ -101,7 +101,37 @@ void test_createWordSalad_too_small(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_createWordSalad_allWordsPlaced() {
|
||||||
|
char words[3][MAX_WORD_LEN] = {"CAT", "DOG", "MOUSE"};
|
||||||
|
char saladHoriz[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
||||||
|
char saladVert[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
||||||
|
|
||||||
|
int placed = createWordSalad(saladHoriz, 20, words, 3);
|
||||||
|
for(int i = 0; i < MAX_SEARCH_FIELD_LEN; i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++)
|
||||||
|
{
|
||||||
|
saladVert[j][i] = saladHoriz[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < 3; i++) {
|
||||||
|
const char* word = words[i];
|
||||||
|
int wordFound = 0;
|
||||||
|
for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++)
|
||||||
|
{
|
||||||
|
const char* row = saladHoriz[j];
|
||||||
|
const char* col = saladVert[j];
|
||||||
|
wordFound |= strstr(row, word) || strstr(col, word);
|
||||||
|
}
|
||||||
|
TEST_ASSERT_TRUE_MESSAGE(wordFound, "Not all words were placed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_INT(3, placed);
|
||||||
|
}
|
||||||
|
|
||||||
// ---------- Test Setup und TearDown Funktionen ----------
|
// ---------- Test Setup und TearDown Funktionen ----------
|
||||||
|
|
||||||
// Hier Setup- und TearDown-Funktionen definieren,
|
// Hier Setup- und TearDown-Funktionen definieren,
|
||||||
// falls Vor- und Nachbereitungen für die Tests benötigt.
|
// falls Vor- und Nachbereitungen für die Tests benötigt.
|
||||||
|
|
||||||
@ -134,6 +164,7 @@ int main(void) {
|
|||||||
RUN_TEST(test_readWords_empty_file);
|
RUN_TEST(test_readWords_empty_file);
|
||||||
RUN_TEST(test_createWordSalad_all_fit);
|
RUN_TEST(test_createWordSalad_all_fit);
|
||||||
RUN_TEST(test_createWordSalad_too_small);
|
RUN_TEST(test_createWordSalad_too_small);
|
||||||
|
RUN_TEST(test_createWordSalad_allWordsPlaced);
|
||||||
|
|
||||||
int result = UNITY_END(); // Test-Ergebnisse
|
int result = UNITY_END(); // Test-Ergebnisse
|
||||||
print_test_result(result);
|
print_test_result(result);
|
||||||
|
|||||||
BIN
Start_Mac/macos-x86_64/libraylib.a
Normal file
BIN
Start_Mac/macos-x86_64/libraylib.a
Normal file
Binary file not shown.
BIN
Start_Mac/macos-x86_64/libunity.a
Normal file
BIN
Start_Mac/macos-x86_64/libunity.a
Normal file
Binary file not shown.
BIN
Start_Mac/macos-x86_64/libwordsalad.a
Normal file
BIN
Start_Mac/macos-x86_64/libwordsalad.a
Normal file
Binary file not shown.
BIN
Start_Mac/macos-x86_64/libwordsalad_complete.a
Normal file
BIN
Start_Mac/macos-x86_64/libwordsalad_complete.a
Normal file
Binary file not shown.
@ -4,7 +4,7 @@ LDFLAGS = -framework OpenGL -framework CoreFoundation -framework CoreGraphics -f
|
|||||||
ARCH := $(shell uname -m)
|
ARCH := $(shell uname -m)
|
||||||
BINARIES = ./macos-$(ARCH)
|
BINARIES = ./macos-$(ARCH)
|
||||||
|
|
||||||
raylib_folder = ./raylib
|
raylibfolder = ./raylib
|
||||||
unityfolder = ./unity
|
unityfolder = ./unity
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
@ -43,4 +43,4 @@ test: input.o game.o unit_tests.c $(BINARIES)/libunity.a
|
|||||||
# Clean
|
# Clean
|
||||||
# --------------------------
|
# --------------------------
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o wordsalad
|
rm -f *.o wordsalad $(TEST_BIN)
|
||||||
|
|||||||
@ -101,6 +101,35 @@ void test_createWordSalad_too_small(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_createWordSalad_allWordsPlaced() {
|
||||||
|
char words[3][MAX_WORD_LEN] = {"CAT", "DOG", "MOUSE"};
|
||||||
|
char saladHoriz[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
||||||
|
char saladVert[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
||||||
|
|
||||||
|
int placed = createWordSalad(saladHoriz, 20, words, 3);
|
||||||
|
for(int i = 0; i < MAX_SEARCH_FIELD_LEN; i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++)
|
||||||
|
{
|
||||||
|
saladVert[j][i] = saladHoriz[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < 3; i++) {
|
||||||
|
const char* word = words[i];
|
||||||
|
int wordFound = 0;
|
||||||
|
for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++)
|
||||||
|
{
|
||||||
|
const char* row = saladHoriz[j];
|
||||||
|
const char* col = saladVert[j];
|
||||||
|
wordFound |= strstr(row, word) || strstr(col, word);
|
||||||
|
}
|
||||||
|
TEST_ASSERT_TRUE_MESSAGE(wordFound, "Not all words were placed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_INT(3, placed);
|
||||||
|
}
|
||||||
|
|
||||||
// ---------- Test Setup und TearDown Funktionen ----------
|
// ---------- Test Setup und TearDown Funktionen ----------
|
||||||
|
|
||||||
// Hier Setup- und TearDown-Funktionen definieren,
|
// Hier Setup- und TearDown-Funktionen definieren,
|
||||||
@ -135,6 +164,7 @@ int main(void) {
|
|||||||
RUN_TEST(test_readWords_empty_file);
|
RUN_TEST(test_readWords_empty_file);
|
||||||
RUN_TEST(test_createWordSalad_all_fit);
|
RUN_TEST(test_createWordSalad_all_fit);
|
||||||
RUN_TEST(test_createWordSalad_too_small);
|
RUN_TEST(test_createWordSalad_too_small);
|
||||||
|
RUN_TEST(test_createWordSalad_allWordsPlaced);
|
||||||
|
|
||||||
int result = UNITY_END(); // Test-Ergebnisse
|
int result = UNITY_END(); // Test-Ergebnisse
|
||||||
print_test_result(result);
|
print_test_result(result);
|
||||||
|
|||||||
@ -13,11 +13,109 @@
|
|||||||
// Creates the word salad by placing words randomly and filling empty spaces
|
// 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)
|
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));
|
||||||
|
// wipe field
|
||||||
|
int placedWords = 0;
|
||||||
|
for (int i = 0; i < searchFieldLen; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < searchFieldLen ; j++)
|
||||||
|
salad[i][j] = EMPTY_CHAR;
|
||||||
|
}
|
||||||
|
// place Words
|
||||||
|
for (int wordNumber = 0; wordNumber < wordCount; wordNumber++)
|
||||||
|
{
|
||||||
|
int wordlength = strlen(words[wordNumber]);
|
||||||
|
|
||||||
|
int placed = 0;
|
||||||
|
|
||||||
|
for (int try = 0; (try < MAX_RAND_TRIES_PER_WORD) && !placed; try++)
|
||||||
|
{
|
||||||
|
int horizontal = rand() % 2; // 0 vertikal --> 1 horizontal
|
||||||
|
|
||||||
|
int x = rand() % searchFieldLen;
|
||||||
|
int y = rand() % searchFieldLen;
|
||||||
|
|
||||||
|
if (horizontal)
|
||||||
|
{
|
||||||
|
if (x + wordlength > searchFieldLen) // word does not fit
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fits = 1;
|
||||||
|
|
||||||
|
for (int i = 0; i < wordlength; i++) // position already occupied by other word
|
||||||
|
{
|
||||||
|
if (salad[y][x + i] != EMPTY_CHAR)
|
||||||
|
{
|
||||||
|
fits = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fits)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < wordlength; i++)
|
||||||
|
{
|
||||||
|
salad[y][x + i] = words[wordNumber][i];
|
||||||
|
}
|
||||||
|
placed = 1;
|
||||||
|
placedWords++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ((y + wordlength) > searchFieldLen)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fits = 1;
|
||||||
|
|
||||||
|
for (int i = 0; i < wordlength; i++) // position already occupied by other word
|
||||||
|
{
|
||||||
|
if (salad[y + i][x] != EMPTY_CHAR)
|
||||||
|
{
|
||||||
|
fits = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fits)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < wordlength; i++)
|
||||||
|
{
|
||||||
|
salad[y + i][x] = words[wordNumber][i];
|
||||||
|
}
|
||||||
|
placed = 1;
|
||||||
|
placedWords++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// fill rest with random characters
|
||||||
|
|
||||||
|
for (int i = 0; i < searchFieldLen; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < searchFieldLen; j++)
|
||||||
|
{
|
||||||
|
if (salad[i][j] == EMPTY_CHAR)
|
||||||
|
{
|
||||||
|
salad[i][j] = rand() % ('Z' - 'A' + 1) + 'A'; // 90 ist Z in ASCII und A ist 65
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return placedWords;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the word salad to console
|
// Prints the word salad to console
|
||||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
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 j = 0; j < searchFieldLen; j++)
|
||||||
|
{
|
||||||
|
printf("%c", salad[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Start_Windows/game.o
Normal file
BIN
Start_Windows/game.o
Normal file
Binary file not shown.
BIN
Start_Windows/graphicalGame.o
Normal file
BIN
Start_Windows/graphicalGame.o
Normal file
Binary file not shown.
@ -8,5 +8,35 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
|
//kein fopen und fclose nötig, weil dies schon in der main passiert und mit *file übergeben wird//
|
||||||
|
|
||||||
|
|
||||||
|
if (file == NULL)
|
||||||
|
{
|
||||||
|
perror("Error invalid pointer to file");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char line[1024];
|
||||||
|
unsigned int count = 0;
|
||||||
|
|
||||||
|
while (fgets(line, sizeof(line), file) && (count < maxWordCount))
|
||||||
|
{
|
||||||
|
line[strcspn(line, "\n")] = '\0';
|
||||||
|
|
||||||
|
char *token = strtok(line, " ;,");
|
||||||
|
while (token && (count < maxWordCount))
|
||||||
|
{
|
||||||
|
for (int i = 0; token[i] != '\0'; i++)
|
||||||
|
{
|
||||||
|
token[i] = toupper(token[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(words[count], token);
|
||||||
|
count++;
|
||||||
|
token = strtok(NULL, " ;,");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|||||||
BIN
Start_Windows/input.o
Normal file
BIN
Start_Windows/input.o
Normal file
Binary file not shown.
@ -40,7 +40,14 @@ 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 (wordCount != placedWords)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error: %u out of %u were placed\n", placedWords, wordCount);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
startGame(wordSalad, SALAD_SIZE, words, placedWords, 1024);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
BIN
Start_Windows/main.o
Normal file
BIN
Start_Windows/main.o
Normal file
Binary file not shown.
@ -1,18 +1,23 @@
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -g -Wall -I$(raylibfolder)
|
CFLAGS = -g -Wall
|
||||||
LDFLAGS = -lopengl32 -lgdi32 -lwinmm
|
LDFLAGS = -lopengl32 -lgdi32 -lwinmm
|
||||||
BINARIES = ./windows
|
BINARIES = ./windows
|
||||||
|
|
||||||
raylib_folder = ./raylib
|
raylibfolder = ./raylib
|
||||||
unityfolder = ./unity
|
unityfolder = ./unity
|
||||||
|
|
||||||
|
# --------------------------
|
||||||
|
# my version
|
||||||
|
# --------------------------
|
||||||
|
wordsalad_myversion: main.o graphicalGame.o
|
||||||
|
$(CC) main.o graphicalGame.o -o wordsalad_myversion $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# initiales Spiel bauen
|
# initiales Spiel bauen
|
||||||
# --------------------------
|
# --------------------------
|
||||||
wordsalad_initial:
|
wordsalad_initial:
|
||||||
$(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
$(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Normales Spiel bauen
|
# Normales Spiel bauen
|
||||||
# --------------------------
|
# --------------------------
|
||||||
@ -29,7 +34,7 @@ game.o: game.c
|
|||||||
$(CC) -c $(CFLAGS) game.c
|
$(CC) -c $(CFLAGS) game.c
|
||||||
|
|
||||||
graphicalGame.o: graphicalGame.c
|
graphicalGame.o: graphicalGame.c
|
||||||
$(CC) -I$(raylib_folder) -c $(CFLAGS) graphicalGame.c
|
$(CC) -I$(raylibfolder) -c $(CFLAGS) graphicalGame.c
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Unit Tests
|
# Unit Tests
|
||||||
|
|||||||
BIN
Start_Windows/runTests.exe
Normal file
BIN
Start_Windows/runTests.exe
Normal file
Binary file not shown.
@ -101,6 +101,35 @@ void test_createWordSalad_too_small(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_createWordSalad_allWordsPlaced() {
|
||||||
|
char words[3][MAX_WORD_LEN] = {"CAT", "DOG", "MOUSE"};
|
||||||
|
char saladHoriz[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
||||||
|
char saladVert[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
||||||
|
|
||||||
|
int placed = createWordSalad(saladHoriz, 20, words, 3);
|
||||||
|
for(int i = 0; i < MAX_SEARCH_FIELD_LEN; i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++)
|
||||||
|
{
|
||||||
|
saladVert[j][i] = saladHoriz[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < 3; i++) {
|
||||||
|
const char* word = words[i];
|
||||||
|
int wordFound = 0;
|
||||||
|
for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++)
|
||||||
|
{
|
||||||
|
const char* row = saladHoriz[j];
|
||||||
|
const char* col = saladVert[j];
|
||||||
|
wordFound |= strstr(row, word) || strstr(col, word);
|
||||||
|
}
|
||||||
|
TEST_ASSERT_TRUE_MESSAGE(wordFound, "Not all words were placed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_INT(3, placed);
|
||||||
|
}
|
||||||
|
|
||||||
// ---------- Test Setup und TearDown Funktionen ----------
|
// ---------- Test Setup und TearDown Funktionen ----------
|
||||||
|
|
||||||
// Hier Setup- und TearDown-Funktionen definieren,
|
// Hier Setup- und TearDown-Funktionen definieren,
|
||||||
@ -135,6 +164,7 @@ int main(void) {
|
|||||||
RUN_TEST(test_readWords_empty_file);
|
RUN_TEST(test_readWords_empty_file);
|
||||||
RUN_TEST(test_createWordSalad_all_fit);
|
RUN_TEST(test_createWordSalad_all_fit);
|
||||||
RUN_TEST(test_createWordSalad_too_small);
|
RUN_TEST(test_createWordSalad_too_small);
|
||||||
|
RUN_TEST(test_createWordSalad_allWordsPlaced);
|
||||||
|
|
||||||
int result = UNITY_END(); // Test-Ergebnisse
|
int result = UNITY_END(); // Test-Ergebnisse
|
||||||
print_test_result(result);
|
print_test_result(result);
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
Yeti,Nessie Werwolf; Vampir
|
Multiplikation, Division, Addition, Subtraktion, Term
|
||||||
Monster
|
Bruch
|
||||||
Hydra;Frankenstein
|
Nenner, Zaehler, Daten, Saeulendiagramm
|
||||||
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
|
|
||||||
Gespenst, Oger
|
|
||||||
BIN
Start_Windows/wordsalad_myversion.exe
Normal file
BIN
Start_Windows/wordsalad_myversion.exe
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user