array befuellen in game und mit empty char
This commit is contained in:
parent
25f7fb4d39
commit
81d0e35517
@ -31,6 +31,14 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
int voll = 0;
|
int voll = 0;
|
||||||
int tries = 0;
|
int tries = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_SEARCH_FIELD_LEN; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < MAX_SEARCH_FIELD_LEN; j++)
|
||||||
|
{
|
||||||
|
salad[i][j] = EMPTY_CHAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (vertikal_horizontal == VERTIKAL) {
|
if (vertikal_horizontal == VERTIKAL) {
|
||||||
|
|
||||||
tries = 0;
|
tries = 0;
|
||||||
@ -39,7 +47,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
positionX = rand() % (searchFieldLen);
|
positionX = rand() % (searchFieldLen);
|
||||||
positionY = rand() % (searchFieldLen-leange);
|
positionY = rand() % (searchFieldLen-leange);
|
||||||
for(int j = positionY; j < positionY+leange ; j++) { //überprüfung ob alle positionen 0 sind
|
for(int j = positionY; j < positionY+leange ; j++) { //überprüfung ob alle positionen 0 sind
|
||||||
if(salad[j][positionX] != '0') {
|
if(salad[j][positionX] != EMPTY_CHAR) {
|
||||||
voll = 1;
|
voll = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,7 +59,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
}
|
}
|
||||||
placedWordsCount++;
|
placedWordsCount++;
|
||||||
} else if (voll == 1)
|
} else if (voll == 1)
|
||||||
printf("Das Wort '%s' konnte nicht plaziert werden", words[i]);
|
printf("Das Wort '%s' konnte nicht plaziert werden\n", words[i]);
|
||||||
|
|
||||||
} else if (vertikal_horizontal == HORIZONTAL) {
|
} else if (vertikal_horizontal == HORIZONTAL) {
|
||||||
|
|
||||||
@ -61,7 +69,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
positionY = rand() % (searchFieldLen);
|
positionY = rand() % (searchFieldLen);
|
||||||
positionX = rand() % (searchFieldLen-leange);
|
positionX = rand() % (searchFieldLen-leange);
|
||||||
for(int j = positionX; j < positionX+leange ; j++) { //überprüfung ob alle positionen 0 sind
|
for(int j = positionX; j < positionX+leange ; j++) { //überprüfung ob alle positionen 0 sind
|
||||||
if(salad[positionY][j] != '0') {
|
if(salad[positionY][j] != EMPTY_CHAR) {
|
||||||
voll = 1;
|
voll = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,7 +81,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
}
|
}
|
||||||
placedWordsCount++;
|
placedWordsCount++;
|
||||||
} else if (voll == 1)
|
} else if (voll == 1)
|
||||||
printf("Das Wort '%s' konnte nicht plaziert werden", words[i]);
|
printf("Das Wort '%s' konnte nicht plaziert werden\n", words[i]);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
printf("Fehler bei Vertikal Horizontal Wert: %d", vertikal_horizontal);
|
printf("Fehler bei Vertikal Horizontal Wert: %d", vertikal_horizontal);
|
||||||
@ -81,7 +89,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
|
|
||||||
for(int i = 0; i < searchFieldLen; i++) {
|
for(int i = 0; i < searchFieldLen; i++) {
|
||||||
for(int j = 0; j < searchFieldLen; j++) {
|
for(int j = 0; j < searchFieldLen; j++) {
|
||||||
if(salad[i][j] == '0') {
|
if(salad[i][j] == EMPTY_CHAR) {
|
||||||
salad[i][j] = buchstaben[rand() % anzahlBuchstaben];
|
salad[i][j] = buchstaben[rand() % anzahlBuchstaben];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Start_Mac/game.o
BIN
Start_Mac/game.o
Binary file not shown.
@ -28,11 +28,6 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
unsigned int placedWords = 0;
|
unsigned int placedWords = 0;
|
||||||
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
|
char wordSalad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; // 2D array to store the word salad
|
||||||
for(int i = 0; i < MAX_SEARCH_FIELD_LEN; i++) {
|
|
||||||
for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++) {
|
|
||||||
wordSalad[i][j] = '0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read words from file and store in 'words' array
|
// Read words from file and store in 'words' array
|
||||||
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
|
wordCount = readWords(file, words, MAX_NUMBER_OF_WORDS);
|
||||||
|
|||||||
BIN
Start_Mac/main.o
BIN
Start_Mac/main.o
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user