deleted testing lines -- tried to build main but had issues with graphicalGame.c

This commit is contained in:
pvtrx
2025-11-05 14:28:38 +01:00
parent 26efe137cb
commit c6664be88c
10 changed files with 97 additions and 23 deletions
+5 -4
View File
@@ -2,17 +2,18 @@
"version": "0.2.0",
"configurations": [
{
"name": "Debug current C file",
"name": "Debug Word Salad",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"program": "${fileDirname}\\word-salad.exe",
"args": ["${fileDirname}/words.txt"],
"cwd": "${fileDirname}",
"stopAtEntry": false,
"cwd": "${fileDirname}",
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:/msys64/mingw64/bin/gdb.exe",
"preLaunchTask": "C/C++: gcc.exe build active file"
"preLaunchTask": "make"
}
]
}
+2 -1
View File
@@ -1,5 +1,6 @@
{
"files.associations": {
"ctype.h": "c"
"ctype.h": "c",
"input.h": "c"
}
}
+17 -1
View File
@@ -2,6 +2,22 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "make",
"type": "shell",
"command": "C:/msys64/usr/bin/make.exe",
"options": {
"cwd": "${fileDirname}",
"env": { "PATH": "C:/msys64/mingw64/bin;${env:PATH}" },
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
},
{
"label": "build C file",
"type": "shell",
@@ -42,7 +58,7 @@
],
"group": {
"kind": "build",
"isDefault": true
"isDefault": false
},
"detail": "Task generated by Debugger."
}
-119
View File
@@ -1,119 +0,0 @@
#include "game.h"
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
{
//testing variables
int MAX_RAND_TRIES_PER_WORD = 10;
int EMPTY_CHAR = 0;
//end of testing variables
memset(salad, EMPTY_CHAR, MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN * sizeof(salad[0][0]));
int line = 0;
int column = 0;
int wordsplaced = 0;
int wordsaborted = 0;
while (wordsplaced < wordCount) {
int direction = rand() % 2; // 0 = horizontal, 1 = vertical
int wordlen = strlen(words[wordsplaced]);
int placed = 0;
int tries = 0;
while (!placed && tries < MAX_RAND_TRIES_PER_WORD) {
if (direction == 0) { // horizontal
if (wordlen <= searchFieldLen) {
column = rand() % (searchFieldLen - wordlen + 1);
line = rand() % searchFieldLen;
int canPlace = 1;
for (int i = 0; i < wordlen; i++) {
if (salad[line][column + i] != EMPTY_CHAR && salad[line][column + i] != words[wordsplaced][i]) {
canPlace = 0;
break;
}
}
if (canPlace) {
for (int i = 0; i < wordlen; i++) {
salad[line][column + i] = words[wordsplaced][i];
}
placed = 1;
}
}
} else { // vertical
if (wordlen <= searchFieldLen) {
line = rand() % (searchFieldLen - wordlen + 1);
column = rand() % searchFieldLen;
int canPlace = 1;
for (int i = 0; i < wordlen; i++) {
if (salad[line + i][column] != EMPTY_CHAR && salad[line + i][column] != words[wordsplaced][i]) {
canPlace = 0;
break;
}
}
if (canPlace) {
for (int i = 0; i < wordlen; i++) {
salad[line + i][column] = words[wordsplaced][i];
}
placed = 1;
}
}
}
tries++;
}
if (placed) {
wordsplaced++;
}
else if (tries == MAX_RAND_TRIES_PER_WORD) {
printf("Abort trying to place the word -%s-\n", words[wordsplaced]);
wordsplaced++; // skip this word and move to the next
wordsaborted++;
}
}
for (int i = 0; i < searchFieldLen; i++) { // replaces 0 with random letters
for (int j = 0; j < searchFieldLen; j++) {
if (salad[i][j] == EMPTY_CHAR) {
salad[i][j] = 'A' + (rand() % 26);
}
}
}
return wordsplaced;
}
int main(void) {
int SALAD_SIZE = 10;
char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
unsigned int searchFieldLen = SALAD_SIZE;
const char words[][MAX_WORD_LEN] = {"TEST", "WORD", "DEINEMUDDAAAA"}; // Add your words here
unsigned int wordCount = 3; // Update this based on number of words
int placedWords;
placedWords = createWordSalad(salad, searchFieldLen, words, wordCount);
for (unsigned int i = 0; i < searchFieldLen; i++) { // code von showWordSalad
for (unsigned int j = 0; j < searchFieldLen; j++) {
printf("%c ", salad[i][j]);
}
printf("\n");
}
//code for main.c:
if (placedWords == wordCount) {
printf("All valid words placed successfully.\n");
} else {
printf("Could not place all words. Placed %d out of %d words.\n", placedWords, wordCount);
}
return 0;
}
-3
View File
@@ -1,3 +0,0 @@
int main(void) {
}
+47 -1
View File
@@ -6,5 +6,51 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
//TODO: Implement function to read words from file words.txt and store them in the words array. See, that in the file words are not seperated only by , ; or space but also by new lines.
int zeilen = 0;
if(file == 0)
{
printf("Fehler beim oeffnen der Woerter \n");
return -1;
}
while(fgets(words[zeilen], MAX_WORD_LEN, file) != 0) //auslesen der Zeilen
{
size_t laenge = strlen(words[zeilen]); // Datentyp size_t wird verwendet bei strlen
if(laenge > 0 && words[zeilen][laenge - 1] == '\n') //austauschen des Leerzeichens mit einem Nullzeichen falls nötig
{
words[zeilen][laenge - 1] = '\0';
laenge--; // Länge nach austauschen 1 kleiner weil nullzeichen nicht mitzählt
}
zeilen++;
}
int alt_zeilen = zeilen;
zeilen = 0;
char *teiler = " .,;\n\t\r";
char *woerter;
char aufgeteilt[MAX_NUMBER_OF_WORDS][MAX_LINE_LEN]; //zwischenspeicher fürs aufteilen der Wörter
for(int i = 0; i < alt_zeilen; i++) // Jede Zeile einzeln betrachten
{
woerter = strtok(words[i], teiler);
while(woerter != 0)
{
strncpy(aufgeteilt[zeilen], woerter, MAX_WORD_LEN); // Kopieren der aufgeteilten Wörter in den Zwischenspeicher
zeilen++;
woerter = strtok(NULL, teiler); // NULL sagt das man weiterhin in der selben Zeile bleibt und dort aufteilt
}
}
for(int i = 0; i < zeilen; i++)
{
strncpy(words[i], aufgeteilt[i], MAX_WORD_LEN); // überschreiben der Wörter zurück ins alte Array
size_t len = strlen(words[i]);
for(int j = 0; j < len; j++)
{
words[i][j] = toupper(words[i][j]); // groß schreiben
}
}
return zeilen;
}
+1
View File
@@ -5,6 +5,7 @@
#define MAX_WORD_LEN 100
#define MAX_LINE_LEN 1024
#define MAX_NUMBER_OF_WORDS 100
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount);
+8 -8
View File
@@ -33,14 +33,14 @@ int main(int argc, char *argv[])
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
fclose(file);
// Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// Start game if all valid words were placed
if (placedWords == wordCount) {
startGame(wordSalad, SALAD_SIZE, words, wordCount);
} else {
printf("Could not place all valid words. Placed %d out of %d words.\n", placedWords, wordCount);
// Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// Start game if all valid words were placed
if (placedWords == wordCount) {
startGame(wordSalad, SALAD_SIZE, words, wordCount, MAX_SEARCH_FIELD_LEN);
} else {
printf("Could not place all valid words. Placed %d out of %d words.\n", placedWords, wordCount);
}
}
+17 -8
View File
@@ -1,10 +1,20 @@
CC = gcc
CFLAGS = -g -Wall
LDFLAGS = -lopengl32 -lgdi32 -lwinmm
BINARIES = ./windows
CC = C:/msys64/mingw64/bin/gcc.exe
CFLAGS = -g -Wall -I. -IC:/msys64/mingw64/include
LDFLAGS = -LC:/msys64/mingw64/lib -lraylib -lopengl32 -lgdi32 -lwinmm
raylibfolder = ./raylib
unityfolder = ./unity
SRC = main.c input.c game.c graphicalGame.c
OBJ = $(SRC:.c=.o)
EXE = word-salad.exe
all: $(EXE)
$(EXE): $(OBJ)
$(CC) -o $@ $(OBJ) $(LDFLAGS)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f *.o *.exe
# --------------------------
# initiales Spiel bauen
@@ -41,5 +51,4 @@ test: input.o game.o unit_tests.c
# --------------------------
# Clean
# --------------------------
clean:
del /f *.o *.exe
-71
View File
@@ -1,71 +0,0 @@
#include "input.h"
#include <string.h>
#include <ctype.h>
#define MAX_NUMBER_OF_WORDS 100 // wird in main definiert zum testen hier auch definiert!
//TODO:
//eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt
int readWords(FILE*file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
int zeilen = 0;
file = fopen("words.txt", "r"); // öffnen der datei (Wird in main gemacht also rausmachen!!!!!!!!!)
if(file == 0)
{
printf("Fehler beim oeffnen der Woerter \n");
return -1;
}
while(fgets(words[zeilen], MAX_WORD_LEN, file) != 0) //auslesen der Zeilen
{
size_t laenge = strlen(words[zeilen]); // Datentyp size_t wird verwendet bei strlen
if(laenge > 0 && words[zeilen][laenge - 1] == '\n') //austauschen des Leerzeichens mit einem Nullzeichen falls nötig
{
words[zeilen][laenge - 1] = '\0';
laenge--; // Länge nach austauschen 1 kleiner weil nullzeichen nicht mitzählt
}
zeilen++;
}
printf("%d \n", zeilen);
fclose(file); // Datei schließen (Wird in main geschlossen also muss man das noch rausmachen!!!!!!!!)
int alt_zeilen = zeilen;
zeilen = 0;
char *teiler = " .,;\n\t\r";
char *woerter;
char aufgeteilt[MAX_NUMBER_OF_WORDS][MAX_LINE_LEN]; //zwischenspeicher fürs aufteilen der Wörter
for(int i = 0; i < alt_zeilen; i++) // Jede Zeile einzeln betrachten
{
woerter = strtok(words[i], teiler);
while(woerter != 0)
{
strncpy(aufgeteilt[zeilen], woerter, MAX_WORD_LEN); // Kopieren der aufgeteilten Wörter in den Zwischenspeicher
zeilen++;
woerter = strtok(NULL, teiler); // NULL sagt das man weiterhin in der selben Zeile bleibt und dort aufteilt
}
}
printf("%d \n", zeilen);
for(int i = 0; i < zeilen; i++)
{
strncpy(words[i], aufgeteilt[i], MAX_WORD_LEN); // überschreiben der Wörter zurück ins alte Array
size_t len = strlen(words[i]);
for(int j = 0; j < len; j++)
{
words[i][j] = toupper(words[i][j]); // groß schreiben
}
}
for(int i = 0; i < zeilen; i++)
{
printf("%s \n", words[i]);
}
return zeilen;
}
int main()
{
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN];
FILE*file;
unsigned int wordCount = 0;
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
}