generated from freudenreichan/info2Praktikum-Wortsalat
Compare commits
3
Commits
a22ac56d40
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af80d62ba6 | ||
|
|
e29f2bb6c3 | ||
|
|
5d91ffc0b1 |
No files matched your search
@@ -34,17 +34,21 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
|
|||||||
int wordlength = 0;
|
int wordlength = 0;
|
||||||
do
|
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++;
|
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
|
if(RANDOMNUMBER(0,1) < 1)//Flips a coin whether the number is vertical or horizontal
|
||||||
{//Horizontal
|
{//Horizontal
|
||||||
int allClear = 0;
|
int allClear = 0;
|
||||||
for(int j = 0; j < wordlength; j++)//Checks, if there already is a word, where the new word should be placed.
|
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)
|
if(salad[startPosition1 + j][startPosition2] != 63)
|
||||||
|
{
|
||||||
allClear++;
|
allClear++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(allClear == 0)//Places the word
|
if(allClear == 0)//Places the word
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ void readWordsFromLine(char buffer[], int* wordCount, char words[][MAX_WORD_LEN]
|
|||||||
// Read words from file and store in 'words' array
|
// Read words from file and store in 'words' array
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < maxWordCount; i++) {
|
||||||
|
for (int j = 0; j < MAX_WORD_LEN; j++) {
|
||||||
|
words[i][j] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
char buffer[MAX_LINE_LEN]; // prepares a large enough buffer to read one line from the .txt-file
|
char buffer[MAX_LINE_LEN]; // prepares a large enough buffer to read one line from the .txt-file
|
||||||
int readwords = 0;
|
int readwords = 0;
|
||||||
int *wordCount = &readwords;
|
int *wordCount = &readwords;
|
||||||
|
|||||||
@@ -35,12 +35,16 @@ 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);
|
||||||
|
printf("Checkpoint1");
|
||||||
|
|
||||||
// TODO:
|
// 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
|
||||||
|
int windowWidth = 720; //Fensterbreite outputfenster
|
||||||
if (placedWords == wordCount && placedWords <= MAX_NUMBER_OF_WORDS) {
|
if (placedWords == wordCount && placedWords <= MAX_NUMBER_OF_WORDS) {
|
||||||
|
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
|
exitCode = EXIT_SUCCESS; //Start the game if placed words is equal to words in textfile
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -58,4 +62,4 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user