Browse Source

struct games_state *rs,

z_createrawtransaction
jl777 5 years ago
parent
commit
a490812049
  1. 18
      src/cc/tetris.c

18
src/cc/tetris.c

@ -226,7 +226,7 @@ static void tg_move(tetris_game *obj, int direction)
/* /*
Send the falling tetris block to the bottom. Send the falling tetris block to the bottom.
*/ */
static void tg_down(tetris_game *obj) static void tg_down(struct games_state *rs,tetris_game *obj)
{ {
tg_remove(obj, obj->falling); tg_remove(obj, obj->falling);
while (tg_fits(obj, obj->falling)) { while (tg_fits(obj, obj->falling)) {
@ -234,7 +234,7 @@ static void tg_down(tetris_game *obj)
} }
obj->falling.loc.row--; obj->falling.loc.row--;
tg_put(obj, obj->falling); tg_put(obj, obj->falling);
tg_new_falling(obj); tg_new_falling(rs,obj);
} }
/* /*
@ -273,12 +273,12 @@ static void tg_rotate(tetris_game *obj, int direction)
/* /*
Swap the falling block with the block in the hold buffer. Swap the falling block with the block in the hold buffer.
*/ */
static void tg_hold(tetris_game *obj) static void tg_hold(struct games_state *rs,tetris_game *obj)
{ {
tg_remove(obj, obj->falling); tg_remove(obj, obj->falling);
if (obj->stored.typ == -1) { if (obj->stored.typ == -1) {
obj->stored = obj->falling; obj->stored = obj->falling;
tg_new_falling(obj); tg_new_falling(rs,obj);
} else { } else {
int typ = obj->falling.typ, ori = obj->falling.ori; int typ = obj->falling.typ, ori = obj->falling.ori;
obj->falling.typ = obj->stored.typ; obj->falling.typ = obj->stored.typ;
@ -431,7 +431,7 @@ bool tg_tick(struct games_state *rs,tetris_game *obj, tetris_move move)
return !tg_game_over(obj); return !tg_game_over(obj);
} }
void tg_init(tetris_game *obj, int rows, int cols) void tg_init(struct games_state *rs,tetris_game *obj, int rows, int cols)
{ {
// Initialization logic // Initialization logic
obj->rows = rows; obj->rows = rows;
@ -443,8 +443,8 @@ void tg_init(tetris_game *obj, int rows, int cols)
obj->ticks_till_gravity = GRAVITY_LEVEL[obj->level]; obj->ticks_till_gravity = GRAVITY_LEVEL[obj->level];
obj->lines_remaining = LINES_PER_LEVEL; obj->lines_remaining = LINES_PER_LEVEL;
//srand(time(NULL)); //srand(time(NULL));
tg_new_falling(obj); tg_new_falling(rs,obj);
tg_new_falling(obj); tg_new_falling(ts,obj);
obj->stored.typ = -1; obj->stored.typ = -1;
obj->stored.ori = 0; obj->stored.ori = 0;
obj->stored.loc.row = 0; obj->stored.loc.row = 0;
@ -452,10 +452,10 @@ void tg_init(tetris_game *obj, int rows, int cols)
printf("%d", obj->falling.loc.col); printf("%d", obj->falling.loc.col);
} }
tetris_game *tg_create(int rows, int cols) tetris_game *tg_create(struct games_state *rs,int rows, int cols)
{ {
tetris_game *obj = (tetris_game *)malloc(sizeof(tetris_game)); tetris_game *obj = (tetris_game *)malloc(sizeof(tetris_game));
tg_init(obj, rows, cols); tg_init(rs,obj, rows, cols);
return obj; return obj;
} }

Loading…
Cancel
Save