generated from freudenreichan/info2Praktikum-Wortsalat
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39addfa981 | ||
|
|
948e51e928 | ||
|
|
ba8df4c6c8 | ||
|
|
78f631fefb | ||
|
|
992119f42c | ||
|
|
629f5ed15e | ||
|
|
1f22de8f99 | ||
|
|
e355223d7c |
No files matched your search
+81
-11
@@ -1,23 +1,93 @@
|
||||
#include "game.h"
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#define MAX_RAND_TRIES_PER_WORD 10
|
||||
#define EMPTY_CHAR 0
|
||||
#define EMPTY_CHAR '.' // Leeres Kästchen
|
||||
|
||||
//TODO: Spiellogik implementieren:
|
||||
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||
typedef enum { HORIZONTAL, VERTICAL } Direction;
|
||||
|
||||
// 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)
|
||||
// 1. Funktion – Array initialisieren
|
||||
static void initializeArray(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int size)
|
||||
{
|
||||
|
||||
for (unsigned int y = 0; y < size; y++)
|
||||
for (unsigned int x = 0; x < size; x++)
|
||||
salad[y][x] = EMPTY_CHAR;
|
||||
}
|
||||
|
||||
// Prints the word salad to console
|
||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||
// 2. Funktion – prüfen, ob Wort passt
|
||||
static int canPlace(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
|
||||
unsigned int size, unsigned int x, unsigned int y,
|
||||
const char *word, Direction dir)
|
||||
{
|
||||
unsigned int len = strlen(word);
|
||||
if ((dir == HORIZONTAL && x + len > size) || (dir == VERTICAL && y + len > size))
|
||||
return 0;
|
||||
|
||||
for (unsigned int i = 0; i < len; i++) {
|
||||
if ((dir == HORIZONTAL && salad[y][x + i] != EMPTY_CHAR) ||
|
||||
(dir == VERTICAL && salad[y + i][x] != EMPTY_CHAR))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 3. Funktion – Wort eintragen
|
||||
static void placeWord(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
|
||||
unsigned int x, unsigned int y, const char *word, Direction dir)
|
||||
{
|
||||
for (unsigned int i = 0; i < strlen(word); i++) {
|
||||
if (dir == HORIZONTAL)
|
||||
salad[y][x + i] = word[i];
|
||||
else
|
||||
salad[y + i][x] = word[i];
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Funktion – leere Felder mit Zufallsbuchstaben füllen
|
||||
static void fillRandomLetters(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int size)
|
||||
{
|
||||
for (unsigned int y = 0; y < size; y++)
|
||||
for (unsigned int x = 0; x < size; x++)
|
||||
if (salad[y][x] == EMPTY_CHAR)
|
||||
salad[y][x] = 'A' + (rand() % 26);
|
||||
}
|
||||
|
||||
// Hauptfunktion – Wortsalat erzeugen
|
||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
|
||||
unsigned int size, const char words[][MAX_WORD_LEN],
|
||||
unsigned int wordCount)
|
||||
{
|
||||
srand(time(NULL));
|
||||
initializeArray(salad, size);
|
||||
|
||||
int placed = 0;
|
||||
for (unsigned int i = 0; i < wordCount; i++) {
|
||||
int success = 0;
|
||||
for (int tries = 0; tries < 1000 && !success; tries++) {
|
||||
unsigned int x = rand() % size;
|
||||
unsigned int y = rand() % size;
|
||||
Direction dir = rand() % 2 ? HORIZONTAL : VERTICAL;
|
||||
|
||||
if (canPlace(salad, size, x, y, words[i], dir)) {
|
||||
placeWord(salad, x, y, words[i], dir);
|
||||
success = 1;
|
||||
placed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fillRandomLetters(salad, size);
|
||||
return placed;
|
||||
}
|
||||
|
||||
// Ausgabe-Funktion
|
||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int size)
|
||||
{
|
||||
for (unsigned int y = 0; y < size; y++) {
|
||||
for (unsigned int x = 0; x < size; x++)
|
||||
printf("%c ", salad[y][x]);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
+30
-4
@@ -1,12 +1,38 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#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)
|
||||
{
|
||||
|
||||
}
|
||||
unsigned int count = 0; // wie viele Wörter bisher gespeichert wurden
|
||||
char line[MAX_LINE_LEN]; // Puffer für EINE gelesene Textzeile
|
||||
|
||||
while(fgets(line, sizeof(line), file)!= NULL && count < maxWordCount) //fgets liest eine komplette Zeile wenn es noch eine Zeile gibt und noch Platz für mehr Wörter ist
|
||||
{
|
||||
const char *delims = "\t\n\r ,;"; //Liste der Trenner (z.B. Komma)
|
||||
char *token = strtok(line, delims); //strok sucht in line das erste Wort, indem es an Trennzeichen teilt. Wenn kein Wort gefunden, wird NULL zurück gegeben
|
||||
|
||||
|
||||
while (token != NULL && count < maxWordCount) //Solange es noch ein Wort (token) gibt und noch Platz in words ist
|
||||
{
|
||||
for(unsigned int i = 0; token[i] != '\0'; i++)
|
||||
{
|
||||
token[i] = toupper((unsigned char)token[i]); //toupper macht jeden Buchstaben groß.
|
||||
}
|
||||
strncpy(words[count], token, MAX_WORD_LEN -1); //Kopiert das Wort in den nächsten freien Slot words[count].
|
||||
words[count][MAX_WORD_LEN -1] = '\0';
|
||||
count++; //Wir habenein Wort abgespeichert count + 1
|
||||
token = strtok(NULL, delims); //hier
|
||||
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
Binary file not shown.
+35
-36
@@ -7,48 +7,47 @@
|
||||
#define MAX_NUMBER_OF_WORDS 100
|
||||
#define SALAD_SIZE 20
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
||||
{
|
||||
int exitCode = EXIT_SUCCESS;
|
||||
|
||||
// Check if the correct number of arguments is provided
|
||||
if(argc != 2)
|
||||
if (argc != 2) //wenn keine zwei argumente gefunde -> alarm
|
||||
{
|
||||
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game
|
||||
unsigned int wordCount = 0;
|
||||
|
||||
FILE *file = fopen(argv[1], "r");
|
||||
|
||||
if(file != NULL)
|
||||
{
|
||||
unsigned int placedWords = 0;
|
||||
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
|
||||
|
||||
// Read words from file and store in 'words' array
|
||||
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);
|
||||
|
||||
// TODO:
|
||||
// Check if all words were successfully placed
|
||||
// Start the game if successful
|
||||
// error message if some words couldn't be placed
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Print error message if file couldn't be opened
|
||||
fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]);
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
fprintf(stderr, "Benutzung: %s <Pfad zur Wörterdatei>\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; //array mit eingelesenen wörtern
|
||||
unsigned int wordCount = 0;
|
||||
|
||||
FILE *file = fopen(argv[1], "r"); //schaut in die words.txt datei
|
||||
if (!file) //wenn keine datei -> alarm
|
||||
{
|
||||
fprintf(stderr, "Konnte Datei %s nicht öffnen.\n", argv[1]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
unsigned int placedWords = 0;
|
||||
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
||||
|
||||
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS); //holt sich aus readwords funktion die wortanzahl
|
||||
fclose(file);
|
||||
|
||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); //holt sich anzahl der platzierten wörter von createwordsalad funktion
|
||||
|
||||
printf("\nWortsalat-Initialisierung\n"); //ganz viel printen
|
||||
printf("-------------------------\n");
|
||||
printf("Gelesene Woerter: %u\n", wordCount);
|
||||
printf("Platzierte Woerter: %u\n", placedWords);
|
||||
|
||||
if (placedWords < wordCount) //macht checker, ob alle wörter salatiert wurden
|
||||
printf("Hinweis: %u Woerter konnten nicht platziert werden.\n", wordCount - placedWords);
|
||||
|
||||
printf("\nSpielfeld (%dx%d):\n\n", SALAD_SIZE, SALAD_SIZE);
|
||||
showWordSalad(wordSalad, SALAD_SIZE);
|
||||
printf("\nInitialisierung abgeschlossen.\n");
|
||||
return exitCode;
|
||||
}
|
||||
Binary file not shown.
+4
-2
@@ -1,5 +1,7 @@
|
||||
Yeti,Nessie Werwolf; Vampir
|
||||
Monster
|
||||
Hydra;Frankenstein
|
||||
Hydra;Frankenstein; fortnite
|
||||
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
|
||||
Gespenst, Oger
|
||||
Gespenst, Oger
|
||||
tomasschwester, lababage, eckesbokesseresekes
|
||||
Doener, Kebab, nacho, alejandrogarnacho, megafon, Telefon, gianluigibuffon, mehrweorter,
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.apple.xcode.dsym.wordsalad</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>dSYM</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
---
|
||||
triple: 'arm64-apple-darwin'
|
||||
binary-path: wordsalad
|
||||
relocations: []
|
||||
...
|
||||
+74
-37
@@ -1,45 +1,82 @@
|
||||
#include "game.h"
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "game.h"
|
||||
|
||||
#define MAX_RAND_TRIES_PER_WORD 10
|
||||
#define EMPTY_CHAR '.'
|
||||
//große Funktion (Gitter bauen, Wörter legen, Zufallsbuchstaben)
|
||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], //Gitter
|
||||
unsigned int size, const char words[][MAX_WORD_LEN], //größe Quadrat,liste von Wörtern
|
||||
unsigned int wordCount) { //anzahl an Wörtern in der Liste
|
||||
#define EMPTY_CHAR '.' // leeres kästchen = "."
|
||||
typedef enum { HORIZONTAL, VERTICAL } Direction; //neuer typ: waagrecht oder senkrecht
|
||||
|
||||
//TODO: Spiellogik implementieren:
|
||||
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||
|
||||
static void initializeArray(char salad [MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN],
|
||||
unsigned int SearchFieldLen) //Array initialisieren & mit Filler füllen
|
||||
{
|
||||
for (int i = 0; i < SearchFieldLen; i++)
|
||||
{
|
||||
for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++)
|
||||
{
|
||||
salad[i][j] = EMPTY_CHAR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void col_roq (unsigned int searchFieldLen, int *x, int *y) //Zufällige x/y Koordinate für Wortanfang
|
||||
{
|
||||
*x = rand() % searchFieldLen;
|
||||
|
||||
*y = rand() % searchFieldLen;
|
||||
}
|
||||
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Prints the word salad to console
|
||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||
{
|
||||
//1.kleine Funktion(setzt jedes Kästchen auf ".")
|
||||
void initializeArray() {
|
||||
for (unsigned int y = 0; y < size; y++) //Zeilen durchlaufen
|
||||
for (unsigned int x = 0; x < size; x++) //Spalten durchlaufen
|
||||
salad[y][x] = EMPTY_CHAR; //punkt schreiben
|
||||
}
|
||||
//2.kleine Funktion (prüfen ob Wort passt)
|
||||
int canPlace(unsigned int x, unsigned int y, const char *word, Direction dir) { //Startposition, das Wort, Richtung
|
||||
unsigned int len = strlen(word); //länge des Wortes
|
||||
if ((dir == HORIZONTAL && x + len > size) || (dir == VERTICAL && y + len > size)) //prüfen ob Wort über rechten bzw. unteren Rand geht
|
||||
return 0; //passt das wort nicht -> 0
|
||||
for (unsigned int i = 0; i < len; i++) { //jedes zeichen nacheinander prüfen
|
||||
if ((dir == HORIZONTAL && salad[y][x + i] != EMPTY_CHAR) || //prüfen ob nach rechts schon ein wort kommt
|
||||
(dir == VERTICAL && salad[y + i][x] != EMPTY_CHAR)) //prüfen ob nach unten ein Wort kommt
|
||||
return 0; //ist dort bereits ein wort -> 0
|
||||
}
|
||||
return 1; //passt das Wort -> 1
|
||||
}
|
||||
//3.kleine Funktion (Wort ins Gitter schreiben)
|
||||
void placeWord(unsigned int x, unsigned int y, const char *word, Direction dir) { //Startposition, das Wort, Richtung
|
||||
for (unsigned int i = 0; i < strlen(word); i++) { //Buchstabe für Buchstabe
|
||||
if (dir == HORIZONTAL) //i-ten Buchstaben an y,x+i schreiben bei waagrecht
|
||||
salad[y][x + i] = word[i];
|
||||
else //i-ten Buchstaben an y+i,x schreiben bei senkrecht
|
||||
salad[y + i][x] = word[i];
|
||||
}
|
||||
}
|
||||
//4.kleine Funktion (alle leeren Kästchen bekommen Zufallsbuchstaben)
|
||||
void fillRandomLetters() { //geht wieder über alle Zeilen und Spalten oh man
|
||||
for (unsigned int y = 0; y < size; y++) {
|
||||
for (unsigned int x = 0; x < size; x++) {
|
||||
if (salad[y][x] == EMPTY_CHAR) //wenns leer ist Zufallsbuchstabe
|
||||
salad[y][x] = 'A' + (rand() % 26);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Hauptschleife(Wörter zufällig platzieren)
|
||||
srand(time(NULL)); //durch aktuelle Sekundenzeit wirkklich zufällig
|
||||
initializeArray(); //1.kleine Funktion
|
||||
|
||||
int placed = 0; //wie viele Wörter wurden gelegt?
|
||||
for (unsigned int i = 0; i < wordCount; i++) { //jedes Wort durchgehen
|
||||
int success = 0; //für dieses Wort schon Platz gefunden?
|
||||
for (int tries = 0; tries < 1000 && !success; tries++) { //1000 verschiedene Stellen und Richtungen probieren
|
||||
unsigned int x = rand() % size; //zufällige Position Spalte
|
||||
unsigned int y = rand() % size; //zufällige Postion Zeile
|
||||
Direction dir = rand() % 2 ? HORIZONTAL : VERTICAL; //zufällige richtung 1-> Horizontal 0-> Vertical
|
||||
if (canPlace(x, y, words[i], dir)) { //2. kleine Funktion
|
||||
placeWord(x, y, words[i], dir); //3. kleine Funktion
|
||||
success = 1; //Wort erfolgreich platziert
|
||||
placed++; //Zähler der gelegten Wörter erhöhen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fillRandomLetters(); //4. kleine Funktion
|
||||
|
||||
return placed; //Rückgabe wie viele Wörter plaziert wurden
|
||||
}
|
||||
//Anzeige-Funktion
|
||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int size) { //funktion printet das wortsalatfeld
|
||||
for (unsigned int y = 0; y < size; y++) {
|
||||
for (unsigned int x = 0; x < size; x++) {
|
||||
printf("%c ", salad[y][x]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
@@ -9,3 +9,4 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen);
|
||||
|
||||
#endif
|
||||
|
||||
+27
-1
@@ -1,12 +1,38 @@
|
||||
#include "input.h"
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.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)
|
||||
{
|
||||
|
||||
unsigned int count = 0; // wie viele Wörter bisher gespeichert wurden
|
||||
char line[MAX_LINE_LEN]; // Puffer für EINE gelesene Textzeile
|
||||
|
||||
while(fgets(line, sizeof(line), file)!= NULL && count < maxWordCount) //fgets liest eine komplette Zeile wenn es noch eine Zeile gibt und noch Platz für mehr Wörter ist
|
||||
{
|
||||
const char *delims = "\t\n\r ,;"; //Liste der Trenner (z.B. Komma)
|
||||
char *token = strtok(line, delims); //strok sucht in line das erste Wort, indem es an Trennzeichen teilt. Wenn kein Wort gefunden, wird NULL zurück gegeben
|
||||
|
||||
|
||||
while (token != NULL && count < maxWordCount) //Solange es noch ein Wort (token) gibt und noch Platz in words ist
|
||||
{
|
||||
for(unsigned int i = 0; token[i] != '\0'; i++)
|
||||
{
|
||||
token[i] = toupper((unsigned char)token[i]); //toupper macht jeden Buchstaben groß.
|
||||
}
|
||||
strncpy(words[count], token, MAX_WORD_LEN -1); //Kopiert das Wort in den nächsten freien Slot words[count].
|
||||
words[count][MAX_WORD_LEN -1] = '\0';
|
||||
count++; //Wir habenein Wort abgespeichert count + 1
|
||||
token = strtok(NULL, delims); //hier
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return count;
|
||||
|
||||
}
|
||||
+37
-35
@@ -11,44 +11,46 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
int exitCode = EXIT_SUCCESS;
|
||||
|
||||
// Check if the correct number of arguments is provided
|
||||
if(argc != 2)
|
||||
if (argc != 2) //wenn keine zwei argumente gefunde -> alarm
|
||||
{
|
||||
fprintf(stderr, "Usage: %s <path to file with search words>\n", argv[0]);
|
||||
exitCode = EXIT_FAILURE;
|
||||
fprintf(stderr, "Benutzung: %s <Pfad zur Wörterdatei>\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else
|
||||
|
||||
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; //array mit eingelesenen wörtern
|
||||
unsigned int wordCount = 0;
|
||||
|
||||
FILE *file = fopen(argv[1], "r"); //schaut in die words.txt datei
|
||||
if (!file) //wenn keine datei -> alarm
|
||||
{
|
||||
char words[MAX_NUMBER_OF_WORDS][MAX_WORD_LEN]; // Array to hold the words to be used in the game
|
||||
unsigned int wordCount = 0;
|
||||
|
||||
FILE *file = fopen(argv[1], "r");
|
||||
|
||||
if(file != NULL)
|
||||
{
|
||||
unsigned int placedWords = 0;
|
||||
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
|
||||
|
||||
// Read words from file and store in 'words' array
|
||||
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);
|
||||
|
||||
// TODO:
|
||||
// Check if all words were successfully placed
|
||||
// Start the game if successful
|
||||
// error message if some words couldn't be placed
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Print error message if file couldn't be opened
|
||||
fprintf(stderr, "Could not open file %s for reading ...\n", argv[1]);
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
fprintf(stderr, "Konnte Datei %s nicht öffnen.\n", argv[1]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
unsigned int placedWords = 0;
|
||||
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
||||
|
||||
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS); //holt sich aus readwords funktion die wortanzahl
|
||||
fclose(file);
|
||||
|
||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); //holt sich anzahl der platzierten wörter von createwordsalad funktion
|
||||
|
||||
printf("\nWortsalat-Initialisierung\n"); //ganz viel printen
|
||||
printf("-------------------------\n");
|
||||
printf("Gelesene Woerter: %u\n", wordCount);
|
||||
printf("Platzierte Woerter: %u\n", placedWords);
|
||||
|
||||
if (placedWords < wordCount) //macht checker, ob alle wörter salatiert wurden
|
||||
printf("Hinweis: %u Woerter konnten nicht platziert werden.\n", wordCount - placedWords);
|
||||
|
||||
printf("\nSpielfeld (%dx%d):\n\n", SALAD_SIZE, SALAD_SIZE);
|
||||
showWordSalad(wordSalad, SALAD_SIZE);
|
||||
|
||||
|
||||
printf("\nInitialisierung abgeschlossen.\n");
|
||||
|
||||
// Später evtl.:
|
||||
// startGraphicalGame(wordSalad, SALAD_SIZE, words, wordCount);
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,6 @@ Yeti,Nessie Werwolf; Vampir
|
||||
Monster
|
||||
Hydra;Frankenstein
|
||||
Dracula;KingKong;Gremlin;Kobold,Hexe;Poltergeist
|
||||
Gespenst, Oger
|
||||
Gespenst, Oger
|
||||
tomasschwester, fortnite, lababage, eckesbokesseresekes
|
||||
Doener, Kebab, nacho, alejandrogarnacho, megafon, Telefon, gianluigibuffon, mehrweorter, flosschwester, gingerlatina
|
||||
Reference in new issue
Block a user