it's working but should fix return issue

This commit is contained in:
Rorikstr | Rust Dev 2025-09-28 12:16:58 +03:00
parent 1911d23459
commit 9de308925c
7 changed files with 609 additions and 212 deletions

View file

@ -1,4 +1,64 @@
#include "tetris.h"
#include "game_logic.h"
#include <string.h>
const int (*get_figure_shape(FigureType type, int rotation))[4] {
const int (*result)[4] = NULL;
switch (type) {
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;
}
break;
case O:
result = o_fig();
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;
}
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;
}
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;
}
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;
}
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;
}
break;
default: result = NULL;
}
return result;
}
// I
const int (*i_fig_up())[4] {
@ -255,4 +315,14 @@ const int (*z_fig_left())[4] {
{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;
}