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

View file

@ -8,16 +8,16 @@ void userInput(UserAction_t action, bool hold) {
// Проверка паузы
if (state->info->pause) {
if (action == Left || action == Right || action == Down ||
action == Up || action == Action || action == Start) {
if (action == Left || action == Right || action == Down || action == Up ||
action == Action || action == Start) {
should_process = 0;
}
}
// Блокируем движения во время Attaching (до завершения задержки)
if (state->state == Attaching && !state->attach_completed) {
if (action == Left || action == Right || action == Down ||
action == Up || action == Action) {
if (action == Left || action == Right || action == Down || action == Up ||
action == Action) {
should_process = 0;
}
}
@ -67,10 +67,12 @@ void userInput(UserAction_t action, bool hold) {
if (!state->info->pause) {
state->pause_start_time = get_current_time_ms();
} 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;
// Корректируем 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;
break;

View file

@ -7,8 +7,10 @@ int get_milliseconds_to_wait(void) {
if (state->moving_type == ToDown) {
result = INSTANT_DROP_DELAY_MS;
} else {
int base_delay = BASE_FALL_DELAY_MS - (state->info->speed * SPEED_MULTIPLIER_MS);
result = (base_delay > SPEED_MULTIPLIER_MS) ? base_delay : SPEED_MULTIPLIER_MS;
int base_delay =
BASE_FALL_DELAY_MS - (state->info->speed * SPEED_MULTIPLIER_MS);
result =
(base_delay > SPEED_MULTIPLIER_MS) ? base_delay : SPEED_MULTIPLIER_MS;
}
return result;

View file

@ -17,7 +17,8 @@ void handle_move_direction(Moving_t direction) {
void handle_rotate(void) {
GameState_t *state = get_game_state();
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 j = 0; j < 4; ++j)
state->curr.mtrx[i][j] = shape[i][j];

View file

@ -108,7 +108,8 @@ void clear_lines() {
}
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];
if (state->info->score > state->info->high_score) {

View file

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

View file

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

View file

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