resize windows for multiplayer
authorLaurent Mazet <mazet@softndesign.org>
Tue, 30 Jul 2024 05:18:09 +0000 (07:18 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Tue, 30 Jul 2024 05:18:09 +0000 (07:18 +0200)
tetris.c

index 839293adcaaefda467a47cb3aac69c4338de6931..934bf83507d0e13b718ee28654ffb6f61ff9d183 100644 (file)
--- a/tetris.c
+++ b/tetris.c
@@ -24,6 +24,7 @@ char *version = "1.2";
 
 int chrono = 0;
 char *filename = NULL;
+int multi = 0;
 int scale = 1;
 
 int height = 20;
@@ -58,6 +59,7 @@ int usage (int ret)
     fprintf (fd, " -c: time penalty (%s)\n", (chrono) ? "yes" : "no" );
     fprintf (fd, " -f: file name (%s)\n", (filename) ? filename : "none");
     fprintf (fd, " -h: help message\n");
+    fprintf (fd, " -m: multi players (%s)", (multi) ? "yes" : "no" );
     fprintf (fd, " -s: scale [0..3] (%d)\n", scale);
     fprintf (fd, " -v: verbose level (%d)\n", verbose);
     fprintf (fd, " -w: board width  [%d, %d] (%d)\n", minwidth, maxwidth, width);
@@ -138,6 +140,11 @@ int main (int argc, char *argv[])
                 return usage (1);
             }
             filename = arg;
+            multi = 0;
+            break;
+        case 'm':
+            multi = 1;
+            filename = NULL;
             break;
         case 's':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
@@ -181,6 +188,7 @@ int main (int argc, char *argv[])
 
     /* init all variables */
     board_t *board = NULL;
+    board_t *board2 = NULL;
     int current = -1;
     int lines = 0;
     int next = -1;
@@ -205,8 +213,14 @@ int main (int argc, char *argv[])
         score = board->score;
     } else {
         board = initboard (width, height);
+        if (multi) {
+            board2 = initboard (width, height);
+        }
     }
     setscale (board, scale);
+    if (multi) {
+        setscale (board2, scale);
+    }
 
     /* get blocks */
     int nb_blocks = 0;
@@ -253,6 +267,14 @@ int main (int argc, char *argv[])
     int ymsg = max (yboard + xoffset + 1 + board->ysize, yhelp + lhelp + yoffset);
     int lmsg = xhelp - xmsg + strmaxlen (help, '\n');
 
+    /* resize windows for multiplayer */
+    if (board2) {
+        board2->xoffset = xhelp + strmaxlen (help, '\n') + xoffset + 1;
+        board2->yoffset = yboard;
+        nextblock->xoffset += (nbdigit + 1) / 2;
+        lmsg += xhelp - xmsg;
+    }
+
     /* event loop */
     int mode = -1;
     int settle = 0;
@@ -338,6 +360,9 @@ int main (int argc, char *argv[])
         }
 
         boardwindow (board, 0);
+        if (multi) {
+            boardwindow (board2, 0);
+        }
         scorewindow (xscore, yscore, nbdigit, score, (lines / 10) + 1);
         int newspeed = 10 + 4900 / (lines / 10 + 1);
         if (newspeed != speed) {