it's working but should fix return issue
This commit is contained in:
parent
1911d23459
commit
9de308925c
7 changed files with 609 additions and 212 deletions
|
|
@ -5,31 +5,40 @@
|
|||
void display_game() {
|
||||
clear();
|
||||
|
||||
GameStateData* state = get_game_state();
|
||||
GameInfo_t game_state = updateCurrentState();
|
||||
|
||||
// Очистка поля
|
||||
// Отображение игрового поля
|
||||
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, '$');
|
||||
}
|
||||
}
|
||||
if (game_state.field[i][j] != 0) {
|
||||
mvaddch(i + 1, j * 2 + 1, '#'); // Заполненные блоки
|
||||
} else {
|
||||
mvaddch(i + 1, j * 2 + 1, '.'); // Пустые ячейки
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Отображение следующей фигуры
|
||||
mvaddstr(1, FIELD_WIDTH * 2 + 5, "Next figure:");
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (game_state.next[i][j]) {
|
||||
mvaddch(i + 3, (FIELD_WIDTH * 2 + 5) + j * 2, '@');
|
||||
} else {
|
||||
mvaddch(i + 3, (FIELD_WIDTH * 2 + 5) + j * 2, ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mvprintw(FIELD_HEIGHT + 2, 1, "Score: %d", game_state.score);
|
||||
mvprintw(FIELD_HEIGHT + 3, 1, "High Score: %d", game_state.high_score);
|
||||
mvprintw(FIELD_HEIGHT + 4, 1, "Level: %d", game_state.level);
|
||||
mvprintw(FIELD_HEIGHT + 5, 1, "Speed: %d", game_state.speed);
|
||||
|
||||
if (game_state.pause) {
|
||||
mvprintw(FIELD_HEIGHT / 2, FIELD_WIDTH - 4, "PAUSED");
|
||||
}
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
|
@ -14,35 +14,57 @@ int main() {
|
|||
nodelay(stdscr, TRUE);
|
||||
curs_set(0);
|
||||
|
||||
timeout(100); // Таймаут для getch()
|
||||
timeout(100);
|
||||
|
||||
int ch;
|
||||
UserAction_t action = Undefined;
|
||||
while (Terminate != action) {
|
||||
UserAction_t current_action;
|
||||
bool action_valid = false;
|
||||
bool running = true;
|
||||
|
||||
while (running) {
|
||||
ch = getch();
|
||||
action_valid = false;
|
||||
|
||||
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 '6': action = Figure6; break;
|
||||
case '7': action = Figure7; break;
|
||||
case 'r': action = Rotate; break;
|
||||
case ' ': action = Rotate; 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;
|
||||
default: action = Undefined;
|
||||
}
|
||||
|
||||
if (action != Undefined) {
|
||||
user_input(action);
|
||||
case 'q':
|
||||
userInput(Terminate, false);
|
||||
running = false;
|
||||
break;
|
||||
case 'r': case ' ':
|
||||
current_action = Action;
|
||||
action_valid = true;
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
current_action = Left;
|
||||
action_valid = true;
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
current_action = Right;
|
||||
action_valid = true;
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
current_action = Down;
|
||||
action_valid = true;
|
||||
break;
|
||||
case KEY_UP:
|
||||
current_action = Up;
|
||||
action_valid = true;
|
||||
break;
|
||||
case 's': case 'S':
|
||||
current_action = Start;
|
||||
action_valid = true;
|
||||
break;
|
||||
case 'p': case 'P':
|
||||
current_action = Pause;
|
||||
action_valid = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (action_valid) {
|
||||
userInput(current_action, false);
|
||||
}
|
||||
|
||||
updateCurrentState();
|
||||
display_game();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue