clang-format

This commit is contained in:
Rorikstr | Rust Dev 2025-10-19 21:33:16 +03:00
parent ace9659ef5
commit 9e712ae326
12 changed files with 720 additions and 769 deletions

View file

@ -35,7 +35,7 @@ TEST_TARGET = $(BUILDDIR)/test.out
PREFIX ?= $(HOME)/.local PREFIX ?= $(HOME)/.local
BINDIR = $(PREFIX)/bin BINDIR = $(PREFIX)/bin
all: $(TARGET) all: dvi dist install gcov_report run
run: clean $(TARGET) run: clean $(TARGET)
./$(TARGET) ./$(TARGET)
@ -100,14 +100,14 @@ dist: clean
tar -czf tetris.tar.gz Makefile $(TETRISDIR) $(CLIDIR) $(TESTDIR) README.md doc.md tar -czf tetris.tar.gz Makefile $(TETRISDIR) $(CLIDIR) $(TESTDIR) README.md doc.md
style: style:
@if [ -f .clang-format ]; then \ @if [ -f ../materials/linters/.clang-format ]; then \
clang-format -n $(TETRIS_SRC) $(CLI_SRC); \ clang-format -n $(TETRIS_SRC) $(CLI_SRC); \
else \ else \
echo ".clang-format not found"; \ echo ".clang-format not found"; \
fi fi
format: format:
@if [ -f .clang-format ]; then \ @if [ -f ../materials/linters/.clang-format ]; then \
clang-format -i $(TETRIS_SRC) $(CLI_SRC); \ clang-format -i $(TETRIS_SRC) $(CLI_SRC); \
else \ else \
echo ".clang-format not found"; \ echo ".clang-format not found"; \

View file

@ -2,22 +2,22 @@
void userInput(UserAction_t action, bool hold) { void userInput(UserAction_t action, bool hold) {
(void)hold; (void)hold;
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
int should_process = 1; int should_process = 1;
// Проверка паузы // Проверка паузы
if (state->info->pause) { if (state->info->pause) {
if (action == Left || action == Right || action == Down || if (action == Left || action == Right || action == Down || action == Up ||
action == Up || action == Action || action == Start) { action == Action || action == Start) {
should_process = 0; should_process = 0;
} }
} }
// Блокируем движения во время Attaching (до завершения задержки) // Блокируем движения во время Attaching (до завершения задержки)
if (state->state == Attaching && !state->attach_completed) { if (state->state == Attaching && !state->attach_completed) {
if (action == Left || action == Right || action == Down || if (action == Left || action == Right || action == Down || action == Up ||
action == Up || action == Action) { action == Action) {
should_process = 0; should_process = 0;
} }
} }
@ -67,10 +67,12 @@ void userInput(UserAction_t action, bool hold) {
if (!state->info->pause) { if (!state->info->pause) {
state->pause_start_time = get_current_time_ms(); state->pause_start_time = get_current_time_ms();
} else { } else {
long long pause_duration = get_current_time_ms() - state->pause_start_time; long long pause_duration =
get_current_time_ms() - state->pause_start_time;
state->last_move_time += pause_duration; state->last_move_time += pause_duration;
// Корректируем attach_start_time если мы в Attaching // Корректируем attach_start_time если мы в Attaching
state->attach_start_time += (state->state == Attaching) * pause_duration; state->attach_start_time +=
(state->state == Attaching) * pause_duration;
} }
state->info->pause = !state->info->pause; state->info->pause = !state->info->pause;
break; break;
@ -81,7 +83,7 @@ void userInput(UserAction_t action, bool hold) {
} }
GameInfo_t updateCurrentState() { GameInfo_t updateCurrentState() {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
int should_update = (!state->info->pause || state->state == GameOver); int should_update = (!state->info->pause || state->state == GameOver);
if (should_update) { if (should_update) {
@ -113,7 +115,7 @@ GameInfo_t updateCurrentState() {
} }
} }
Figure_t* fig = &state->curr; Figure_t *fig = &state->curr;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) { for (int j = 0; j < 4; j++) {
if (fig->mtrx[i][j]) { if (fig->mtrx[i][j]) {

View file

@ -7,7 +7,7 @@ long long get_current_time_ms(void) {
} }
int load_high_score() { int load_high_score() {
FILE* file = fopen("build/high_score.txt", "r"); FILE *file = fopen("build/high_score.txt", "r");
int high_score = 0; int high_score = 0;
if (file) { if (file) {
if (fscanf(file, "%d", &high_score) != 1) { if (fscanf(file, "%d", &high_score) != 1) {
@ -19,25 +19,25 @@ int load_high_score() {
} }
void save_high_score(int score) { void save_high_score(int score) {
FILE* file = fopen("build/high_score.txt", "w"); FILE *file = fopen("build/high_score.txt", "w");
if (file) { if (file) {
fprintf(file, "%d", score); fprintf(file, "%d", score);
fclose(file); fclose(file);
} }
} }
GameState_t* get_game_state(void) { GameState_t *get_game_state(void) {
static GameState_t state = {0}; static GameState_t state = {0};
static int initialized = 0; static int initialized = 0;
if (!initialized) { if (!initialized) {
state.info = malloc(sizeof(GameInfo_t)); state.info = malloc(sizeof(GameInfo_t));
state.info->field = malloc(FIELD_HEIGHT * sizeof(int*)); state.info->field = malloc(FIELD_HEIGHT * sizeof(int *));
for (int i = 0; i < FIELD_HEIGHT; i++) { for (int i = 0; i < FIELD_HEIGHT; i++) {
state.info->field[i] = malloc(FIELD_WIDTH * sizeof(int)); state.info->field[i] = malloc(FIELD_WIDTH * sizeof(int));
} }
state.info->next = malloc(4 * sizeof(int*)); state.info->next = malloc(4 * sizeof(int *));
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
state.info->next[i] = malloc(4 * sizeof(int)); state.info->next[i] = malloc(4 * sizeof(int));
} }
@ -60,7 +60,7 @@ GameState_t* get_game_state(void) {
} }
void terminate_and_free() { void terminate_and_free() {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
if (state->info) { if (state->info) {
if (state->info->field != NULL) { if (state->info->field != NULL) {

View file

@ -1,14 +1,14 @@
#include "01_automato.h" #include "01_automato.h"
void clear_field(void) { void clear_field(void) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
for (int i = 0; i < FIELD_HEIGHT; ++i) for (int i = 0; i < FIELD_HEIGHT; ++i)
for (int j = 0; j < FIELD_WIDTH; ++j) for (int j = 0; j < FIELD_WIDTH; ++j)
state->field[i][j] = 0; state->field[i][j] = 0;
} }
void reset_game_stats(void) { void reset_game_stats(void) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
state->info->score = 0; state->info->score = 0;
state->info->level = 1; state->info->level = 1;
state->info->speed = 1; state->info->speed = 1;

View file

@ -1,7 +1,7 @@
#include "01_automato.h" #include "01_automato.h"
void set_current_figure_from_next(void) { void set_current_figure_from_next(void) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
state->curr = state->next; state->curr = state->next;
state->curr.x = FIELD_WIDTH / 2 - 2; state->curr.x = FIELD_WIDTH / 2 - 2;
state->curr.y = 0; state->curr.y = 0;
@ -9,10 +9,10 @@ void set_current_figure_from_next(void) {
} }
void generate_next_figure(void) { void generate_next_figure(void) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
state->next.sprite = rand() % FIGURE_COUNT; state->next.sprite = rand() % FIGURE_COUNT;
state->next.rotation = 0; state->next.rotation = 0;
const int (*shape)[4] = get_figure_shape(state->next.sprite, 0); const int(*shape)[4] = get_figure_shape(state->next.sprite, 0);
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) { for (int j = 0; j < 4; ++j) {
state->next.mtrx[i][j] = shape[i][j]; state->next.mtrx[i][j] = shape[i][j];
@ -21,7 +21,7 @@ void generate_next_figure(void) {
} }
void do_spawn(void) { void do_spawn(void) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
set_current_figure_from_next(); set_current_figure_from_next();
generate_next_figure(); generate_next_figure();

View file

@ -1,21 +1,23 @@
#include "01_automato.h" #include "01_automato.h"
int get_milliseconds_to_wait(void) { int get_milliseconds_to_wait(void) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
int result = 0; int result = 0;
if (state->moving_type == ToDown) { if (state->moving_type == ToDown) {
result = INSTANT_DROP_DELAY_MS; result = INSTANT_DROP_DELAY_MS;
} else { } else {
int base_delay = BASE_FALL_DELAY_MS - (state->info->speed * SPEED_MULTIPLIER_MS); int base_delay =
result = (base_delay > SPEED_MULTIPLIER_MS) ? base_delay : SPEED_MULTIPLIER_MS; BASE_FALL_DELAY_MS - (state->info->speed * SPEED_MULTIPLIER_MS);
result =
(base_delay > SPEED_MULTIPLIER_MS) ? base_delay : SPEED_MULTIPLIER_MS;
} }
return result; return result;
} }
void do_move(void) { void do_move(void) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
long long current_time = get_current_time_ms(); long long current_time = get_current_time_ms();
int ms_to_wait = get_milliseconds_to_wait(); int ms_to_wait = get_milliseconds_to_wait();

View file

@ -1,7 +1,7 @@
#include "01_automato.h" #include "01_automato.h"
void handle_move_direction(Moving_t direction) { void handle_move_direction(Moving_t direction) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
switch (direction) { switch (direction) {
case LeftDown: case LeftDown:
state->curr.x--; state->curr.x--;
@ -15,16 +15,17 @@ void handle_move_direction(Moving_t direction) {
} }
void handle_rotate(void) { void handle_rotate(void) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
state->curr.rotation = (state->curr.rotation + 1) % 4; state->curr.rotation = (state->curr.rotation + 1) % 4;
const int (*shape)[4] = get_figure_shape(state->curr.sprite, state->curr.rotation); const int(*shape)[4] =
get_figure_shape(state->curr.sprite, state->curr.rotation);
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
for (int j = 0; j < 4; ++j) for (int j = 0; j < 4; ++j)
state->curr.mtrx[i][j] = shape[i][j]; state->curr.mtrx[i][j] = shape[i][j];
} }
void handle_horizontal_rotate_move(void) { void handle_horizontal_rotate_move(void) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
Figure_t old = state->curr; Figure_t old = state->curr;
switch (state->moving_type) { switch (state->moving_type) {
@ -46,7 +47,7 @@ void handle_horizontal_rotate_move(void) {
} }
void handle_to_down_move(void) { void handle_to_down_move(void) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
while (!check_collision()) { while (!check_collision()) {
state->curr.y++; state->curr.y++;
} }
@ -55,7 +56,7 @@ void handle_to_down_move(void) {
} }
void do_moving(void) { void do_moving(void) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
switch (state->moving_type) { switch (state->moving_type) {
case LeftDown: case LeftDown:

View file

@ -1,7 +1,7 @@
#include "01_automato.h" #include "01_automato.h"
void do_attaching(void) { void do_attaching(void) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
long long current_time = get_current_time_ms(); long long current_time = get_current_time_ms();
// Если только что вошли в Attaching - размещаем фигуру и запускаем таймер // Если только что вошли в Attaching - размещаем фигуру и запускаем таймер
@ -35,8 +35,8 @@ void do_attaching(void) {
} }
int check_collision() { int check_collision() {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
Figure_t* fig = &state->curr; Figure_t *fig = &state->curr;
int collision_detected = 0; int collision_detected = 0;
for (int i = 0; i < 4 && !collision_detected; ++i) { for (int i = 0; i < 4 && !collision_detected; ++i) {
@ -59,8 +59,8 @@ int check_collision() {
} }
void place_figure() { void place_figure() {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
Figure_t* fig = &state->curr; Figure_t *fig = &state->curr;
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) { for (int j = 0; j < 4; ++j) {
@ -76,7 +76,7 @@ void place_figure() {
} }
void shift_lines_down(int from_row) { void shift_lines_down(int from_row) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
for (int y = from_row; y > 0; --y) { for (int y = from_row; y > 0; --y) {
for (int x = 0; x < FIELD_WIDTH; ++x) { for (int x = 0; x < FIELD_WIDTH; ++x) {
state->field[y][x] = state->field[y - 1][x]; state->field[y][x] = state->field[y - 1][x];
@ -88,7 +88,7 @@ void shift_lines_down(int from_row) {
} }
void clear_lines() { void clear_lines() {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
int lines_cleared = 0; int lines_cleared = 0;
for (int i = FIELD_HEIGHT - 1; i >= 0; --i) { for (int i = FIELD_HEIGHT - 1; i >= 0; --i) {
@ -108,7 +108,8 @@ void clear_lines() {
} }
if (lines_cleared > 0) { if (lines_cleared > 0) {
int points[] = {0, POINTS_ONE_LINE, POINTS_TWO_LINES, POINTS_THREE_LINES, POINTS_FOUR_LINES}; int points[] = {0, POINTS_ONE_LINE, POINTS_TWO_LINES, POINTS_THREE_LINES,
POINTS_FOUR_LINES};
state->info->score += points[lines_cleared]; state->info->score += points[lines_cleared];
if (state->info->score > state->info->high_score) { if (state->info->score > state->info->high_score) {

View file

@ -1,14 +1,14 @@
#include "01_automato.h" #include "01_automato.h"
void do_gameover(void) { void do_gameover(void) {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
if (state->info->score > state->info->high_score) { if (state->info->score > state->info->high_score) {
state->info->high_score = state->info->score; state->info->high_score = state->info->score;
save_high_score(state->info->high_score); save_high_score(state->info->high_score);
} }
const int (*shape)[4] = empty_fig(); const int(*shape)[4] = empty_fig();
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) { for (int j = 0; j < 4; ++j) {
state->next.mtrx[i][j] = shape[i][j]; state->next.mtrx[i][j] = shape[i][j];
@ -17,7 +17,7 @@ void do_gameover(void) {
} }
int is_game_over() { int is_game_over() {
GameState_t* state = get_game_state(); GameState_t *state = get_game_state();
int game_over = 0; int game_over = 0;
for (int j = 0; j < FIELD_WIDTH; ++j) { for (int j = 0; j < FIELD_WIDTH; ++j) {

View file

@ -1,14 +1,22 @@
#include "01_automato.h" #include "01_automato.h"
const int (*get_figure_shape(Sprite_t sprite, int rotation))[4] { const int (*get_figure_shape(Sprite_t sprite, int rotation))[4] {
const int (*result)[4] = NULL; const int(*result)[4] = NULL;
switch (sprite) { switch (sprite) {
case I: case I:
switch (rotation % 4) { switch (rotation % 4) {
case 0: result = i_fig_up(); break; case 0:
case 1: result = i_fig_right(); break; result = i_fig_up();
case 2: result = i_fig_down(); break; break;
case 3: result = i_fig_left(); break; case 1:
result = i_fig_right();
break;
case 2:
result = i_fig_down();
break;
case 3:
result = i_fig_left();
break;
} }
break; break;
case O: case O:
@ -16,45 +24,86 @@ const int (*get_figure_shape(Sprite_t sprite, int rotation))[4] {
break; break;
case T: case T:
switch (rotation % 4) { switch (rotation % 4) {
case 0: result = t_fig_up(); break; case 0:
case 1: result = t_fig_right(); break; result = t_fig_up();
case 2: result = t_fig_down(); break; break;
case 3: result = t_fig_left(); break; case 1:
result = t_fig_right();
break;
case 2:
result = t_fig_down();
break;
case 3:
result = t_fig_left();
break;
} }
break; break;
case L: case L:
switch (rotation % 4) { switch (rotation % 4) {
case 0: result = l_fig_up(); break; case 0:
case 1: result = l_fig_right(); break; result = l_fig_up();
case 2: result = l_fig_down(); break; break;
case 3: result = l_fig_left(); break; case 1:
result = l_fig_right();
break;
case 2:
result = l_fig_down();
break;
case 3:
result = l_fig_left();
break;
} }
break; break;
case J: case J:
switch (rotation % 4) { switch (rotation % 4) {
case 0: result = j_fig_up(); break; case 0:
case 1: result = j_fig_right(); break; result = j_fig_up();
case 2: result = j_fig_down(); break; break;
case 3: result = j_fig_left(); break; case 1:
result = j_fig_right();
break;
case 2:
result = j_fig_down();
break;
case 3:
result = j_fig_left();
break;
} }
break; break;
case S: case S:
switch (rotation % 4) { switch (rotation % 4) {
case 0: result = s_fig_up(); break; case 0:
case 1: result = s_fig_right(); break; result = s_fig_up();
case 2: result = s_fig_down(); break; break;
case 3: result = s_fig_left(); break; case 1:
result = s_fig_right();
break;
case 2:
result = s_fig_down();
break;
case 3:
result = s_fig_left();
break;
} }
break; break;
case Z: case Z:
switch (rotation % 4) { switch (rotation % 4) {
case 0: result = z_fig_up(); break; case 0:
case 1: result = z_fig_right(); break; result = z_fig_up();
case 2: result = z_fig_down(); break; break;
case 3: result = z_fig_left(); break; case 1:
result = z_fig_right();
break;
case 2:
result = z_fig_down();
break;
case 3:
result = z_fig_left();
break;
} }
break; break;
default: result = NULL; default:
result = NULL;
} }
return result; return result;
} }
@ -62,266 +111,162 @@ const int (*get_figure_shape(Sprite_t sprite, int rotation))[4] {
// I // I
const int (*i_fig_up())[4] { const int (*i_fig_up())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 0, 0, 0}, {0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}};
{1, 1, 1, 1}, return (const int(*)[4])shape;
{0, 0, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*i_fig_right())[4] { const int (*i_fig_right())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}};
{0, 0, 1, 0}, return (const int(*)[4])shape;
{0, 0, 1, 0},
{0, 0, 1, 0}
};
return (const int (*)[4])shape;
} }
const int (*i_fig_down())[4] { const int (*i_fig_down())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}};
{0, 0, 0, 0}, return (const int(*)[4])shape;
{1, 1, 1, 1},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*i_fig_left())[4] { const int (*i_fig_left())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}};
{0, 1, 0, 0}, return (const int(*)[4])shape;
{0, 1, 0, 0},
{0, 1, 0, 0}
};
return (const int (*)[4])shape;
} }
// O // O
const int (*o_fig())[4] { const int (*o_fig())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 1, 1, 0}, {0, 1, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
{0, 1, 1, 0}, return (const int(*)[4])shape;
{0, 0, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
// T // T
const int (*t_fig_up())[4] { const int (*t_fig_up())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 1, 0, 0}, {0, 1, 0, 0}, {1, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
{1, 1, 1, 0}, return (const int(*)[4])shape;
{0, 0, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*t_fig_right())[4] { const int (*t_fig_right())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}};
{0, 1, 1, 0}, return (const int(*)[4])shape;
{0, 1, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*t_fig_down())[4] { const int (*t_fig_down())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 0, 0, 0}, {0, 0, 0, 0}, {1, 1, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}};
{1, 1, 1, 0}, return (const int(*)[4])shape;
{0, 1, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*t_fig_left())[4] { const int (*t_fig_left())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 1, 0, 0}, {0, 1, 0, 0}, {1, 1, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}};
{1, 1, 0, 0}, return (const int(*)[4])shape;
{0, 1, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
// L // L
const int (*l_fig_up())[4] { const int (*l_fig_up())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 0, 1, 0}, {0, 0, 1, 0}, {1, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
{1, 1, 1, 0}, return (const int(*)[4])shape;
{0, 0, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*l_fig_right())[4] { const int (*l_fig_right())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{1, 0, 0, 0}, {1, 0, 0, 0}, {1, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}};
{1, 0, 0, 0}, return (const int(*)[4])shape;
{1, 1, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*l_fig_down())[4] { const int (*l_fig_down())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 0, 0, 0}, {0, 0, 0, 0}, {1, 1, 1, 0}, {1, 0, 0, 0}, {0, 0, 0, 0}};
{1, 1, 1, 0}, return (const int(*)[4])shape;
{1, 0, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*l_fig_left())[4] { const int (*l_fig_left())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{1, 1, 0, 0}, {1, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}};
{0, 1, 0, 0}, return (const int(*)[4])shape;
{0, 1, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
// J // J
const int (*j_fig_up())[4] { const int (*j_fig_up())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{1, 0, 0, 0}, {1, 0, 0, 0}, {1, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
{1, 1, 1, 0}, return (const int(*)[4])shape;
{0, 0, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*j_fig_right())[4] { const int (*j_fig_right())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 1, 1, 0}, {0, 1, 1, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}};
{0, 1, 0, 0}, return (const int(*)[4])shape;
{0, 1, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*j_fig_down())[4] { const int (*j_fig_down())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 0, 0, 0}, {0, 0, 0, 0}, {1, 1, 1, 0}, {0, 0, 1, 0}, {0, 0, 0, 0}};
{1, 1, 1, 0}, return (const int(*)[4])shape;
{0, 0, 1, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*j_fig_left())[4] { const int (*j_fig_left())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}};
{0, 1, 0, 0}, return (const int(*)[4])shape;
{1, 1, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
// S // S
const int (*s_fig_up())[4] { const int (*s_fig_up())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 1, 1, 0}, {0, 1, 1, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
{1, 1, 0, 0}, return (const int(*)[4])shape;
{0, 0, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*s_fig_right())[4] { const int (*s_fig_right())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 1, 0}, {0, 0, 1, 0}, {0, 0, 0, 0}};
{0, 1, 1, 0}, return (const int(*)[4])shape;
{0, 0, 1, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*s_fig_down())[4] { const int (*s_fig_down())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 1, 1, 0}, {0, 1, 1, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
{1, 1, 0, 0}, return (const int(*)[4])shape;
{0, 0, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*s_fig_left())[4] { const int (*s_fig_left())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 1, 0}, {0, 0, 1, 0}, {0, 0, 0, 0}};
{0, 1, 1, 0}, return (const int(*)[4])shape;
{0, 0, 1, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
// Z // Z
const int (*z_fig_up())[4] { const int (*z_fig_up())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{1, 1, 0, 0}, {1, 1, 0, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
{0, 1, 1, 0}, return (const int(*)[4])shape;
{0, 0, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*z_fig_right())[4] { const int (*z_fig_right())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 0, 1, 0}, {0, 0, 1, 0}, {0, 1, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}};
{0, 1, 1, 0}, return (const int(*)[4])shape;
{0, 1, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*z_fig_down())[4] { const int (*z_fig_down())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{1, 1, 0, 0}, {1, 1, 0, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
{0, 1, 1, 0}, return (const int(*)[4])shape;
{0, 0, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*z_fig_left())[4] { const int (*z_fig_left())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 0, 1, 0}, {0, 0, 1, 0}, {0, 1, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}};
{0, 1, 1, 0}, return (const int(*)[4])shape;
{0, 1, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }
const int (*empty_fig())[4] { const int (*empty_fig())[4] {
static const int shape[4][4] = { static const int shape[4][4] = {
{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
{0, 0, 0, 0}, return (const int(*)[4])shape;
{0, 0, 0, 0},
{0, 0, 0, 0}
};
return (const int (*)[4])shape;
} }

View file

@ -1,6 +1,6 @@
// src/gui/cli/display.c // src/gui/cli/display.c
#include <ncurses.h>
#include "../../brick_game/tetris/00_tetris.h" #include "../../brick_game/tetris/00_tetris.h"
#include <ncurses.h>
void display_game(GameInfo_t game_state) { void display_game(GameInfo_t game_state) {
clear(); clear();

View file

@ -1,8 +1,8 @@
#include "../../brick_game/tetris/00_tetris.h"
#include <ncurses.h> #include <ncurses.h>
#include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include "../../brick_game/tetris/00_tetris.h" #include <unistd.h>
void display_game(GameInfo_t game_state); void display_game(GameInfo_t game_state);