Template
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a75c51c13a | ||
|
|
35d7a0822f | ||
|
|
3a00180f02 |
-62
@@ -1,62 +0,0 @@
|
|||||||
# ---> C
|
|
||||||
# Prerequisites
|
|
||||||
*.d
|
|
||||||
|
|
||||||
# Object files
|
|
||||||
*.o
|
|
||||||
*.ko
|
|
||||||
*.obj
|
|
||||||
*.elf
|
|
||||||
|
|
||||||
# Linker output
|
|
||||||
*.ilk
|
|
||||||
*.map
|
|
||||||
*.exp
|
|
||||||
|
|
||||||
# Precompiled Headers
|
|
||||||
*.gch
|
|
||||||
*.pch
|
|
||||||
|
|
||||||
# Libraries
|
|
||||||
*.lib
|
|
||||||
*.la
|
|
||||||
*.lo
|
|
||||||
|
|
||||||
# Shared objects (inc. Windows DLLs)
|
|
||||||
*.dll
|
|
||||||
*.so
|
|
||||||
*.so.*
|
|
||||||
*.dylib
|
|
||||||
|
|
||||||
# Executables
|
|
||||||
*.exe
|
|
||||||
*.out
|
|
||||||
*.app
|
|
||||||
*.i*86
|
|
||||||
*.x86_64
|
|
||||||
*.hex
|
|
||||||
Startcode/wordsalad_initial
|
|
||||||
Startcode/wordsalad
|
|
||||||
test
|
|
||||||
|
|
||||||
# Debug files
|
|
||||||
*.dSYM/
|
|
||||||
*.su
|
|
||||||
*.idb
|
|
||||||
*.pdb
|
|
||||||
|
|
||||||
# Kernel Module Compile Results
|
|
||||||
*.mod*
|
|
||||||
*.cmd
|
|
||||||
.tmp_versions/
|
|
||||||
modules.order
|
|
||||||
Module.symvers
|
|
||||||
Mkfile.old
|
|
||||||
dkms.conf
|
|
||||||
|
|
||||||
# IDE folders
|
|
||||||
.vscode/
|
|
||||||
.idea/
|
|
||||||
|
|
||||||
# macOS
|
|
||||||
.DS_Store
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,17 +0,0 @@
|
|||||||
#include "game.h"
|
|
||||||
#include <time.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define MAX_RAND_TRIES_PER_WORD 10
|
|
||||||
#define EMPTY_CHAR 0
|
|
||||||
|
|
||||||
//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)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#include "input.h"
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.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)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,59 +0,0 @@
|
|||||||
CC = gcc
|
|
||||||
CFLAGS = -g -Wall
|
|
||||||
|
|
||||||
ifeq ($(OS),Windows_NT)
|
|
||||||
include makefile_windows.variables
|
|
||||||
else
|
|
||||||
UNAME = $(shell uname)
|
|
||||||
ifeq ($(UNAME),Linux)
|
|
||||||
include makefile_linux.variables
|
|
||||||
else
|
|
||||||
include makefile_mac.variables
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
raylibfolder = ./raylib
|
|
||||||
unityfolder = ./unity
|
|
||||||
codefolder = .
|
|
||||||
|
|
||||||
# --------------------------
|
|
||||||
# initiales Spiel bauen
|
|
||||||
# --------------------------
|
|
||||||
wordsalad_initial:
|
|
||||||
$(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
|
||||||
|
|
||||||
# --------------------------
|
|
||||||
# Normales Spiel bauen
|
|
||||||
# --------------------------
|
|
||||||
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: $(codefolder)/main.c
|
|
||||||
$(CC) -c $(CFLAGS) $(codefolder)/main.c
|
|
||||||
|
|
||||||
input.o: $(codefolder)/input.c
|
|
||||||
$(CC) -c $(CFLAGS) $(codefolder)/input.c
|
|
||||||
|
|
||||||
game.o: $(codefolder)/game.c
|
|
||||||
$(CC) -c $(CFLAGS) $(codefolder)/game.c
|
|
||||||
|
|
||||||
graphicalGame.o: $(codefolder)/graphicalGame.c
|
|
||||||
$(CC) -I$(raylibfolder) -c $(CFLAGS) $(codefolder)/graphicalGame.c
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------
|
|
||||||
# Unit Tests
|
|
||||||
# --------------------------
|
|
||||||
TEST_BIN = runTests
|
|
||||||
|
|
||||||
test: input.o game.o $(codefolder)/unit_tests.c $(unityfolder)/unity.c
|
|
||||||
$(CC) -Wall -I$(unityfolder) -o $(TEST_BIN) input.o game.o $(codefolder)/unit_tests.c $(unityfolder)/unity.c
|
|
||||||
# --------------------------
|
|
||||||
# Clean
|
|
||||||
# --------------------------
|
|
||||||
clean:
|
|
||||||
ifeq ($(OS),Windows_NT)
|
|
||||||
del /f *.o *.exe
|
|
||||||
else
|
|
||||||
rm -f *.o wordsalad $(TEST_BIN)
|
|
||||||
endif
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
LDFLAGS = -lGL -lX11 -lm
|
|
||||||
BINARIES = ./linux
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
LDFLAGS = -framework OpenGL -framework CoreFoundation -framework CoreGraphics -framework IOKit -framework Cocoa -framework CoreVideo
|
|
||||||
ARCH := $(shell uname -m)
|
|
||||||
BINARIES = ./macos-$(ARCH)
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
LDFLAGS = -lopengl32 -lgdi32 -lwinmm
|
|
||||||
BINARIES = ./windows
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
Copyright (c) 2013-2025 Ramon Santamaria (@raysan5)
|
|
||||||
|
|
||||||
This software is provided "as-is", without any express or implied warranty. In no event
|
|
||||||
will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose, including commercial
|
|
||||||
applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must not claim that you
|
|
||||||
wrote the original software. If you use this software in a product, an acknowledgment
|
|
||||||
in the product documentation would be appreciated but is not required.
|
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
|
||||||
as being the original software.
|
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "input.h"
|
|
||||||
|
|
||||||
#define MAX_WORDS 100
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
const char *filePath = "words.txt";
|
|
||||||
|
|
||||||
FILE *file = fopen(filePath, "r");
|
|
||||||
|
|
||||||
if(file != NULL)
|
|
||||||
{
|
|
||||||
char words[MAX_WORDS][MAX_WORD_LEN];
|
|
||||||
|
|
||||||
int wordCount = readWords(file, words, MAX_WORDS);
|
|
||||||
|
|
||||||
for(int i = 0; i < wordCount; i++)
|
|
||||||
{
|
|
||||||
printf("%d. Entry: %s\n", i+1, words[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Could not find %s ...\n", filePath);
|
|
||||||
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
#include "game.h"
|
|
||||||
#include "input.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen);
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
const int searchFieldLen = 30;
|
|
||||||
|
|
||||||
if(searchFieldLen < MAX_SEARCH_FIELD_LEN)
|
|
||||||
{
|
|
||||||
const char words[][MAX_WORD_LEN] = {"Test", "NochEinTest", "WiederEinTest", "EinWeiteresTestWort", "UndSoWeiter"};
|
|
||||||
char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
|
||||||
|
|
||||||
int numberOfWords = sizeof(words)/sizeof(words[0]);
|
|
||||||
int placedWords = createWordSalad(salad, searchFieldLen, words, numberOfWords);
|
|
||||||
|
|
||||||
printf("Placed %d of %d words ...\n", placedWords, numberOfWords);
|
|
||||||
showWordSalad(salad, searchFieldLen);
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Error: Selected search field must not be larger than maximum search field ...\n");
|
|
||||||
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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]);
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
Binary file not shown.
@@ -0,0 +1,146 @@
|
|||||||
|
#include "game.h"
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#define MAX_RAND_TRIES_PER_WORD 10
|
||||||
|
#define EMPTY_CHAR 0
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Prints the word salad to console
|
||||||
|
// void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Funktion, die einen zufälligen Großbuchstaben (A–Z) erzeugt
|
||||||
|
char randomLetter()
|
||||||
|
{
|
||||||
|
return 'A' + rand() % 26;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erstellt das Wortsalat-Spielfeld und platziert die Wörter zufällig
|
||||||
|
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
|
||||||
|
unsigned int searchFieldLen,
|
||||||
|
const char words[][MAX_WORD_LEN],
|
||||||
|
unsigned int wordCount)
|
||||||
|
{
|
||||||
|
// 1. Spielfeld mit leeren Zeichen initialisieren
|
||||||
|
for (unsigned int i = 0; i < searchFieldLen; i++)
|
||||||
|
{
|
||||||
|
for (unsigned int j = 0; j < searchFieldLen; j++)
|
||||||
|
{
|
||||||
|
salad[i][j] = EMPTY_CHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
srand((unsigned int)time(NULL));
|
||||||
|
int placedWords = 0;
|
||||||
|
|
||||||
|
// 2. Jedes Wort zufällig auf dem Spielfeld platzieren
|
||||||
|
for (unsigned int w = 0; w < wordCount; w++)
|
||||||
|
{
|
||||||
|
char word[MAX_WORD_LEN];
|
||||||
|
strncpy(word, words[w], MAX_WORD_LEN);
|
||||||
|
word[MAX_WORD_LEN - 1] = '\0';
|
||||||
|
|
||||||
|
// Alle Buchstaben des Wortes in Großbuchstaben umwandeln
|
||||||
|
for (size_t k = 0; k < strlen(word); k++)
|
||||||
|
{
|
||||||
|
word[k] = (char)toupper((unsigned char)word[k]);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t len = strlen(word);
|
||||||
|
if (len > searchFieldLen)
|
||||||
|
continue; // Wort ist zu lang → überspringen
|
||||||
|
|
||||||
|
int placed = 0;
|
||||||
|
for (int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD && !placed; attempt++)
|
||||||
|
{
|
||||||
|
int dir = rand() % 2; // 0 = horizontal, 1 = vertikal
|
||||||
|
int row = rand() % searchFieldLen;
|
||||||
|
int col = rand() % searchFieldLen;
|
||||||
|
|
||||||
|
if (dir == 0 && col + len <= searchFieldLen)
|
||||||
|
{
|
||||||
|
int ok = 1;
|
||||||
|
// Prüfen, ob der Platz frei ist oder die Buchstaben passen
|
||||||
|
for (size_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
if (salad[row][col + i] != EMPTY_CHAR && salad[row][col + i] != word[i])
|
||||||
|
{
|
||||||
|
ok = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
// Wort horizontal einfügen
|
||||||
|
for (size_t i = 0; i < len; i++)
|
||||||
|
salad[row][col + i] = word[i];
|
||||||
|
placed = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (dir == 1 && row + len <= searchFieldLen)
|
||||||
|
{
|
||||||
|
int ok = 1;
|
||||||
|
// Prüfen, ob der Platz frei ist oder die Buchstaben passen
|
||||||
|
for (size_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
if (salad[row + i][col] != EMPTY_CHAR && salad[row + i][col] != word[i])
|
||||||
|
{
|
||||||
|
ok = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
// Wort vertikal einfügen
|
||||||
|
for (size_t i = 0; i < len; i++)
|
||||||
|
salad[row + i][col] = word[i];
|
||||||
|
placed = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (placed)
|
||||||
|
placedWords++; // Anzahl der erfolgreich platzierten Wörter erhöhen
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Alle leeren Felder 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] = randomLetter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rückgabewert: Anzahl der platzierten Wörter
|
||||||
|
return placedWords;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gibt das Spielfeld in der Konsole aus
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,5 +6,6 @@
|
|||||||
#define MAX_SEARCH_FIELD_LEN 100
|
#define MAX_SEARCH_FIELD_LEN 100
|
||||||
|
|
||||||
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);
|
||||||
|
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
#include "input.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.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)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Wörter aus einer Datei lesen und im Array 'words' speichern
|
||||||
|
// Gibt die Anzahl der gelesenen Wörter zurück oder -1 im Fehlerfall.
|
||||||
|
|
||||||
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
|
{
|
||||||
|
if (file == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Fehler: Datei ist NULL.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int count = 0;
|
||||||
|
char buffer[512];
|
||||||
|
|
||||||
|
// Ganze Datei zeilenweise lesen
|
||||||
|
while (fgets(buffer, sizeof(buffer), file) != NULL && count < maxWordCount)
|
||||||
|
{
|
||||||
|
// Entfernt Zeilenumbruch '\n' oder '\r\n'
|
||||||
|
buffer[strcspn(buffer, "\r\n")] = '\0';
|
||||||
|
|
||||||
|
// Zerlegt die Zeile in Wörter mit den Trennzeichen: Leerzeichen, Komma, Semikolon
|
||||||
|
char *token = strtok(buffer, " ,;");
|
||||||
|
while (token != NULL && count < maxWordCount)
|
||||||
|
{
|
||||||
|
// Leerzeichen am Anfang und Ende entfernen
|
||||||
|
while (isspace((unsigned char)*token))
|
||||||
|
token++;
|
||||||
|
char *end = token + strlen(token) - 1;
|
||||||
|
while (end > token && isspace((unsigned char)*end))
|
||||||
|
{
|
||||||
|
*end = '\0';
|
||||||
|
end--;
|
||||||
|
}
|
||||||
|
|
||||||
|
// In Großbuchstaben umwandeln
|
||||||
|
for (unsigned int i = 0; i < strlen(token); i++)
|
||||||
|
{
|
||||||
|
token[i] = (char)toupper((unsigned char)token[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// In das Array 'words' kopieren
|
||||||
|
strncpy(words[count], token, MAX_WORD_LEN - 1);
|
||||||
|
words[count][MAX_WORD_LEN - 1] = '\0';
|
||||||
|
|
||||||
|
count++;
|
||||||
|
token = strtok(NULL, " ,;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ int main(int argc, char *argv[])
|
|||||||
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
|
||||||
if(argc != 2)
|
if (argc != 2)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
|
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
|
||||||
exitCode = EXIT_FAILURE;
|
exitCode = EXIT_FAILURE;
|
||||||
@@ -24,7 +24,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
FILE *file = fopen(argv[1], "r");
|
FILE *file = fopen(argv[1], "r");
|
||||||
|
|
||||||
if(file != NULL)
|
if (file != NULL)
|
||||||
{
|
{
|
||||||
unsigned int placedWords = 0;
|
unsigned int placedWords = 0;
|
||||||
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
|
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
|
||||||
@@ -38,9 +38,19 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// Check if all words were successfully placed
|
// Check if all words were successfully placed
|
||||||
|
if (placedWords < wordCount)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Warning: Only %d out of %d words could be placed in the salad.\n",
|
||||||
|
placedWords, wordCount);
|
||||||
|
fprintf(stderr, "Some words could not be placed.\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("All %u words placed successfully!\n", wordCount);
|
||||||
|
}
|
||||||
// Start the game if successful
|
// Start the game if successful
|
||||||
|
showWordSalad(wordSalad, SALAD_SIZE);
|
||||||
// error message if some words couldn't be placed
|
// error message if some words couldn't be placed
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
CC = gcc
|
||||||
|
CFLAGS = -g -Wall
|
||||||
|
LDFLAGS = -lopengl32 -lgdi32 -lwinmm
|
||||||
|
BINARIES = ./windows
|
||||||
|
|
||||||
|
raylibfolder = ./raylib
|
||||||
|
unityfolder = ./unity
|
||||||
|
|
||||||
|
# --------------------------
|
||||||
|
# initiales Spiel bauen
|
||||||
|
# --------------------------
|
||||||
|
wordsalad_initial:
|
||||||
|
$(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
|
|
||||||
|
# --------------------------
|
||||||
|
# Normales Spiel bauen
|
||||||
|
# --------------------------
|
||||||
|
all: 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) -c $(CFLAGS) main.c
|
||||||
|
|
||||||
|
input.o: input.c
|
||||||
|
$(CC) -c $(CFLAGS) input.c
|
||||||
|
|
||||||
|
game.o: game.c
|
||||||
|
$(CC) -c $(CFLAGS) game.c
|
||||||
|
|
||||||
|
graphicalGame.o: graphicalGame.c
|
||||||
|
$(CC) -I$(raylibfolder) -c $(CFLAGS) graphicalGame.c
|
||||||
|
|
||||||
|
# --------------------------
|
||||||
|
# Unit Tests
|
||||||
|
# --------------------------
|
||||||
|
TEST_BIN = runTests
|
||||||
|
|
||||||
|
test: input.o game.o unit_tests.c
|
||||||
|
$(CC) $(CFLAGS) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a
|
||||||
|
|
||||||
|
# --------------------------
|
||||||
|
# Clean
|
||||||
|
# --------------------------
|
||||||
|
clean:
|
||||||
|
del /f *.o *.exe
|
||||||
Binary file not shown.
Binary file not shown.
@@ -101,35 +101,6 @@ 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,
|
||||||
@@ -164,7 +135,6 @@ 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);
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
unity: unity.c unity.h
|
||||||
|
gcc -c -Wall -o unity.o unity.c
|
||||||
|
ar rcs libunity.a unity.o
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user