Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/wiesendsi102436/info2Praktikum-Wortsalat
This commit is contained in:
commit
26bc089865
5
.gitignore
vendored
5
.gitignore
vendored
@ -2,3 +2,8 @@ wordsalad_initial
|
|||||||
game.o
|
game.o
|
||||||
input.o
|
input.o
|
||||||
runTests
|
runTests
|
||||||
|
main.o
|
||||||
|
graphicalGame.o
|
||||||
|
wordsalad
|
||||||
|
wordsalad_initial.exe
|
||||||
|
runTests.exe
|
||||||
@ -13,11 +13,48 @@
|
|||||||
// Creates the word salad by placing words randomly and filling empty spaces
|
// 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 createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
||||||
{
|
{
|
||||||
|
// set seed for random number generator
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
|
int r, c;
|
||||||
|
|
||||||
|
//Gesamtes Feld auf 0 setzen
|
||||||
|
for (r=0; r < searchFieldLen; r++) {
|
||||||
|
for (c=0; c < searchFieldLen; c++) {
|
||||||
|
salad [r][c] = EMPTY_CHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Wörter zufällig horizontal oder vertikal platzieren
|
||||||
|
enum Richtung {HORIZONTAL,VERTIKAL}; //0;1
|
||||||
|
enum Richtung dir;
|
||||||
|
dir = (rand() % 2 == 0) ? HORIZONTAL : VERTIKAL;
|
||||||
|
//Schleife, die das Setzen für alle Wörter durchführt, Zufällig horizontal(0) oder vertikal(1), an zufällige Stelle
|
||||||
|
//Prüfen, ob das Wort von der Länge her ins Feld passt
|
||||||
|
|
||||||
|
|
||||||
|
//Felder, in denen keine Wörter stehen, werden mit zufälligen Buchstaben befüllt
|
||||||
|
for (r=0; r < searchFieldLen; r++) {
|
||||||
|
for (c=0; c < searchFieldLen; c++) {
|
||||||
|
if (salad[r][c] == EMPTY_CHAR) {
|
||||||
|
salad [r][c] = 'A' + (rand()% 26);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the word salad to console
|
// Prints the word salad to console
|
||||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||||
{
|
{
|
||||||
|
int r, c;
|
||||||
|
|
||||||
|
//Ausgabe des gesamten Feldes
|
||||||
|
for (r=0; r < searchFieldLen; r++) {
|
||||||
|
for (c=0; c < searchFieldLen; c++) {
|
||||||
|
printf("%c ", salad[r][c]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@ -36,11 +36,18 @@ 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:
|
|
||||||
// Check if all words were successfully placed
|
// Check if all words were successfully placed
|
||||||
// Start the game if successful
|
// Start the game if successful
|
||||||
// error message if some words couldn't be placed
|
// error message if some words couldn't be placed
|
||||||
|
|
||||||
|
if (placedWords < wordCount)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "some words couldn't be placed\n");
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// Start the game if successful
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -13,11 +13,48 @@
|
|||||||
// Creates the word salad by placing words randomly and filling empty spaces
|
// 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 createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
||||||
{
|
{
|
||||||
|
// set seed for random number generator
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
|
int r, c, placedWords=0;
|
||||||
|
|
||||||
|
//Gesamtes Feld auf 0 setzen, am besten in eigene Fkt, dann aber extra Tests dafür erstellen
|
||||||
|
for (r=0; r < searchFieldLen; r++) {
|
||||||
|
for (c=0; c < searchFieldLen; c++) {
|
||||||
|
salad [r][c] = EMPTY_CHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Wörter zufällig horizontal oder vertikal platzieren
|
||||||
|
enum Richtung {HORIZONTAL,VERTIKAL}; //0;1
|
||||||
|
enum Richtung dir;
|
||||||
|
dir = (rand() % 2 == 0) ? HORIZONTAL : VERTIKAL;
|
||||||
|
//Schleife, die das Setzen für alle Wörter durchführt, Zufällig horizontal(0) oder vertikal(1), an zufällige Stelle
|
||||||
|
//Prüfen, ob das Wort von der Länge her ins Feld passt
|
||||||
|
|
||||||
|
|
||||||
|
//Felder, in denen keine Wörter stehen, werden mit zufälligen Buchstaben befüllt, am besten in eigene Fkt, dann aber extra Tests dafür erstellen
|
||||||
|
for (r=0; r < searchFieldLen; r++) {
|
||||||
|
for (c=0; c < searchFieldLen; c++) {
|
||||||
|
if (salad[r][c] == EMPTY_CHAR) {
|
||||||
|
salad [r][c] = 'A' + (rand()% 26);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//return "Anzahl platzierter Wörter", wird in Main dann mit soll verglichen
|
||||||
|
return placedWords;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the word salad to console
|
// Prints the word salad to console
|
||||||
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||||
{
|
{
|
||||||
|
int r, c;
|
||||||
|
|
||||||
|
//Ausgabe des gesamten Feldes
|
||||||
|
for (r=0; r < searchFieldLen; r++) {
|
||||||
|
for (c=0; c < searchFieldLen; c++) {
|
||||||
|
printf("%c ", salad[r][c]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,11 +36,18 @@ 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:
|
|
||||||
// Check if all words were successfully placed
|
// Check if all words were successfully placed
|
||||||
// Start the game if successful
|
// Start the game if successful
|
||||||
// error message if some words couldn't be placed
|
// error message if some words couldn't be placed
|
||||||
|
|
||||||
|
if (placedWords < wordCount)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "some words couldn't be placed\n");
|
||||||
|
exitCode = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// Start the game if successful
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user