/
egevtech
/
blocker
Обзор
Документация
Войти
/
egevtech
/
blocker
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
include/blocks.c
71 строка
2 KB
Павел
v0.0.2
17 май 2025, 19:24
17 май 2025, 19:24
bf1862c
Код
Авторство
О чём код?
#include "blocks.h" #include <stdio.h> void initField(BAC bac) { // bac.blocks[0][0] = *bac.null; printf("\e[1;33mИниализация поля...\n\e[0m"); for (int x = 0; x < bac.grid_size; x++) for ( int y = 0; y < bac.grid_size; y++) bac.blocks[x][y] = *bac.null; printf("\e[1;32mИниализация поля завершена\n\e[0m"); } void put ( BAC bac, Block t, Vec2 pos ) { if (bac.blocks[pos.x][pos.y].id != t.id) { bac.blocks[pos.x][pos.y] = t; printf("\e[1;32mБлок %s(id:%d) установлен по координатам: x%d:y%d\e[0m\n", t.title, t.id, pos.x, pos.y); } else return; } Block get( BAC bac, Vec2 pos ) { return bac.blocks[pos.x][pos.y]; } void destroy(BAC bac, Vec2 pos) { Block *block = &bac.blocks[pos.x][pos.y]; if (block == NULL) *block = *bac.null; else if ( block->id != bac.null->id) { printf("\e[1;31mБлок %s(id:%d) удален по координатам: x%d:y%d\e[0m\n", block->title, block->id, pos.x, pos.y); *block = *bac.null; } } void clearGrid(BAC bac) { if (isGridEmpty( bac ) == 1) return; printf("\e[1;33mОчистка начата...\e[0m\n"); for ( int x = 0; x < bac.grid_size; x++ ) { for ( int y = 0; y < bac.grid_size; y++ ) { destroy(bac, (Vec2){x, y}); } } printf("\e[1;33mПоле очищено\e[0m\n"); } int isGridEmpty( BAC bac ) { for ( int x = 0; x < bac.grid_size; x++ ) { for ( int y = 0; y < bac.grid_size; y++ ) { if ( bac.blocks[x][y].id != bac.null->id ) return 0; } } return 1; }