forked from freudenreichan/info2Praktikum-Wortsalat
finished Programm
This commit is contained in:
1 parent
cbfd7d5071
commit
f81b98bc1c
2 files changed
+22
-12
No files matched your search
+8
-8
@@ -19,12 +19,12 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
//befüllen des Arrays mit '\0'
|
//befüllen des Arrays mit '\0'
|
||||||
for(unsigned int i = 0; i < searchFieldLen; i++)
|
for(unsigned int i = 0; i < searchFieldLen; i++)
|
||||||
{
|
{
|
||||||
for(unsigned int j = 0; j < searchFieldLen; i++)
|
for(unsigned int j = 0; j < searchFieldLen; j++)
|
||||||
{
|
{
|
||||||
salad[i][j] = '\0';
|
salad[i][j] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//erstellen von Richtungsvektoren
|
//erstellen von Richtungsvektoren
|
||||||
int dx[] = {1, 0};
|
int dx[] = {1, 0};
|
||||||
int dy[] = {0, 1};
|
int dy[] = {0, 1};
|
||||||
@@ -37,7 +37,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
{
|
{
|
||||||
return FEHLER_LAENGE_WORT;
|
return FEHLER_LAENGE_WORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int placed = 0;
|
int placed = 0;
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
|
|
||||||
@@ -48,8 +48,8 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
int zeile = rand() % searchFieldLen;
|
int zeile = rand() % searchFieldLen;
|
||||||
int spalte = rand() % searchFieldLen;
|
int spalte = rand() % searchFieldLen;
|
||||||
|
|
||||||
if(dir == 0 && (zeile + laenge > searchFieldLen))
|
if ((dir == 0 && (zeile + laenge > searchFieldLen)) ||
|
||||||
if(dir == 1 && (spalte + laenge > searchFieldLen))
|
(dir == 1 && (spalte + laenge > searchFieldLen)))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
placed = 1;
|
placed = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!placed) //überprüft ob das Wort gesetzt wurde, wenn nicht Fehlerausgabe
|
if(!placed) //überprüft ob das Wort gesetzt wurde, wenn nicht Fehlerausgabe
|
||||||
{
|
{
|
||||||
return FEHLER_SETZEN;
|
return FEHLER_SETZEN;
|
||||||
@@ -89,12 +89,12 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
{
|
{
|
||||||
for(unsigned int j = 0; j < searchFieldLen; j++)
|
for(unsigned int j = 0; j < searchFieldLen; j++)
|
||||||
{
|
{
|
||||||
if(salad[i][j] == '\n')
|
if(salad[i][j] == '\0')
|
||||||
{
|
{
|
||||||
salad[i][j] = 'A' + rand() % 26;
|
salad[i][j] = 'A' + rand() % 26;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERFOLG;
|
return (int)wordCount;
|
||||||
}
|
}
|
||||||
+14
-4
@@ -2,6 +2,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include <time.h>
|
||||||
#include "graphicalGame.h"
|
#include "graphicalGame.h"
|
||||||
|
|
||||||
#define MAX_NUMBER_OF_WORDS 100
|
#define MAX_NUMBER_OF_WORDS 100
|
||||||
@@ -38,10 +39,19 @@ int main(int argc, char *argv[])
|
|||||||
// Create the word salad by placing words into grid
|
// Create the word salad by placing words into grid
|
||||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
||||||
|
|
||||||
// TODO:
|
if (placedWords == (int)wordCount)
|
||||||
// Check if all words were successfully placed
|
{
|
||||||
// Start the game if successful
|
// Alle Wörter wurden erfolgreich platziert
|
||||||
// error message if some words couldn't be placed
|
startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Fehler beim Erstellen des Wortsalats
|
||||||
|
fprintf(stderr,
|
||||||
|
"Fehler beim Erstellen des Wortsalats. Rueckgabewert: %d\n",
|
||||||
|
(int)placedWords);
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in new issue
Block a user