clang-format
This commit is contained in:
parent
ace9659ef5
commit
9e712ae326
12 changed files with 720 additions and 769 deletions
|
|
@ -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"; \
|
||||
|
|
|
|||
|
|
@ -2,22 +2,22 @@
|
|||
|
||||
void userInput(UserAction_t action, bool hold) {
|
||||
(void)hold;
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
|
||||
int should_process = 1;
|
||||
|
||||
// Проверка паузы
|
||||
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;
|
||||
|
|
@ -81,7 +83,7 @@ void userInput(UserAction_t action, bool hold) {
|
|||
}
|
||||
|
||||
GameInfo_t updateCurrentState() {
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
|
||||
int should_update = (!state->info->pause || state->state == GameOver);
|
||||
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 j = 0; j < 4; j++) {
|
||||
if (fig->mtrx[i][j]) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ long long get_current_time_ms(void) {
|
|||
}
|
||||
|
||||
int load_high_score() {
|
||||
FILE* file = fopen("build/high_score.txt", "r");
|
||||
FILE *file = fopen("build/high_score.txt", "r");
|
||||
int high_score = 0;
|
||||
if (file) {
|
||||
if (fscanf(file, "%d", &high_score) != 1) {
|
||||
|
|
@ -19,25 +19,25 @@ int load_high_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) {
|
||||
fprintf(file, "%d", score);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
|
||||
GameState_t* get_game_state(void) {
|
||||
GameState_t *get_game_state(void) {
|
||||
static GameState_t state = {0};
|
||||
static int initialized = 0;
|
||||
|
||||
if (!initialized) {
|
||||
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++) {
|
||||
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++) {
|
||||
state.info->next[i] = malloc(4 * sizeof(int));
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ GameState_t* get_game_state(void) {
|
|||
}
|
||||
|
||||
void terminate_and_free() {
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
|
||||
if (state->info) {
|
||||
if (state->info->field != NULL) {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
#include "01_automato.h"
|
||||
|
||||
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 j = 0; j < FIELD_WIDTH; ++j)
|
||||
state->field[i][j] = 0;
|
||||
}
|
||||
|
||||
void reset_game_stats(void) {
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
state->info->score = 0;
|
||||
state->info->level = 1;
|
||||
state->info->speed = 1;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "01_automato.h"
|
||||
|
||||
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.x = FIELD_WIDTH / 2 - 2;
|
||||
state->curr.y = 0;
|
||||
|
|
@ -9,10 +9,10 @@ void set_current_figure_from_next(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.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 j = 0; j < 4; ++j) {
|
||||
state->next.mtrx[i][j] = shape[i][j];
|
||||
|
|
@ -21,7 +21,7 @@ void generate_next_figure(void) {
|
|||
}
|
||||
|
||||
void do_spawn(void) {
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
|
||||
set_current_figure_from_next();
|
||||
generate_next_figure();
|
||||
|
|
|
|||
|
|
@ -1,21 +1,23 @@
|
|||
#include "01_automato.h"
|
||||
|
||||
int get_milliseconds_to_wait(void) {
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
int result = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void do_move(void) {
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
|
||||
long long current_time = get_current_time_ms();
|
||||
int ms_to_wait = get_milliseconds_to_wait();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "01_automato.h"
|
||||
|
||||
void handle_move_direction(Moving_t direction) {
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
switch (direction) {
|
||||
case LeftDown:
|
||||
state->curr.x--;
|
||||
|
|
@ -15,16 +15,17 @@ void handle_move_direction(Moving_t direction) {
|
|||
}
|
||||
|
||||
void handle_rotate(void) {
|
||||
GameState_t* state = get_game_state();
|
||||
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];
|
||||
}
|
||||
|
||||
void handle_horizontal_rotate_move(void) {
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
Figure_t old = state->curr;
|
||||
|
||||
switch (state->moving_type) {
|
||||
|
|
@ -46,7 +47,7 @@ void handle_horizontal_rotate_move(void) {
|
|||
}
|
||||
|
||||
void handle_to_down_move(void) {
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
while (!check_collision()) {
|
||||
state->curr.y++;
|
||||
}
|
||||
|
|
@ -55,7 +56,7 @@ void handle_to_down_move(void) {
|
|||
}
|
||||
|
||||
void do_moving(void) {
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
|
||||
switch (state->moving_type) {
|
||||
case LeftDown:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "01_automato.h"
|
||||
|
||||
void do_attaching(void) {
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
long long current_time = get_current_time_ms();
|
||||
|
||||
// Если только что вошли в Attaching - размещаем фигуру и запускаем таймер
|
||||
|
|
@ -35,8 +35,8 @@ void do_attaching(void) {
|
|||
}
|
||||
|
||||
int check_collision() {
|
||||
GameState_t* state = get_game_state();
|
||||
Figure_t* fig = &state->curr;
|
||||
GameState_t *state = get_game_state();
|
||||
Figure_t *fig = &state->curr;
|
||||
int collision_detected = 0;
|
||||
|
||||
for (int i = 0; i < 4 && !collision_detected; ++i) {
|
||||
|
|
@ -59,8 +59,8 @@ int check_collision() {
|
|||
}
|
||||
|
||||
void place_figure() {
|
||||
GameState_t* state = get_game_state();
|
||||
Figure_t* fig = &state->curr;
|
||||
GameState_t *state = get_game_state();
|
||||
Figure_t *fig = &state->curr;
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
|
|
@ -76,7 +76,7 @@ void place_figure() {
|
|||
}
|
||||
|
||||
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 x = 0; x < FIELD_WIDTH; ++x) {
|
||||
state->field[y][x] = state->field[y - 1][x];
|
||||
|
|
@ -88,7 +88,7 @@ void shift_lines_down(int from_row) {
|
|||
}
|
||||
|
||||
void clear_lines() {
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
int lines_cleared = 0;
|
||||
|
||||
for (int i = FIELD_HEIGHT - 1; i >= 0; --i) {
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
#include "01_automato.h"
|
||||
|
||||
void do_gameover(void) {
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
|
||||
if (state->info->score > state->info->high_score) {
|
||||
state->info->high_score = state->info->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 j = 0; j < 4; ++j) {
|
||||
state->next.mtrx[i][j] = shape[i][j];
|
||||
|
|
@ -17,7 +17,7 @@ void do_gameover(void) {
|
|||
}
|
||||
|
||||
int is_game_over() {
|
||||
GameState_t* state = get_game_state();
|
||||
GameState_t *state = get_game_state();
|
||||
int game_over = 0;
|
||||
|
||||
for (int j = 0; j < FIELD_WIDTH; ++j) {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,22 @@
|
|||
#include "01_automato.h"
|
||||
|
||||
const int (*get_figure_shape(Sprite_t sprite, int rotation))[4] {
|
||||
const int (*result)[4] = NULL;
|
||||
const int(*result)[4] = NULL;
|
||||
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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{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}
|
||||
};
|
||||
return (const int (*)[4])shape;
|
||||
{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
|
||||
return (const int(*)[4])shape;
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue