Compare commits

...
5 Commits
Author SHA1 Message Date
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 154 additions and 29 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)
{
}
+98
View File
@@ -0,0 +1,98 @@
#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 */
int clearField();
int placeWords();
// 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)
{
/*srand(time(NULL));
char bustaben[] = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
char zufall = bustaben[rand() % 26];
printf("Zufaelliger Bustabe: %c\n", zufall);
const char words[15][MAX_WORD_LEN] = "Yeti,Nessie,Werwolf,Vampir,Monster,Hydra,Frankenstein,Dracula,KingKong,Gremlin,Kobold,Hexe,Poltergeist,Gespenst,Oge";
return 0; */
srand(time(NULL));
clearField[ROWS, COLS];
placeWords();
return 0;
}
int clearField() {
for (int r=0; r < ROWS; r++) {
for (int c =0; c < COLS; c++) {
grid[r][c] = '.';
}
}
}
int placeWords() {
//Wörter plazieren
for (unsigned int w = 0; w< wordCount; w++) {
int wordLen = strlen(words[w]);
int placed = 0;
while (!placed) {
int direction = rand() % 2;
int row;
int col;
int fits = 1;
if (direction == 0) {
row = rand() % ROWS;
col = rand() % (COLS - wordLen +1);
for (int i = 0; i< wordLen; i++) {
if (grid[row][col +i] != '.') {
fits = 0;
}
}
if (fits) {
for (int i=0; i < wordLen; i++) {
grid[row][col +i] = words[w][i];
}
placed = 1;
}
}
else {
row = rand() % (ROWS - wordLen +1);
col = rand() % COLS;
for (int i = 0; i< wordLen; i++) {
if (grid[row+i][col] != '.') {
fits = 0;
}
}
if (fits) {
for (int i = 0; i<worldLen; i++) {
grid[row+i][col] = words[w][i];
}
placed =1;
}
}
}
}
//Rest mit Zufallszahlen füllen
for (int r=0; r < ROWS; r++) {
for (int c=0; c < COLS; c++) {
if (grid[r][c] == '.') {
grid[r][c]='A' + rand() % 26;
}
}
}
}
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.
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.
File renamed without changes.