generated from freudenreichan/info2Praktikum-Wortsalat
Compare commits
2 Commits
5d91ffc0b1
...
af80d62ba6
| Author | SHA1 | Date | |
|---|---|---|---|
| af80d62ba6 | |||
| e29f2bb6c3 |
@ -34,17 +34,21 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
||||
int wordlength = 0;
|
||||
do
|
||||
{
|
||||
while(words[i][wordlength] != '0')//gets the length of the current word
|
||||
while((words[i][wordlength] != '\0')&&(wordlength != MAX_WORD_LEN))//gets the length of the current word
|
||||
{
|
||||
wordlength++;
|
||||
int startPosition1 = RANDOMNUMBER(0, MAX_SEARCH_FIELD_LEN - wordlength);//gets a random starting position for the word
|
||||
int startPosition2 = RANDOMNUMBER(0, MAX_SEARCH_FIELD_LEN);//gest a second coordinate for the starting position
|
||||
}
|
||||
int startPosition1 = RANDOMNUMBER(0, searchFieldLen - wordlength);//gets a random starting position for the word
|
||||
int startPosition2 = RANDOMNUMBER(0, searchFieldLen);//gest a second coordinate for the starting position
|
||||
if(RANDOMNUMBER(0,1) < 1)//Flips a coin whether the number is vertical or horizontal
|
||||
{//Horizontal
|
||||
int allClear = 0;
|
||||
for(int j = 0; j < wordlength; j++)//Checks, if there already is a word, where the new word should be placed.
|
||||
{
|
||||
if(salad[startPosition1 + j][startPosition2] != 63)
|
||||
{
|
||||
allClear++;
|
||||
}
|
||||
}
|
||||
if(allClear == 0)//Places the word
|
||||
{
|
||||
|
||||
@ -43,7 +43,8 @@ int main(int argc, char *argv[])
|
||||
// error message if some words couldn't be placed
|
||||
int windowWidth = 720; //Fensterbreite outputfenster
|
||||
if (placedWords == wordCount && placedWords <= MAX_NUMBER_OF_WORDS) {
|
||||
startGame(wordSalad, MAX_SEARCH_FIELD_LEN, words, wordCount, windowWidth);
|
||||
showWordSalad(wordSalad, SALAD_SIZE);
|
||||
startGame(wordSalad, SALAD_SIZE, words, wordCount, windowWidth);
|
||||
exitCode = EXIT_SUCCESS; //Start the game if placed words is equal to words in textfile
|
||||
}
|
||||
else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user