Фигурки то рисуются!

This commit is contained in:
Rorikstr | Rust Dev 2025-09-26 13:28:53 +03:00
parent e20765d252
commit fef0d8cbe3
6 changed files with 176 additions and 22 deletions

View file

@ -0,0 +1,35 @@
// src/gui/cli/display.c
#include <ncurses.h>
#include "../../brick_game/tetris/tetris.h"
void display_game() {
clear();
GameStateData* state = getGameState();
// Очистка поля
for (int i = 0; i < FIELD_HEIGHT; i++) {
for (int j = 0; j < FIELD_WIDTH; j++) {
mvaddch(i + 1, j * 2 + 1, '.');
}
}
// Если фигура активна — отображаем её
if (state->figure_active) {
Figure* f = &state->current_figure;
const int (*shape)[4] = get_figure_shape(f->type, f->rotation);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (shape[i][j]) {
int x = f->x + j;
int y = f->y + i;
if (x >= 0 && x < FIELD_WIDTH && y >= 0 && y < FIELD_HEIGHT) {
mvaddch(y + 1, x * 2 + 1, '$');
}
}
}
}
}
refresh();
}

View file

@ -0,0 +1,50 @@
// src/gui/cli/main.c
#include <ncurses.h>
#include <time.h>
#include <unistd.h>
#include "../../brick_game/tetris/tetris.h"
void display_game();
int main() {
initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);
nodelay(stdscr, TRUE);
curs_set(0);
timeout(100); // Таймаут для getch()
int ch;
bool hold = false;
while (1) {
ch = getch();
UserAction_t action = Undefined;
switch (ch) {
case 'q': action = Terminate; break;
case '1': action = Figure1; break;
case '2': action = Figure2; break;
case '3': action = Figure3; break;
case '4': action = Figure4; break;
case '5': action = Figure5; break;
case KEY_LEFT: action = Left; break;
case KEY_RIGHT: action = Right; break;
case KEY_DOWN: action = Down; break;
case KEY_UP: action = Up; break;
}
if (action != Undefined) {
userInput(action, hold);
}
display_game();
if (action == Terminate) break;
}
endwin();
return 0;
}