Compare commits

...
14 Commits
Author SHA1 Message Date
MiraSchütz b5d6a5d1b3 main.c verändert 2026-10-26 17:51:49 +01:00
MiraSchütz a0bd61a872 game.c verändert 2026-10-26 17:48:56 +01:00
roesselid103915 556a83c9af nach test2 korrigiert game.c 2026-10-26 09:16:27 +01:00
roesselid103915 d2357c9040 nach test2 korrigiert game.c 2026-10-26 09:15:19 +01:00
roesselid103915 69d0c0ee4d nach tests korrigiert game.c 2026-10-26 09:09:13 +01:00
roesselid103915 075a2ad50c korrigiert game.c 2026-10-26 08:42:06 +01:00
roesselid103915 b0b70e371d fertig game.c 2026-10-26 08:31:30 +01:00
roesselid103915 7df641beb3 main.c fertig 2026-10-26 08:30:18 +01:00
roesselid103915 88575ba8bf fertig game.c 2026-10-26 08:07:43 +01:00
roesselid103915 f1fdbb5424 game.c bearbeitet 2026-10-21 15:07:56 +02:00
roesselid103915 84e854fdc2 Merge branch 'game' 2026-10-19 09:10:56 +02:00
roesselid103915 d5be49e0ff WiP game.c 2026-10-19 09:08:06 +02:00
roesselid103915 8c4e01b75c Anfang von game.c 2026-10-19 08:34:21 +02:00
MiraSchütz 20496fdfba Bearbeitung von input.c 2026-10-19 08:20:03 +02:00
37 changed files with 151 additions and 30 deletions

No files matched your search

-17
View File
@@ -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)
{
}
-12
View File
@@ -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)
{
}
+90
View File
@@ -0,0 +1,90 @@
#include "game.h"
#include "input.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) {
int placedWords = 0;
srand(time(NULL));
for (unsigned int r=0; r < searchFieldLen; r++) {
for (unsigned int c =0; c <searchFieldLen; c++) {
salad[r][c] = EMPTY_CHAR;
}
}
//Wörter plazieren
for (unsigned int w = 0; w< wordCount; w++) {
int wordLen = strlen(words[w]);
if (wordLen > searchFieldLen) {
continue;
}
int tries = 0;
int placed = 0;
while (!placed && tries < MAX_RAND_TRIES_PER_WORD) {
int direction = rand() % 2;
int row;
int col;
int fits = 1;
if (direction == 0) {
row = rand() % searchFieldLen;
col = rand() % (searchFieldLen - wordLen +1);
for (int i = 0; i< wordLen; i++) {
if (salad[row][col +i] != EMPTY_CHAR) {
fits = 0;
break;
}
}
if (fits) {
for (int i=0; i < wordLen; i++) {
salad[row][col +i] = words[w][i];
}
placed = 1;
placedWords++;
}
}
else {
row = rand() % (searchFieldLen - wordLen +1);
col = rand() % searchFieldLen;
for (int i = 0; i< wordLen; i++) {
if (salad[row+i][col] != EMPTY_CHAR) {
fits = 0;
break;
}
}
if (fits) {
for (int i = 0; i<wordLen; i++) {
salad[row+i][col] = words[w][i];
}
placed = 1;
placedWords++;
}
}
tries++;
}
}
//Rest mit Zufallsbustaben füllen
for (unsigned int r=0; r < searchFieldLen; r++) {
for (int c=0; c < searchFieldLen; c++) {
if (salad[r][c] == EMPTY_CHAR) {
salad[r][c]='A' + rand() % 26;
}
}
}
return placedWords;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
+56
View File
@@ -0,0 +1,56 @@
#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)
{
int wordCount = 0;
char line[MAX_LINE_LEN];
while (fgets(line, MAX_LINE_LEN, file)) {
char currentWord[MAX_LINE_LEN];
int wordPos = 0;
for ( int i = 0; line[i] != '\0'; i++) {
if (line[i] == ',' || line[i] == ';' || line[i] == ' ' || line[i] == '\n') {
if (wordPos > 0) {
currentWord[wordPos] = '\0';
if (wordCount < maxWordCount) {
strcpy(words[wordCount], currentWord);
wordCount++;
}
wordPos = 0;
}
}
else {
if (wordPos < MAX_WORD_LEN-1) {
currentWord[wordPos] = toupper(line[i]);
wordPos++;
}
}
}
if (wordPos > 0) {
currentWord[wordPos] = '\0';
if (wordCount < maxWordCount) {
strcpy(words[wordCount], currentWord);
wordCount++;
}
}
}
return wordCount;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+5 -1
View File
@@ -40,7 +40,11 @@ int main(int argc, char *argv[])
// Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed
if (placedWords == wordCount){
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
}else {
fprintf(stderr, "Could not open file %s for reading ...\n");
exitCode = EXIT_FAILURE;
}
else
{
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.