generated from freudenreichan/info2Praktikum-Wortsalat
Compare commits
4
Commits
markus-game
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5830c24eb | ||
|
|
fdb0390b59 | ||
|
|
7d7e410f49 | ||
|
|
d09b63ea08 |
No files matched your search
@@ -65,3 +65,58 @@ int createWordSalad(
|
||||
|
||||
|
||||
// 5. Vertikale Platzierung prüfen
|
||||
|
||||
else {
|
||||
|
||||
if (row + wordLen > searchFieldLen) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < wordLen; j++) {
|
||||
|
||||
if (salad[row + j][col] != EMPTY_CHAR &&
|
||||
salad[row + j][col] != words[i][j]) {
|
||||
|
||||
canPlace = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Platzierung nicht möglich
|
||||
if (!canPlace) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 6. Wort tatsächlich platzieren
|
||||
for (size_t j = 0; j < wordLen; j++) {
|
||||
|
||||
if (direction == 0) {
|
||||
salad[row][col + j] = words[i][j];
|
||||
}
|
||||
else {
|
||||
salad[row + j][col] = words[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
// Erfolgreich platziertes Wort zählen
|
||||
placedWords++;
|
||||
|
||||
// Nächstes Wort bearbeiten
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 7. Leere Felder mit Zufallsbuchstaben füllen
|
||||
for (unsigned int i = 0; i < searchFieldLen; i++) {
|
||||
for (unsigned int j = 0; j < searchFieldLen; j++) {
|
||||
|
||||
if (salad[i][j] == EMPTY_CHAR) {
|
||||
salad[i][j] = 'A' + rand() % 26;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 8. Anzahl erfolgreich platzierter Wörter zurückgeben
|
||||
return (int)placedWords;
|
||||
}
|
||||
+21
-4
@@ -4,12 +4,16 @@
|
||||
#include "game.h"
|
||||
#include "graphicalGame.h"
|
||||
|
||||
#define MAX_NUMBER_OF_WORDS 100
|
||||
#define SALAD_SIZE 20
|
||||
#define MAX_NUMBER_OF_WORDS 100 //Maximale Anzahl an Wörtern, die eingelesen werden können
|
||||
#define SALAD_SIZE 20 //Größe des Wortsalats 20 Zeilen * 20 Spalten
|
||||
|
||||
int main(int argc, char *argv[]) // Hauptfunktion des Programms
|
||||
// argc = Anzahl der übergebenen Kommandozeilenargumente
|
||||
// argv = enthält die übergebenen Argumente
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int exitCode = EXIT_SUCCESS;
|
||||
int exitCode = EXIT_SUCCESS; // Speichert, ob das Programm erfolgreich beendet wird
|
||||
// EXIT_SUCCESS = kein Fehler
|
||||
|
||||
// Check if the correct number of arguments is provided
|
||||
if(argc != 2)
|
||||
@@ -36,6 +40,19 @@ int main(int argc, char *argv[])
|
||||
// Create the word salad by placing words into grid
|
||||
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
|
||||
|
||||
|
||||
if (placedWords == wordCount)
|
||||
{
|
||||
startGame(wordSalad, SALAD_SIZE, words, wordCount,800);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Not all words could be placed.\n");
|
||||
exitCode = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO:
|
||||
// Check if all words were successfully placed
|
||||
// Start the game if successful
|
||||
|
||||
Reference in new issue
Block a user