Fehlerbehebung klein und großbuchstaben behoben!
This commit is contained in:
parent
91ab73663a
commit
f77c450c0f
8
.idea/Informatik_2_Praktikum.iml
generated
8
.idea/Informatik_2_Praktikum.iml
generated
@ -1,8 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="CPP_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
<module classpath="CIDR" type="CPP_MODULE" version="4" />
|
2
.idea/vcs.xml
generated
2
.idea/vcs.xml
generated
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -12,22 +12,23 @@
|
||||
|
||||
// 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)
|
||||
{
|
||||
{// Länge der searchFieldLen wird in Main unter Salad size festgelegt (20)
|
||||
|
||||
srand((unsigned int)time(NULL)); // Seed für Zufallsgenerator
|
||||
|
||||
|
||||
// Initialisiere das Spielfeld mit EMPTY_CHAR
|
||||
for (unsigned int i = 0; i < searchFieldLen; ++i)
|
||||
{
|
||||
for (unsigned int j = 0; j < searchFieldLen; ++j)
|
||||
{
|
||||
salad[i][j] = EMPTY_CHAR;
|
||||
salad[i][j] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int placedWords = 0;
|
||||
|
||||
for (unsigned int w = 0; w < wordCount; ++w)
|
||||
for (unsigned int word = 0; word < wordCount; ++word)
|
||||
{
|
||||
int placed = 0;
|
||||
for (int tries = 0; tries < MAX_RAND_TRIES_PER_WORD && !placed; ++tries)
|
||||
@ -35,15 +36,15 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
int direction = rand() % 2; // 1 = horizontal, 0 = vertical
|
||||
int row = rand() % searchFieldLen;
|
||||
int col = rand() % searchFieldLen;
|
||||
int len = (int)strlen(words[w]);
|
||||
int len = (int)strlen(words[word]);
|
||||
|
||||
if (direction == 1 && col + len <= searchFieldLen) // horizontal
|
||||
if (direction == 1 && col + len <= searchFieldLen) // prüft ob das Wort horizontal in die Tabelle passt
|
||||
{
|
||||
int canPlace = 1;
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
|
||||
if (salad[row][col + i] != EMPTY_CHAR && salad[row][col + i] != words[w][i])
|
||||
if (salad[row][col + i] != EMPTY_CHAR && salad[row][col + i] != words[word][i])
|
||||
{
|
||||
canPlace = 0;
|
||||
break;
|
||||
@ -52,7 +53,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
if (canPlace)
|
||||
{
|
||||
for (int i = 0; i < len; ++i)
|
||||
salad[row][col + i] = words[w][i];
|
||||
salad[row][col + i] = words[word][i];
|
||||
placed = 1;
|
||||
}
|
||||
}
|
||||
@ -61,7 +62,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
int canPlace = 1;
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
if (salad[row + i][col] != EMPTY_CHAR && salad[row + i][col] != words[w][i])
|
||||
if (salad[row + i][col] != EMPTY_CHAR && salad[row + i][col] != words[word][i])
|
||||
{
|
||||
canPlace = 0;
|
||||
|
||||
@ -71,7 +72,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
if (canPlace)
|
||||
{
|
||||
for (int i = 0; i < len; ++i)
|
||||
salad[row + i][col] = words[w][i];
|
||||
salad[row + i][col] = words[word][i];
|
||||
placed = 1;
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,24 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
void capitalletters(char *str){
|
||||
while (*str) {
|
||||
*str = toupper((unsigned char) *str);
|
||||
str++;
|
||||
}
|
||||
|
||||
}
|
||||
// Liest Wörter aus Datei und speichert sie sicher im Array
|
||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
{
|
||||
char buffer[MAX_WORD_LEN];
|
||||
unsigned int count_word = 0;
|
||||
|
||||
|
||||
while (count_word < maxWordCount && fgets(buffer, sizeof(buffer), file) != NULL)
|
||||
{
|
||||
|
||||
// Zeilenumbruch manuell entfernen
|
||||
for (int i = 0; i < MAX_WORD_LEN; i++)
|
||||
{
|
||||
@ -20,6 +30,8 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||
}
|
||||
}
|
||||
|
||||
capitalletters(buffer);
|
||||
|
||||
// Sicheres Kopieren in das Zielarray
|
||||
strncpy(words[count_word], buffer, MAX_WORD_LEN - 1);
|
||||
words[count_word][MAX_WORD_LEN - 1] = '\0'; // Nullterminierung sicherstellen
|
||||
|
@ -57,8 +57,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,10 +1,12 @@
|
||||
raylib_folder = ./raylib
|
||||
unityfolder = ./unity
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -g -Wall -I$(raylibfolder)
|
||||
CFLAGS = -g -Wall -I$(raylib_folder)
|
||||
LDFLAGS = -lopengl32 -lgdi32 -lwinmm
|
||||
BINARIES = ./windows
|
||||
|
||||
raylib_folder = ./raylib
|
||||
unityfolder = ./unity
|
||||
|
||||
|
||||
# --------------------------
|
||||
# initiales Spiel bauen
|
||||
@ -23,7 +25,7 @@ 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
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user