fix seed generator for game

This commit is contained in:
hoangto105860 committed 2026-10-24 21:28:35 +02:00
1 parent ab558de8b3
commit cbf5f85caf
9 files changed
+27 -10

No files matched your search

+2 -6
View File
@@ -1,5 +1,4 @@
#include "game.h"
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
@@ -14,7 +13,6 @@
// Creates the word salad by placing words randomly and filling empty spaces
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
{
srand(time(NULL));
unsigned int placedWords = 0;
//printf("start game.c\n");
@@ -28,7 +26,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
//printf("[%d] of words: %s\n", i, words[i]);
}
//fillRandAlpha(searchFieldLen, salad);
fillRandAlpha(searchFieldLen, salad);
printf("placedWords:%d\n", placedWords);
@@ -61,9 +59,7 @@ int placement(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned i
printf("%s\n", word);
int verhor = rand() % 2;
if(verhor == 1)
if(rand() % 2)
{
for(int i = 0; i < strlen(word); i++)
{
BIN
View File
Binary file not shown.
+21 -4
View File
@@ -3,6 +3,9 @@
#include "input.h"
#include "game.h"
#include "graphicalGame.h"
#include <errno.h>
#include <time.h>
#define MAX_NUMBER_OF_WORDS 100
#define SALAD_SIZE 20
@@ -10,8 +13,9 @@
int main(int argc, char *argv[])
{
int exitCode = EXIT_SUCCESS;
printf("start main\n");
srand(time(NULL));
// Check if the correct number of arguments is provided
if(argc != 2)
{
@@ -35,13 +39,26 @@ int main(int argc, char *argv[])
fclose(file);
// Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
//placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// TODO:
// Check if all words were successfully placed
// Start the game if successful
// error message if some words couldn't be placed
for(int i = 0; i < 10000; i++)
{
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
if(placedWords == wordCount)
{
// Start the game if successful
return exitCode;
}
}
// error message if some words couldn't be placed
fprintf(stderr, "could not start wordsalad.\n");
exitCode = EXIT_FAILURE;
}
else
{
BIN
View File
Binary file not shown.
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
Hund,Katze; Maus
View File
Whitespace-only changes.
+3
View File
@@ -0,0 +1,3 @@
Apfel
Banane
Kiwi
Binary file not shown.