move drawblock function
authorLaurent Mazet <mazet@softndesign.org>
Wed, 31 Jul 2024 19:22:53 +0000 (21:22 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Wed, 31 Jul 2024 19:23:22 +0000 (21:23 +0200)
function.c
function.h
tetris.c

index 943dfb218a23aecc432135253555f06f6cb36069..5314ba4eadca0214d3f042ff85a2853e9657f54e 100644 (file)
@@ -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: */
index e9af8131c5df32ce3b231d23df330347f58872aa..310d2ab305c8af972ac326c92cca2678cb3061e7 100644 (file)
@@ -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__ */
 
index 7465c8afcbe185967d447538aecda10cdd75b6b7..756a73e6c9d1d2108d52cf5e4ad412f1b8ebc770 100644 (file)
--- 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[])
 {