Template
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4079cb02bf | ||
|
|
547fc13e0f | ||
|
|
c114b40e7e | ||
|
|
3e56933d1b | ||
|
|
96ecac9e4c | ||
|
|
a48f1b961e | ||
|
|
61221a5b8d | ||
|
|
327332b4a2 | ||
|
|
b664c6dc5c | ||
|
|
d9ac9f27e1 | ||
|
|
b2d4ac22a2 | ||
|
|
281e3ad21b | ||
|
|
7cdcd0e8db | ||
|
|
28c70cf01b | ||
|
|
029eb426ab | ||
|
|
ce4be9f902 | ||
|
|
ce17403a1b | ||
|
|
a02b363e20 | ||
|
|
d61687f8df | ||
|
|
d368eea2f3 | ||
|
|
947054bb51 |
No files matched your search
@@ -60,3 +60,6 @@ dkms.conf
|
|||||||
|
|
||||||
# macOS
|
# macOS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
Startcode/testwords_delims.txt
|
||||||
|
Startcode/testwords_empty.txt
|
||||||
|
Startcode/testwords_simple.txt
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "input.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -6,6 +7,8 @@
|
|||||||
#define MAX_RAND_TRIES_PER_WORD 10
|
#define MAX_RAND_TRIES_PER_WORD 10
|
||||||
#define EMPTY_CHAR 0
|
#define EMPTY_CHAR 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//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 */
|
||||||
@@ -13,5 +16,88 @@
|
|||||||
// 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)
|
||||||
{
|
{
|
||||||
|
//Initialisiert den seed für rand()
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
|
//Initialisiere spielfeld auf '0'
|
||||||
|
// TODO: memset()
|
||||||
|
//memset(salad, '0', MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN);
|
||||||
|
for(int i = 0; i < MAX_SEARCH_FIELD_LEN; i++){
|
||||||
|
for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++){
|
||||||
|
salad[i][j] = '0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int placedWords = 0;
|
||||||
|
//Iterate over words
|
||||||
|
for(int counter = 0; counter < wordCount; counter++){
|
||||||
|
|
||||||
|
size_t len = strlen(words[counter]);
|
||||||
|
|
||||||
|
//try to place a word
|
||||||
|
for(int try = 0; try < 10; try++){
|
||||||
|
int x = rand() % MAX_SEARCH_FIELD_LEN;
|
||||||
|
int y = rand() % MAX_SEARCH_FIELD_LEN;
|
||||||
|
|
||||||
|
int dir = rand() % 2;
|
||||||
|
// cant place vertically
|
||||||
|
if(dir == 1 && MAX_SEARCH_FIELD_LEN < (y + (int) len)){
|
||||||
|
dir = 0;
|
||||||
|
}
|
||||||
|
//cant place horizontally
|
||||||
|
if((x + (int) len) > MAX_SEARCH_FIELD_LEN){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//place word vertically
|
||||||
|
if(dir == 1){
|
||||||
|
|
||||||
|
//see if all neccessary spaces are empty
|
||||||
|
bool cont = false;
|
||||||
|
for (int i = 0; i < (int)len; i++){
|
||||||
|
if(salad[x][y+i] != '0'){
|
||||||
|
cont = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//if not all spaces are empty try again
|
||||||
|
if(cont) continue;
|
||||||
|
//insert currentWord into playing field
|
||||||
|
for (int i = 0; i < (int)len; i++){
|
||||||
|
salad[x][y+i] = words[counter][i];
|
||||||
|
}
|
||||||
|
placedWords++;
|
||||||
|
break;
|
||||||
|
}else{
|
||||||
|
//place currentWord horizontally
|
||||||
|
//see if all neccessary spaces are emtry
|
||||||
|
bool cont = false;
|
||||||
|
for (int i = 0; i < (int)len; i++){
|
||||||
|
if(salad[x+1][y] != '0'){
|
||||||
|
cont = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//if not all spaces are empty try again
|
||||||
|
if(cont) continue;
|
||||||
|
|
||||||
|
//place currentWord
|
||||||
|
for (int i = 0; i < (int)len; i++){
|
||||||
|
salad[x+1][y] = words[counter][i];
|
||||||
|
}
|
||||||
|
placedWords++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < MAX_SEARCH_FIELD_LEN; i++){
|
||||||
|
for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++){
|
||||||
|
if(salad[i][j] == '0'){
|
||||||
|
char c = 'A' + (rand() % 26);
|
||||||
|
salad[i][j] = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return placedWords;
|
||||||
}
|
}
|
||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
#define MAX_SEARCH_FIELD_LEN 100
|
#define MAX_SEARCH_FIELD_LEN 20
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
//Torbens Kopie zum Testen
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "game.h"
|
||||||
|
#include "graphicalGame.h"
|
||||||
|
|
||||||
|
#define MAX_NUMBER_OF_WORDS 100
|
||||||
|
#define MAX_WORD_LEN 100
|
||||||
|
#define MAX_LINE_LEN 1024
|
||||||
|
#define SALAD_SIZE 20
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
int counter = 0;
|
||||||
|
char delimiters[] = ",!.;:? \n";
|
||||||
|
char *token;
|
||||||
|
while(fgets(tmp, MAX_LINE_LEN, file)){
|
||||||
|
printf("Input Line: %s\n", tmp);
|
||||||
|
token = strtok (tmp, delimiters);
|
||||||
|
|
||||||
|
while(token != NULL){
|
||||||
|
printf("Token:%s\n", token);
|
||||||
|
|
||||||
|
size_t len = strlen(token);
|
||||||
|
char copy[len+1];
|
||||||
|
strncpy(copy, token, len+1);
|
||||||
|
copy[len] = '\0';
|
||||||
|
|
||||||
|
strncpy(words[counter+1], copy, len);
|
||||||
|
words[counter+1][len] = '\0';
|
||||||
|
printf("Word: %s\n", words[counter+1]);
|
||||||
|
token = strtok (NULL, delimiters);
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void){
|
||||||
|
|
||||||
|
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game
|
||||||
|
unsigned int wordCount = 0;
|
||||||
|
FILE *file = fopen("words.txt", "r");
|
||||||
|
if(file != NULL)
|
||||||
|
{
|
||||||
|
unsigned int placedWords = 0;
|
||||||
|
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word sala
|
||||||
|
// Read words from file and store in 'words' array
|
||||||
|
printf("readWords start\n");
|
||||||
|
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
|
||||||
|
printf("%d", wordCount);
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
// 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.
|
||||||
@@ -8,5 +9,37 @@
|
|||||||
// 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 count = 0;
|
||||||
|
char *line = calloc(MAX_LINE_LEN, sizeof(char));
|
||||||
|
|
||||||
|
char delimit[] = ",.;:!? \n";
|
||||||
|
|
||||||
|
while(fgets(line, MAX_LINE_LEN, file) != NULL && (count < maxWordCount)){
|
||||||
|
|
||||||
|
char *token = strtok(line, delimit);
|
||||||
|
|
||||||
|
while(token != NULL){
|
||||||
|
size_t len = strlen(token);
|
||||||
|
token[len] = '\0';
|
||||||
|
char copy[MAX_LINE_LEN];
|
||||||
|
strncpy(copy, token, len);
|
||||||
|
copy[len] = '\0';
|
||||||
|
|
||||||
|
strncpy(words[count], copy, len);
|
||||||
|
words[count][len] = '\0';
|
||||||
|
|
||||||
|
|
||||||
|
//schaue ob auch alles groß geschrieben ist
|
||||||
|
for(int i = 0; i < len; i++){
|
||||||
|
if(words[count][i] <= 122 && words[count][i] >= 97){
|
||||||
|
//mache Kleinbuchstaben zu Großbuchstaben //ASCII A = 65, a = 97, z = 122
|
||||||
|
words[count][i] -= 32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
token = strtok(NULL, delimit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define MAX_WORD_LEN 100
|
#define MAX_WORD_LEN 20
|
||||||
#define MAX_LINE_LEN 1024
|
#define MAX_LINE_LEN 1024
|
||||||
|
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount);
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount);
|
||||||
|
|||||||
+57
-3
@@ -1,11 +1,49 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "graphicalGame.h"
|
#include "graphicalGame.h"
|
||||||
|
|
||||||
#define MAX_NUMBER_OF_WORDS 100
|
#define MAX_NUMBER_OF_WORDS 100
|
||||||
#define SALAD_SIZE 20
|
#define SALAD_SIZE 36
|
||||||
|
|
||||||
|
|
||||||
|
int checkSalad(char words[][MAX_WORD_LEN], char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], int placedWords, int wordCount){
|
||||||
|
//Iteriere über alle verfügbaren Wörter
|
||||||
|
int foundWords = 0;
|
||||||
|
|
||||||
|
//suche horizontal
|
||||||
|
for(int i = 0; i < wordCount; i++){
|
||||||
|
for(int h = 0; h < MAX_SEARCH_FIELD_LEN; h++){
|
||||||
|
if(strstr(wordSalad[h], words[i]) != NULL){
|
||||||
|
foundWords++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//flip Board
|
||||||
|
char copySalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
||||||
|
for (int i = 0; i< MAX_SEARCH_FIELD_LEN; i++){
|
||||||
|
for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++){
|
||||||
|
copySalad[i][j] = wordSalad[j][i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sucher vertikal
|
||||||
|
for(int i = 0; i < wordCount; i++){
|
||||||
|
for(int h = 0; h < MAX_SEARCH_FIELD_LEN; h++){
|
||||||
|
if(strstr(copySalad[h], words[i]) != NULL){
|
||||||
|
foundWords++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(foundWords == placedWords) return 0;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@@ -17,10 +55,11 @@ int main(int argc, char *argv[])
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game
|
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game
|
||||||
unsigned int wordCount = 0;
|
int wordCount = 0;
|
||||||
|
|
||||||
FILE *file = fopen(argv[1], "r");
|
FILE *file = fopen(argv[1], "r");
|
||||||
|
|
||||||
@@ -39,8 +78,23 @@ int main(int argc, char *argv[])
|
|||||||
// TODO:
|
// TODO:
|
||||||
// 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 (return input.c / game.c <=0)
|
||||||
|
|
||||||
|
// Prüfen, ob input.c (readWords) einen Fehler oder 0 Wörter zurückgegeben hat
|
||||||
|
if (wordCount <= 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Fehler: Es konnten keine Wörter eingelesen werden (input.c Rückgabewert <= 0).\n");
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prüfen, ob game.c (createWordSalad) einen Fehler zurückgegeben hat (<= 0) oder ob nicht alle eingelesenen Wörter platziert werden konnten
|
||||||
|
else if (placedWords <= 0 || placedWords < wordCount)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Fehler: Nicht alle Wörter konnten im Wortsalat platziert werden (game.c Rückgabewert <= 0).\n");
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
//keine Ahnung wiegroß pixelSize sein soll
|
||||||
|
startGame(wordSalad, MAX_SEARCH_FIELD_LEN, words, placedWords, MAX_SEARCH_FIELD_LEN * SALAD_SIZE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,12 +16,14 @@ raylibfolder = ./raylib
|
|||||||
unityfolder = ./unity
|
unityfolder = ./unity
|
||||||
codefolder = .
|
codefolder = .
|
||||||
|
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# initiales Spiel bauen
|
# initiales Spiel bauen
|
||||||
# --------------------------
|
# --------------------------
|
||||||
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)
|
||||||
|
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Normales Spiel bauen
|
# Normales Spiel bauen
|
||||||
# --------------------------
|
# --------------------------
|
||||||
@@ -48,6 +50,8 @@ TEST_BIN = runTests
|
|||||||
|
|
||||||
test: input.o game.o $(codefolder)/unit_tests.c $(unityfolder)/unity.c
|
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
|
$(CC) -Wall -I$(unityfolder) -o $(TEST_BIN) input.o game.o $(codefolder)/unit_tests.c $(unityfolder)/unity.c
|
||||||
|
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Clean
|
# Clean
|
||||||
# --------------------------
|
# --------------------------
|
||||||
@@ -57,3 +61,10 @@ ifeq ($(OS),Windows_NT)
|
|||||||
else
|
else
|
||||||
rm -f *.o wordsalad $(TEST_BIN)
|
rm -f *.o wordsalad $(TEST_BIN)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------
|
||||||
|
# Eigene Version bauen (Deine main.c + libwordsalad.a)
|
||||||
|
# --------------------------
|
||||||
|
wordsalad_TMN: main.o graphicalGame.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a
|
||||||
|
$(CC) $(CFLAGS) -o wordsalad_TMN main.o graphicalGame.o -L$(BINARIES) -lwordsalad $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||||
Reference in new issue
Block a user