Start_Windows/game.c aktualisiert
This commit is contained in:
parent
6f92d66b10
commit
5d4a58dd34
@ -1,29 +1,31 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define SIZE 10 // Anzahl der Zeilen in der Spalte
|
#define SIZE 20 // Spielfeldgröße 20x20
|
||||||
|
#define EMPTY_CHAR 0 // Kennzeichen für leere Felder
|
||||||
|
|
||||||
// Erzeugt eine Spalte mit zufälligen Buchstaben
|
// Platziert Wörter zufällig horizontal oder vertikal
|
||||||
void createColumn(char column[SIZE]) {
|
void createWordSalad(char grid[SIZE][SIZE], const char words[][50], int wordCount) {
|
||||||
for (int i = 0; i < SIZE; i++) {
|
srand(time(NULL));
|
||||||
column[i] = 'A' + rand() % 26; // Zufälliger Buchstabe A-Z
|
for (int w = 0; w < wordCount; w++) {
|
||||||
|
int len = strlen(words[w]);
|
||||||
|
int horizontal = rand() % 2;
|
||||||
|
int row = rand() % SIZE;
|
||||||
|
int col = rand() % SIZE;
|
||||||
|
|
||||||
|
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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gibt die Spalte aus
|
// Füllt leere Felder mit zufälligen Buchstaben
|
||||||
void showColumn(char column[SIZE]) {
|
void fillEmptySpaces(char grid[SIZE][SIZE]) {
|
||||||
for (int i = 0; i < SIZE; i++) {
|
for (int i = 0; i < SIZE; i++)
|
||||||
printf("%c\n", column[i]);
|
for (int j = 0; j < SIZE; j++)
|
||||||
}
|
if (grid[i][j] == EMPTY_CHAR)
|
||||||
}
|
grid[i][j] = 'A' + rand() % 26;
|
||||||
|
|
||||||
int main() {
|
|
||||||
srand(time(NULL)); // Zufallszahlengenerator initialisieren
|
|
||||||
|
|
||||||
char column[SIZE];
|
|
||||||
createColumn(column);
|
|
||||||
showColumn(column);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user