Untitled
unknown
plain_text
2 years ago
1.3 kB
9
Indexable
void add_structure_from_file(int field[HEIGHT][WIDTH], const char* filename) {
FILE* file = fopen(filename, "r");
if (!file) {
perror("Ошибка при открытии файла структуры");
exit(EXIT_FAILURE);
}
int offsetX = rand() % WIDTH;
int offsetY = rand() % HEIGHT;
char line[100];
int y = 0;
while (fgets(line, sizeof(line), file)) {
for (int x = 0; line[x] != '\n' && line[x] != '\0'; x++) {
if (line[x] == 'O') {
int actualX = (offsetX + x) % WIDTH;
int actualY = (offsetY + y) % HEIGHT;
field[actualY][actualX] = 1;
}
}
y++;
}
fclose(file);
}
int main() {
srand(time(NULL)); // Инициализация генератора случайных чисел
int field[HEIGHT][WIDTH];
init_field(field);
// Пример добавления глайдера и LWSS из файлов
add_structure_from_file(field, "glider.txt");
add_structure_from_file(field, "lwss.txt");
while (1) {
render(field);
update(field);
wait(0.1);
// Рассмотрите условие для добавления новых структур по времени или событию
}
return 0;
}
Editor is loading...
Leave a Comment