110 lines
4.1 KiB
C
110 lines
4.1 KiB
C
#include <stdlib.h>
|
||
#include <stdio.h>
|
||
#include <string.h>
|
||
#include "input.h"
|
||
#include "game.h"
|
||
#include "graphicalGame.h"
|
||
|
||
#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)
|
||
{
|
||
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);
|
||
|
||
|
||
// – Platzieren Sie die Wörter aus der Wörterliste zufällig horizontal oder vertikal im
|
||
// Spielfeld.
|
||
for(unsigned int index = 0; index <= wordCount -1; index++)
|
||
{
|
||
int coordx = 0;
|
||
int coordy = 0;
|
||
int dir = 0; //0 = horizontal 1 = vertikal
|
||
|
||
coordx = rand() % SALAD_SIZE;
|
||
coordy = rand() % SALAD_SIZE;
|
||
dir = rand() % 2;
|
||
|
||
if (wordSalad[coordx][coordy] == 0){
|
||
//checken wie lang index wort ist
|
||
unsigned int wordLength = strlen(words[index]);
|
||
//checken ob von coord aus in dir richtung genügend platz ist
|
||
switch (dir){
|
||
case 0: // Horizontal
|
||
if(coordx + wordLength < SALAD_SIZE){
|
||
|
||
}else {break};
|
||
// 1. Prüfen, ob das Wort horizontal ins Spielfeld passt
|
||
// 2. Prüfen, ob alle benötigten Zellen frei sind
|
||
// 3. Wenn ja: Wort platzieren
|
||
// 4. Wenn nein: neue Position versuchen
|
||
break;
|
||
|
||
case 1: // Vertikal
|
||
// 1. Prüfen, ob das Wort vertikal ins Spielfeld passt
|
||
// 2. Prüfen, ob alle benötigten Zellen frei sind
|
||
// 3. Wenn ja: Wort platzieren
|
||
// 4. Wenn nein: neue Position versuchen
|
||
break;
|
||
}
|
||
|
||
|
||
} else {
|
||
--index;
|
||
}
|
||
|
||
anschauen ob position leer ist
|
||
falls ja, länge des wortes anschauen, in die dir die länge gehen und checken ob alles leer ist, falls ja plazieren, falls nein neue coordinate
|
||
falls nein, neue coordinate ohne index zu erhöhen
|
||
}
|
||
// irgendwie array an pos 1 0 laden und dann von 1 0 bis 1 X bis das wort leer ist, also bis ein 0 char eingeladen wird und dann länge checken, dann mit der länge checken welche pos legit sind und dann random auswählen
|
||
// spielfeld ist 20x20 array, also zufällige koordinate auswählen, richtung auswählen
|
||
|
||
|
||
// – Füllen Sie die übrigen Felder mit zufälligen Buchstaben.
|
||
// – Definieren Sie ggf. geeignete Datentypen (z.B. enum für Platzierungsrichtung
|
||
// etc.).test sieht man das hier??
|
||
|
||
// 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;
|
||
}
|
||
}
|
||
|
||
return exitCode;
|
||
} |