Start_Windows/game.c aktualisiert
This commit is contained in:
parent
5d4a58dd34
commit
6c6235b310
@ -1,31 +1,24 @@
|
|||||||
|
#include "game.h"
|
||||||
|
#include <time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#define SIZE 20 // Spielfeldgröße 20x20
|
#define MAX_RAND_TRIES_PER_WORD 10
|
||||||
#define EMPTY_CHAR 0 // Kennzeichen für leere Felder
|
#define EMPTY_CHAR 0
|
||||||
|
|
||||||
// Platziert Wörter zufällig horizontal oder vertikal
|
//TODO: Spiellogik implementieren:
|
||||||
void createWordSalad(char grid[SIZE][SIZE], const char words[][50], int wordCount) {
|
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
|
||||||
srand(time(NULL));
|
* restliche Felder mit zufälligen Buchstaben füllen */
|
||||||
for (int w = 0; w < wordCount; w++) {
|
|
||||||
int len = strlen(words[w]);
|
// Creates the word salad by placing words randomly and filling empty spaces
|
||||||
int horizontal = rand() % 2;
|
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
||||||
int row = rand() % SIZE;
|
{
|
||||||
int col = rand() % SIZE;
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prints the word salad to console
|
||||||
|
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
|
||||||
|
{
|
||||||
|
|
||||||
if (horizontal && col + len <= SIZE) {
|
|
||||||
for (int i = 0; i < len; i++) grid[row][col + i] = words[w][i];
|
|
||||||
} else if (!horizontal && row + len <= SIZE) {
|
|
||||||
for (int i = 0; i < len; i++) grid[row + i][col] = words[w][i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Füllt leere Felder mit zufälligen Buchstaben
|
|
||||||
void fillEmptySpaces(char grid[SIZE][SIZE]) {
|
|
||||||
for (int i = 0; i < SIZE; i++)
|
|
||||||
for (int j = 0; j < SIZE; j++)
|
|
||||||
if (grid[i][j] == EMPTY_CHAR)
|
|
||||||
grid[i][j] = 'A' + rand() % 26;
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user