24 Commits
Author SHA1 Message Date
hofmannjo99187 7f0f3ceeb9 vorgeführt 2025-11-11 10:07:33 +01:00
hofmannjo99187 9ef55c581f added comments to input.c and tested the programm again 2025-11-11 07:58:07 +01:00
hofmannjo99187 d00feb8401 testing 2025-11-04 18:55:20 +01:00
hofmannjo99187 b26202cd9b testing 2025-11-04 18:27:56 +01:00
hofmannjo99187 25a13b1dca removed testing statement in input.c 2025-11-04 17:44:22 +01:00
hofmannjo99187 398936b789 removed testing statement in input.c 2025-11-04 17:43:48 +01:00
hofmannjo99187 cba52d17c5 testet if everything works (it does) 2025-11-04 17:39:23 +01:00
hofmannjo99187 42a5143e9a testing-statements entfernt 2025-11-04 17:03:59 +01:00
hofmannjo99187 acc14b49d8 Funktionaler Wortsalat mit Test-printf()-anweisungen 2025-11-04 16:48:22 +01:00
hofmannjo99187 6027c2a061 ausbesserungen aus stunde 2025-11-04 11:20:21 +01:00
hofmannjo99187 ed22736f68 debugging, placeWord noch fehlerhaft 2025-11-04 10:42:35 +01:00
hofmannjo99187 7146174e78 removed unused variable in input.c 2025-11-04 09:43:12 +01:00
hofmannjo99187 d097819ef9 durchführen Tests 2025-11-04 08:57:12 +01:00
hofmannjo99187 5e9132a48b test durchgeführt 2025-11-03 22:13:38 +01:00
hofmannjo99187 5d1c8ac8a5 überprüfungen in game.c angepasst so das ASCII zeichen zwischen Groß- und Kleinbuchstanben ausgeschlossen 2025-10-31 02:28:42 +01:00
hofmannjo99187 7414849901 input passes all tests 2025-10-31 02:10:20 +01:00
hofmannjo99187 46b6efbd69 began developing concept for readWords 2025-10-31 01:50:00 +01:00
hofmannjo99187 1affb13041 return 0 if file not found 2025-10-31 01:13:56 +01:00
hofmannjo99187 63cafdbc0c angefangen input neu zu schreiben 2025-10-31 01:09:29 +01:00
hofmannjo99187 543ba65b7e test durchgeführt 2025-10-31 00:53:26 +01:00
hofmannjo99187 9747bc4530 test druchgeführt 2025-10-30 17:25:39 +01:00
Florian Wetzel 30f601d4df Anpassung Darstellung 2025-10-30 17:05:38 +01:00
hofmannjo99187 f89019437f makefile korrektur in main übernommen 2025-10-30 15:43:58 +01:00
hofmannjo99187 eb77a4d1b8 leerzeichen vor input.c in line 33 im makefile 2025-10-30 15:42:36 +01:00
17 changed files with 136 additions and 19 deletions
+1
View File
@@ -403,6 +403,7 @@ static int allWordsFound(SearchWordPanel searchWordPanel)
// Main game loop where game is run and updated // Main game loop where game is run and updated
static void gameLoop(const Vector2 screenSize, MouseSelection mouseSelection, CharSquarePanel squarePanel, SearchWordPanel searchWordPanel, const HelperMessage helperMsg, const WinMessage winMsg) static void gameLoop(const Vector2 screenSize, MouseSelection mouseSelection, CharSquarePanel squarePanel, SearchWordPanel searchWordPanel, const HelperMessage helperMsg, const WinMessage winMsg)
{ {
SetConfigFlags(FLAG_WINDOW_HIGHDPI);
InitWindow(screenSize.x, screenSize.y, "Word Salad"); // Initialize game window InitWindow(screenSize.x, screenSize.y, "Word Salad"); // Initialize game window
SetTargetFPS(60); SetTargetFPS(60);
+47 -17
View File
@@ -31,16 +31,33 @@ typedef struct
} wordPosition; } wordPosition;
void initializeWordsalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
{
int i = 0;
int j = 0;
for (i = 0; i < searchFieldLen; i++)
{
for (j = 0; j < searchFieldLen; j++)
{
salad[i][j] = '=';
}
}
}
// Choses a random Position for the current Word // Choses a random Position for the current Word
wordPosition choserandomPosition(unsigned int searchFieldLen, unsigned int wordLength) wordPosition choserandomPosition(unsigned int searchFieldLen, unsigned int wordLength)
{ {
wordPosition position = {0, 0, 0}; wordPosition position = {0, 0, 0};
srand(time(NULL));
position.alignment = rand()%(VERTIKAL - HORIZONTAL + 1) + HORIZONTAL; position.alignment = rand()%(VERTIKAL - HORIZONTAL + 1) + HORIZONTAL;
position.rowOrColumn = rand()%(searchFieldLen); position.rowOrColumn = rand()%(searchFieldLen);
position.startingCell = rand()%(searchFieldLen - wordLength); position.startingCell = rand()%(searchFieldLen - wordLength);
return position; return position;
} }
@@ -60,7 +77,7 @@ int checkIfPositionIsFree(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]
// by scanning each column in the given row // by scanning each column in the given row
for (i = position.startingCell; (i < serchFieldLen) && !(letterFound); i++) for (i = position.startingCell; (i < serchFieldLen) && !(letterFound); i++)
{ {
if ((salad[position.rowOrColumn][i] >= 'A') && (salad[position.rowOrColumn][i] <= 'z')) if (((salad[position.rowOrColumn][i] >= 'A') && (salad[position.rowOrColumn][i] <= 'Z')) || ((salad[position.rowOrColumn][i] >= 'a') && (salad[position.rowOrColumn][i] <= 'z')))
{ {
letterFound = 1; letterFound = 1;
} }
@@ -72,7 +89,7 @@ int checkIfPositionIsFree(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]
// by scanning each row in the given column // by scanning each row in the given column
for (i = position.startingCell; (i < serchFieldLen) && !(letterFound); i++) for (i = position.startingCell; (i < serchFieldLen) && !(letterFound); i++)
{ {
if ((salad[i][position.rowOrColumn] >= 'A') && (salad[i][position.rowOrColumn] <= 'z')) if (((salad[i][position.rowOrColumn] >= 'A') && (salad[i][position.rowOrColumn] <= 'z')) || ((salad[i][position.rowOrColumn] >= 'a') && (salad[i][position.rowOrColumn] <= 'z')))
{ {
letterFound = 1; letterFound = 1;
} }
@@ -91,26 +108,27 @@ int checkIfPositionIsFree(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]
int placeWord(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], wordPosition position, const char currentWord[], unsigned int currentWordLen, unsigned int serchFieldLen) int placeWord(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], wordPosition position, const char currentWord[], unsigned int currentWordLen, unsigned int serchFieldLen)
{ {
int i = 0; int i = 0;
int j = 0;
if (position.alignment == HORIZONTAL) if (position.alignment == HORIZONTAL)
{ {
for (i = position.startingCell; (i < serchFieldLen) && (currentWord[j] != '\0'); i++)
for (i = position.startingCell; (i < serchFieldLen) && (i < currentWordLen); i++)
{ {
salad[position.rowOrColumn][i] = currentWord[i]; salad[position.rowOrColumn][i] = currentWord[j];
j++;
} }
salad[position.rowOrColumn][i] = '\0'; salad[position.rowOrColumn][i] = '\0';
} }
else if (position.alignment == VERTIKAL) else if (position.alignment == VERTIKAL)
{ {
for (i = position.startingCell; (i < serchFieldLen) && (i < currentWordLen); i++) for (i = position.startingCell; (i < serchFieldLen) && (currentWord[j] != '\0'); i++)
{ {
salad[i][position.rowOrColumn] = currentWord[i]; salad[i][position.rowOrColumn] = currentWord[j];
j++;
} }
salad[i][position.rowOrColumn] = '\0'; salad[i][position.rowOrColumn] = '\0';
} }
return 1; return 1;
} }
@@ -123,13 +141,11 @@ void placeRandomLetters(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
int j = 0; int j = 0;
srand(time(NULL));
for (i = 0; i < searchFieldLen; i++) for (i = 0; i < searchFieldLen; i++)
{ {
for (j = 0; i < searchFieldLen; j++) for (j = 0; j < searchFieldLen; j++)
{ {
if ((salad[i][j] < 'A') && (salad[i][j] > 'z')) if ((salad[i][j] < 'A') || (salad[i][j] > 'z') || ((salad[i][j] < 'a') && (salad[i][j] > 'Z')))
{ {
salad[i][j] = rand()%('Z' - 'A' + 1) + 'A'; salad[i][j] = rand()%('Z' - 'A' + 1) + 'A';
} }
@@ -144,24 +160,38 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
{ {
int i = 0; int i = 0;
int j = 0; int j = 0;
int k = 0;
int positionFound = 0; int positionFound = 0;
int placedWords = 0; int placedWords = 0;
char nullWord[MAX_WORD_LEN];
char currentWord[MAX_WORD_LEN]; char currentWord[MAX_WORD_LEN];
wordPosition currentWordPosition = {0,0,0}; wordPosition currentWordPosition = {0,0,0};
for (k = 0; k < MAX_WORD_LEN; k++)
{
nullWord[k] = '\0';
}
srand(time(NULL));
initializeWordsalad(salad, searchFieldLen);
for (i = 1; i <= wordCount; i++) for (i = 1; i <= wordCount; i++)
{ {
j = 0;
strcpy(currentWord, nullWord);
strcpy(currentWord, words[i-1]);
do do
{ {
currentWordPosition = choserandomPosition(searchFieldLen, strlen(words[i])); currentWordPosition = choserandomPosition(searchFieldLen, strlen(currentWord));
positionFound = checkIfPositionIsFree(salad, currentWordPosition, strlen(words[i]), searchFieldLen); positionFound = checkIfPositionIsFree(salad, currentWordPosition, strlen(currentWord), searchFieldLen);
j++; j++;
} while ((j < MAX_RAND_TRIES_PER_WORD) && !(positionFound)); } while ((j < MAX_RAND_TRIES_PER_WORD) && !(positionFound));
if (positionFound) if (positionFound)
{ {
strcpy(currentWord, words[i-1]);
placedWords += placeWord(salad, currentWordPosition, currentWord, strlen(currentWord), searchFieldLen); placedWords += placeWord(salad, currentWordPosition, currentWord, strlen(currentWord), searchFieldLen);
} }
} }
@@ -182,7 +212,7 @@ void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
for (i = 0; i < searchFieldLen; i++) for (i = 0; i < searchFieldLen; i++)
{ {
for (j = 0; i < searchFieldLen; j++) for (j = 0; j < searchFieldLen; j++)
{ {
printf("%c", salad[i][j]); printf("%c", salad[i][j]);
} }
Binary file not shown.
+79
View File
@@ -2,6 +2,83 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
/*
char *readSingleWord(FILE *file)
{
if (file == NULL)
{
return 0;
}
fgets(singleWordBuffer, MAX_LINE_LEN, file);
}
*/
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
int currentlyInWord = 0;
int word = 0;
int wordChar = 0;
char currentChar = 0;
do
{
// get the next char from the file
currentChar = fgetc(file);
// if current char is a capital letter
// write it into the words array
if ((currentChar >= 'A') && (currentChar <= 'Z'))
{
if (!currentlyInWord)
{
currentlyInWord = 1;
}
words[word][wordChar] = currentChar;
wordChar++;
}
// if the current char is a lowercase letter
// change it to its capital version
// and write it into the words array
else if ((currentChar >= 'a') && (currentChar <= 'z'))
{
if (!currentlyInWord)
{
currentlyInWord = 1;
}
words[word][wordChar] = toupper(currentChar);
wordChar++;
}
// if the current char is NOT a letter
// the end of a word has been reached
// skip chars untill a new letter is found
else if (currentlyInWord)
{
words[word][wordChar] = '\0';
word++;
wordChar = 0;
currentlyInWord = 0;
}
} while (((currentChar != EOF) && (word <= maxWordCount)));
return word;
}
/*
#define MAX_BUFFER_LEN 256 #define MAX_BUFFER_LEN 256
// TODO? // TODO?
@@ -36,3 +113,5 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
return count; return count;
} }
*/
Binary file not shown.
+3
View File
@@ -43,6 +43,8 @@ int main(int argc, char *argv[])
// Create the word salad by placing words into grid // Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
printf("placed Words: %d\n", placedWords);
printf("wordCount = %d\n", wordCount);
// DONE: // DONE:
// Check if all words were successfully placed // Check if all words were successfully placed
// Start the game if successful // Start the game if successful
@@ -59,6 +61,7 @@ int main(int argc, char *argv[])
// annahme: windowWidth wird in Pixeln gesucht, // annahme: windowWidth wird in Pixeln gesucht,
// da auch andere funktionen, wie createCharSquarePanel // da auch andere funktionen, wie createCharSquarePanel
// in Pixeln arbeiten // in Pixeln arbeiten
showWordSalad(wordSalad, SALAD_SIZE);
startGame(wordSalad, SALAD_SIZE, words, placedWords, WINDOW_WIDTH); startGame(wordSalad, SALAD_SIZE, words, placedWords, WINDOW_WIDTH);
} }
Binary file not shown.
+2 -2
View File
@@ -17,7 +17,7 @@ unityfolder = ./unity
# eigenes Spiel bauen # eigenes Spiel bauen
# -------------------------- # --------------------------
wordsalad_myversion: main.o graphicalGame.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a wordsalad_myversion: main.o graphicalGame.o $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a
$(CC) -o wordsalad_myvesion.exe main.c graphicalGame.c $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS) $(CC) -o wordsalad_myversion.exe main.c graphicalGame.c $(BINARIES)/libwordsalad.a $(BINARIES)/libraylib.a $(LDFLAGS)
# -------------------------- # --------------------------
@@ -30,7 +30,7 @@ main.o: main.c
$(CC) -c $(CFLAGS) main.c $(CC) -c $(CFLAGS) main.c
input.o: input.c input.o: input.c
$(CC) -c $(CFLAGS)input.c $(CC) -c $(CFLAGS) input.c
game.o: game.c game.o: game.c
$(CC) -c $(CFLAGS) game.c $(CC) -c $(CFLAGS) game.c
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
Hund,Katze; Maus
View File
+3
View File
@@ -0,0 +1,3 @@
Apfel
Banane
Kiwi
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.