From b73fea560ba02f346773b9b0ee82bcf201105e8f Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Wed, 31 Jul 2024 21:22:53 +0200 Subject: [PATCH] move drawblock function --- function.c | 24 ++++++++++++++++++++++++ function.h | 4 +++- tetris.c | 24 ------------------------ 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/function.c b/function.c index 943dfb2..5314ba4 100644 --- a/function.c +++ b/function.c @@ -450,4 +450,28 @@ int addline (board_t *board, int nbholes) return isempty; } +block_t *drawblock (board_t *board, block_t *blocks, int nb_blocks, block_t *cblock, int *current, int *xblock, int *yblock, int *next) +{ + freeblock (cblock); + + /* if not restarting a saved game */ + if (cblock == NULL) { + if (*current == -1) { + *current = rand () % nb_blocks; + } + if (*next == -1) { + *next = rand () % nb_blocks; + } + } else { + *current = *next; + *next = rand () % nb_blocks; + } + + cblock = copyblock (blocks + *current); + *xblock = board->width / 2; + *yblock = 0; + + return cblock; +} + /* vim: set ts=4 sw=4 et: */ diff --git a/function.h b/function.h index e9af813..310d2ab 100644 --- a/function.h +++ b/function.h @@ -59,7 +59,9 @@ int checkline (board_t *board, int *score, int *lines); void stackboard (board_t *board); -int addline (board_t *board, int nbholes); +int addline (board_t *board, int nbholes); + +block_t *drawblock (board_t *board, block_t *blocks, int nb_blocks, block_t *cblock, int *current, int *xblock, int *yblock, int *next); #endif /* __FUNCTION_H__ */ diff --git a/tetris.c b/tetris.c index 7465c8a..756a73e 100644 --- a/tetris.c +++ b/tetris.c @@ -77,30 +77,6 @@ int usage (int ret) return ret; } -block_t *drawblock (board_t *board, block_t *blocks, int nb_blocks, block_t *cblock, int *current, int *xblock, int *yblock, int *next) -{ - freeblock (cblock); - - /* if not restarting a saved game */ - if (cblock == NULL) { - if (*current == -1) { - *current = rand () % nb_blocks; - } - if (*next == -1) { - *next = rand () % nb_blocks; - } - } else { - *current = *next; - *next = rand () % nb_blocks; - } - - cblock = copyblock (blocks + *current); - *xblock = board->width / 2; - *yblock = 0; - - return cblock; -} - /* main function */ int main (int argc, char *argv[]) { -- 2.30.2