return board;
}
-board_t *copyboard (board_t *board)
-{
- board_t *newboard = initboard (board->width, board->height);
- char *tab = newboard->tab;
- memcpy (newboard, board, sizeof (board_t));
- newboard->tab = tab;
- memcpy (newboard->tab, board->tab, board->width * board->height + 1);
- return newboard;
-}
-
board_t *setscale (board_t *board, int scale)
{
board->scale = scale;
int l = sprintf (buffer, "width: %d\n", board->width);
l += sprintf (buffer + l, "height: %d\n", board->height);
l += sprintf (buffer + l, "tab: \"%s\"\n", board->tab);
- l += sprintf (buffer + l, "current: \"%d\"\n", board->current);
+ l += sprintf (buffer + l, "current: %d\n", board->current);
+ l += sprintf (buffer + l, "lines: %d\n", board->lines);
l += sprintf (buffer + l, "next: %d\n", board->next);
+ l += sprintf (buffer + l, "score: %d\n", board->score);
VERBOSE (INFO, _makecomments (buffer + l, board));
int height = 0;
char *tab = NULL;
int current = -1;
+ int lines = 0;
int next = -1;
+ int score = 0;
char *saveptr1, *saveptr2;
tab = atos (value);
} else if (strcmp (keyword, "current") == 0) {
current = atoi (value);
+ } else if (strcmp (keyword, "lines") == 0) {
+ lines = atoi (value);
} else if (strcmp (keyword, "next") == 0) {
next = atoi (value);
+ } else if (strcmp (keyword, "score") == 0) {
+ score = atoi (value);
} else if (strcmp (keyword, "rem") == 0) {
/* nothing to do with remark */
} else {
board = initboard (width, height);
memcpy (board->tab, tab, width * height);
board->current = current;
+ board->lines = lines;
board->next = next;
+ board->score = score;
}
return board;
return 1;
}
+ /* init all variables */
board_t *board = NULL;
+ int current = -1;
+ int lines = 0;
+ int next = -1;
+ int score = 0;
+
+ /* read file */
if (filename) {
char *buffer = readdata (filename);
if (buffer == NULL) {
VERBOSE (ERROR, fprintf (stderr, "incorrect file (%s)\n", filename));
return 1;
}
+ current = board->current;
+ lines = board->lines;
+ next = board->next;
+ score = board->score;
} else {
board = initboard (width, height);
}
board_t *nextblock = initboard (maxblockwidth (blocks, nb_blocks) + 2, maxblockheight (blocks, nb_blocks));
setscale (nextblock, scale);
+ /* init seed */
+ srand (time (NULL));
+
/* get first bloc */
- int current = rand () % nb_blocks;
+ if (current == -1) {
+ current = rand () % nb_blocks;
+ }
block_t *cblock = copyblock (blocks + current);
int xblock = board->width / 2;
int yblock = 0;
- int next = rand () % nb_blocks;
+ if (next == -1) {
+ next = rand () % nb_blocks;
+ }
VERBOSE (DEBUG, fprintf (stderr, "%d/%d: (%d, %d)\n", current, nb_blocks, xblock, yblock));
/* init curses window */
int lmsg = xhelp - xmsg + strmaxlen (help, '\n');
/* event loop */
- int level = 0;
int mode = -1;
- int score = 0;
int settle = 0;
int speed = 5000;
int stop = 0;
}
msgwindow (msg, xmsg, ymsg, lmsg);
- int nblines = checkline (board, &score, &level);
+ int nblines = checkline (board, &score, &lines);
while (nblines-- > 0) {
boardwindow (board, 0);
stackboard (board);
}
boardwindow (board, 0);
- scorewindow (xscore, yscore, nbdigit, score, (level / 10) + 1);
- int newspeed = 10 + 4900 / (level / 10 + 1);
+ scorewindow (xscore, yscore, nbdigit, score, (lines / 10) + 1);
+ int newspeed = 10 + 4900 / (lines / 10 + 1);
if (newspeed != speed) {
speed = newspeed;
setendtime (&tend, speed);
case 's':
savename = savewindow (savelen, xsave, ysave);
if (savename != NULL) {
+ board->current = current;
+ board->lines = lines;
+ board->next = next;
+ board->score = score;
char *ptr = saveboard (board);
if (writedata (savename, ptr)) {
VERBOSE (WARNING, printf ("issue writing Board\n"));
}
/* test: tetris.exe -f 2>&1 | grep 'no file' */
-/* test: tetris.exe -f tests/nofile.ttr 2>&1 | grep "can't read file" */
-/* test: tetris.exe -f tests/bogus.ttr 2>&1 | grep 'incorrect file' */
+/* test: tetris.exe -f nofile.ttr 2>&1 | grep "can't read file" */
+/* test: tetris.exe -f bogus.ttr 2>&1 | grep 'incorrect file' */
/* test: tetris.exe -h | grep usage */
/* 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 _ 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 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 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 */
/* vim: set ts=4 sw=4 et: */