From: Laurent Mazet Date: Thu, 25 Jul 2024 20:33:53 +0000 (+0200) Subject: new option (width) and slide on line staking X-Git-Tag: v1.1~2 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=56757e646151e5c110d8f1a59bf33af5971878e4;p=tetris.git new option (width) and slide on line staking --- diff --git a/lines.ttr b/lines.ttr index 9d3e3d2..c76830c 100644 --- a/lines.ttr +++ b/lines.ttr @@ -1,7 +1,7 @@ width: 9 height: 20 tab: " 33 7 33334 7 33344 73344444 73355566 73332566 73332266 75333266 755533" -current: 2 +current: 3 lines: 3 -next: 5 +next: 0 score: 34 diff --git a/tetris.c b/tetris.c index c1b4d13..45085ec 100644 --- a/tetris.c +++ b/tetris.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "constant.h" #include "debug.h" @@ -25,7 +26,9 @@ char *filename = NULL; int scale = 1; int height = 20; -int width = 9; +int minwidth = 8; +int width = 10; +int maxwidth = 15; int nbdigit = 5; int maxscor = 100000; @@ -49,10 +52,11 @@ char *help = int usage (int ret) { FILE *fd = ret ? stderr : stdout; - fprintf (fd, "usage: %s [-f file] [-h] [-s int] [-v level]\n", progname); + fprintf (fd, "usage: %s [-f file] [-h] [-s int] [-v int] [-w int]\n", progname); fprintf (fd, " -f: file name (%s)\n", (filename) ? filename : "none"); 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); fprintf (fd, "%s version %s\n", progname, version); return ret; @@ -120,6 +124,14 @@ int main (int argc, char *argv[]) } verbose = atoi (arg); break; + case 'w': + arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; + if (arg == NULL) { + VERBOSE (ERROR, fprintf (stderr, "%s: no width specified\n", progname)); + return usage (1); + } + width = atoi (arg); + break; case 'h': default: return usage (c != 'h'); @@ -131,6 +143,10 @@ int main (int argc, char *argv[]) VERBOSE (ERROR, fprintf (stderr, "incorrect scale (%d)\n", scale)); return 1; } + if ((width < minwidth) || (width > maxwidth)) { + VERBOSE (ERROR, fprintf (stderr, "incorrect width (%d)\n", width)); + return 1; + } /* init all variables */ board_t *board = NULL; @@ -273,6 +289,8 @@ int main (int argc, char *argv[]) while (nblines-- > 0) { boardwindow (board, 0); stackboard (board); + usleep ((200 + 2000 / (lines / 10 + 1)) * 100); + refresh (); } boardwindow (board, 0); scorewindow (xscore, yscore, nbdigit, score, (lines / 10) + 1); @@ -400,17 +418,19 @@ int main (int argc, char *argv[]) /* test: tetris.exe -s 2>&1 | grep 'no scale' */ /* test: tetris.exe -s 4 2>&1 | grep incorrect */ /* test: tetris.exe -v 2>&1 | grep missing */ +/* test: tetris.exe -w 2>&1 | grep 'no width' */ +/* test: tetris.exe -w 6 2>&1 | grep incorrect */ /* test: tetris.exe _ 2>&1 | grep invalid */ /* test: { sleep 1; echo -n s; sleep 1; echo ouuljk; sleep 1; echo q; } | tetris.exe -s 0 */ /* test: { sleep 1; echo -n s; sleep 1; echo ouuljk; sleep 1; echo q; } | tetris.exe -s 1 */ /* test: { sleep 1; echo -n s; sleep 1; echo ouuljk; sleep 1; echo q; } | tetris.exe -s 2 */ /* test: { sleep 1; echo -n s; sleep 1; echo ouuljk; sleep 1; echo q; } | tetris.exe -s 3 */ /* test: { sleep 1; echo -n skkkkkkkkkkkkkkkkkk; sleep 6; echo -n kkkkkkkkkkkkkkkkk; sleep 1; echo q; } | tetris.exe */ -/* test: { sleep 1; echo -n s; sleep 1; echo oup; sleep 1; echo puljk; sleep 1; echo -ne 'sb.ttr\e'; sleep 1; echo -e 'sab\b.ttr'; sleep 1; echo q; } | tetris.exe -v 3 */ +/* test: { sleep 1; echo -n s; sleep 1; echo oup; sleep 1; echo puljk; sleep 1; echo -ne 'sb.ttr\e'; sleep 1; echo -e 'sab\b.ttr'; sleep 1; echo q; } | tetris.exe -w 9 -v 3 */ /* test: { sleep 1; echo -n s; sleep 1; echo q; } | tetris.exe -f a.ttr && rm a.ttr && test \! -f b.ttr */ -/* test: { echo -n s; sleep 1; echo ooolllk; sleep 1; echo uuukjjj; sleep 1; echo ooolllk; sleep 1; echo uuukjjj; sleep 1; echo ooolllk; sleep 1; echo uuukjjj; sleep 1; echo ooolllk; sleep 1; echo uuukjjj; sleep 1; echo cccc; sleep 1; echo q; } | tetris.exe */ -/* test: { echo -n s; sleep 1; echo lllololo; sleep 1; echo jjjujuju; sleep 1; echo lllololo; sleep 1; echo jjjujuju; sleep 1; echo q; } | tetris.exe */ +/* test: { echo -n s; sleep 1; echo ooollllk; sleep 1; echo uuukjjjj; sleep 1; echo ooollllk; sleep 1; echo uuukjjjj; sleep 1; echo ooollllk; sleep 1; echo uuukjjjj; sleep 1; echo ooollllk; sleep 1; echo uuukjjjj; sleep 1; echo cccc; sleep 1; echo q; } | tetris.exe -w 9 */ +/* test: { echo -n s; sleep 1; echo lllololo; sleep 1; echo jjjujuju; sleep 1; echo lllololo; sleep 1; echo jjjujuju; sleep 1; echo q; } | tetris.exe -w 9*/ /* test: { echo -n s; sleep 1; echo ccccccccccccc; sleep 1; echo q; } | tetris.exe */ -/* test: { echo -n s; sleep 1; echo -n jjuuc; sleep 1; echo -n jjc; sleep 1; echo q; } | tetris.exe -f lines.ttr */ +/* test: { echo -n s; sleep 1; echo -n jjuuuc; sleep 1; echo -n jjoc; sleep 1; echo q; } | tetris.exe -f lines.ttr */ /* vim: set ts=4 sw=4 et: */