fixed to more readable state

This commit is contained in:
Rorikstr | Rust Dev 2025-09-26 14:11:45 +03:00
parent f8b74bf43d
commit 851d303aab
4 changed files with 187 additions and 37 deletions

View file

@ -9,41 +9,193 @@ static bool initialized = false;
const int (*get_figure_shape(FigureType type, int rotation))[4] {
static const int shapes[FIGURE_COUNT][4][4][4] = {
// I
{{{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}},
{{0, 0, 0, 0}, {0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
{{0, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}}},
// I
{
{
{0, 0, 0, 0},
{1, 1, 1, 1},
{0, 0, 0, 0},
{0, 0, 0, 0}
},
{
{0, 0, 1, 0},
{0, 0, 1, 0},
{0, 0, 1, 0},
{0, 0, 1, 0}
},
{
{0, 0, 0, 0},
{0, 0, 0, 0},
{1, 1, 1, 1},
{0, 0, 0, 0}
},
{
{0, 1, 0, 0},
{0, 1, 0, 0},
{0, 1, 0, 0},
{0, 1, 0, 0}
}
},
// O
{{{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}},
{{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}}},
{
{
{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}
},
{
{0, 1, 1, 0},
{0, 1, 1, 0},
{0, 0, 0, 0},
{0, 0, 0, 0}
},
{
{0, 1, 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, {0, 0, 0, 0}}}};
{
{
{1, 1, 0, 0},
{0, 1, 1, 0},
{0, 0, 0, 0},
{0, 0, 0, 0}
},
{
{0, 0, 1, 0},
{0, 1, 1, 0},
{0, 1, 0, 0},
{0, 0, 0, 0}
},
{
{1, 1, 0, 0},
{0, 1, 1, 0},
{0, 0, 0, 0},
{0, 0, 0, 0}
},
{
{0, 0, 1, 0},
{0, 1, 1, 0},
{0, 1, 0, 0},
{0, 0, 0, 0}
}
}
};
return shapes[type][rotation];
}
@ -53,7 +205,7 @@ void user_input(UserAction_t action) {
initialized = true;
}
if (action >= Figure1 && action <= Figure7) {
if ( Figure1 <= action && action <= Figure7) {
FigureType type = (FigureType)(action - Figure1);
game_state.current_figure.type = type;
game_state.current_figure.x = FIELD_WIDTH / 2 - 2;

View file

@ -57,7 +57,7 @@ typedef enum {
// Основные функции библиотеки
void user_input(UserAction_t action);
GameStateData* getGameState(void);
GameStateData* get_game_state(void);
const int (*get_figure_shape(FigureType type, int rotation))[4];

View file

@ -5,7 +5,7 @@
void display_game() {
clear();
GameStateData* state = getGameState();
GameStateData* state = get_game_state();
// Очистка поля
for (int i = 0; i < FIELD_HEIGHT; i++) {

View file

@ -18,10 +18,10 @@ int main() {
int ch;
bool hold = false;
while (1) {
UserAction_t action = Undefined;
while (!Terminate) {
ch = getch();
UserAction_t action = Undefined;
switch (ch) {
case 'q': action = Terminate; break;
@ -43,8 +43,6 @@ int main() {
}
display_game();
if (action == Terminate) break;
}
endwin();