Setze random Buchstaben in die noch leeren Felder (hab bei mir die unit-tests nicht zum laufen bekommen)
This commit is contained in:
1 parent
a02b363e20
commit
ce17403a1b
2 files changed
+69
-13
No files matched your search
+15
-1
@@ -6,6 +6,11 @@
|
||||
#define MAX_RAND_TRIES_PER_WORD 10
|
||||
#define EMPTY_CHAR 0
|
||||
|
||||
typedef enum Richtung {
|
||||
VERTIKAL = 0;
|
||||
HORIZONTAL = 1;
|
||||
};
|
||||
|
||||
//TODO: Spiellogik implementieren:
|
||||
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||
@@ -18,6 +23,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
|
||||
//Initialisiere spielfeld auf '0'
|
||||
// TODO: memset()
|
||||
//memset(salad, '0', MAX_SEARCH_FIELD_LEN * MAX_SEARCH_FIELD_LEN);
|
||||
for(int i = 0; i < MAX_SEARCH_FIELD_LEN; i++){
|
||||
for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++){
|
||||
salad[i][j] = '0';
|
||||
@@ -53,7 +59,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
}
|
||||
|
||||
//place word vertically
|
||||
if(dir == 1){
|
||||
if(dir == HORIZONTAL){
|
||||
//see if all neccessary spaces are empty
|
||||
bool cont = false;
|
||||
for (int i = 0; i < (int)len; i++){
|
||||
@@ -95,5 +101,13 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
placedWords++;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < MAX_SEARCH_FIELD_LEN; i++){
|
||||
for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++){
|
||||
if(salad[i][j] == '0'){
|
||||
char c = 'A' + (rand() % 26);
|
||||
salad[i][j] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return placedWords;
|
||||
}
|
||||
Reference in new issue
Block a user