"<s> Save file\n"
;
+static int computetempo (int lines)
+{
+ return 20 + 200 / (lines / 10 + 1);
+}
+
/* main function for one player*/
int oneplayer (int width, int height, int scale, int chrono, char *filename)
{
if (settle) {
settleblock (board, cblock, xblock, yblock);
- }
- int nblines = checkline (board, &score, &lines);
- if (nblines) {
- while (nblines-- > 0) {
- boardwindow (board, 0);
- stackboard (board);
- msleep (20 + 200 / (lines / 10 + 1));
- refresh ();
- }
- if (chrono) {
+ int nblines = checkline (board, &score, &lines);
+ removelines (board, nblines, computetempo (lines));
+ if (nblines && chrono) {
setendtime (&lineend, chronoratio * speed);
}
- } else if (chrono && lineend.tv_sec && isovertime (&lineend)) {
+ }
+ if (chrono && lineend.tv_sec && isovertime (&lineend)) {
if (!testvalidpos (board, cblock, xblock, yblock + 1)) {
settleblock (board, cblock, xblock, yblock);
+ int nblines = checkline (board, &score, &lines);
+ removelines (board, nblines, computetempo (lines));
settle = 1;
}
int isempty = addline (board, nbholes);
"<escape> Quit\n"
;
+static int computetempo (int lines)
+{
+ return 20 + 200 / (lines / 20 + 1);
+}
+
+static int computepenalty (int nblines)
+{
+ return (nblines == 4) ? 4 : (nblines > 1) ? nblines - 1 : 0;
+}
+
/* main function for two players */
int twoplayers (int width, int height, int scale)
{
break;
case 1:
halfdelay (1);
+
boardwindow (nextblock, 1);
displayblock (nextblock, blocks + next, -1, -1);
+
+ int penalty_left = 0;
+ int penalty_right = 0;
+
+ /* check timeout */
if (blockend_left.tv_sec && isovertime (&blockend_left)) {
if (testvalidpos (board_left, cblock_left, xblock_left, yblock_left + 1)) {
yblock_left++;
/* Player one */
if (settle_left) {
settleblock (board_left, cblock_left, xblock_left, yblock_left);
- }
- int nblines_left = checkline (board_left, &score_left, &lines);
- if (nblines_left) {
- while (nblines_left-- > 0) {
- boardwindow (board_left, 0);
- stackboard (board_left);
- msleep (20 + 200 / (lines / 20 + 1));
- refresh ();
- }
- }
- if (settle_left) {
+ int nblines_left = checkline (board_left, &score_left, &lines);
+ penalty_right = computepenalty (nblines_left);
+ removelines (board_left, nblines_left, computetempo (lines));
if (!testvalidpos (board_left, blocks + next , board_left->width / 2, 0)) {
sprintf (msg, "To bad, player One looses. Score is %d / %d", score_left, score_right);
mode = 2;
/* Player two */
if (settle_right) {
settleblock (board_right, cblock_right, xblock_right, yblock_right);
- }
- int nblines_right = checkline (board_right, &score_right, &lines);
- if (nblines_right) {
- while (nblines_right-- > 0) {
- boardwindow (board_right, 0);
- stackboard (board_right);
- msleep (20 + 200 / (lines / 20 + 1));
- refresh ();
- }
- }
- if (settle_right) {
+ int nblines_right = checkline (board_right, &score_right, &lines);
+ penalty_left = computepenalty (nblines_right);
+ removelines (board_right, nblines_right, computetempo (lines));
if (!testvalidpos (board_right, blocks + next , board_right->width / 2, 0)) {
sprintf (msg, "To bad, player Two looses. Score is %d / %d", score_left, score_right);
mode = 2;
settle_right = 0;
}
+ /* Penalty */
+ while ((penalty_left > 0) || (penalty_right > 0)) {
+
+ /* Player one */
+ if (penalty_left) {
+ if (!testvalidpos (board_left, cblock_left, xblock_left, yblock_left + 1)) {
+ settleblock (board_left, cblock_left, xblock_left, yblock_left);
+ int nblines_left = checkline (board_left, &score_left, &lines);
+ penalty_right += computepenalty (nblines_left);
+ removelines (board_left, nblines_left, computetempo (lines));
+ if (!testvalidpos (board_left, blocks + next , board_left->width / 2, 0)) {
+ sprintf (msg, "To bad, player One looses. Score is %d / %d", score_right, score_left);
+ mode = 2;
+ } else {
+ cblock_left = drawblock (board_left, blocks, nb_blocks, cblock_left, ¤t_left, &xblock_left, &yblock_left, &next);
+ boardwindow (nextblock, 1);
+ displayblock (nextblock, blocks + next, -1, -1);
+ }
+ }
+ int isempty = addline (board_left, nbholes);
+ if (!isempty) {
+ sprintf (msg, "Shame, player One looses. Score is %d / %d", score_right, score_left);
+ mode = 2;
+ }
+ penalty_left--;
+ }
+
+ /* Player two */
+ if (penalty_right) {
+ if (!testvalidpos (board_right, cblock_right, xblock_right, yblock_right + 1)) {
+ settleblock (board_right, cblock_right, xblock_right, yblock_right);
+ int nblines_right = checkline (board_right, &score_right, &lines);
+ penalty_left += computepenalty (nblines_right);
+ removelines (board_right, nblines_right, computetempo (lines));
+ if (!testvalidpos (board_right, blocks + next , board_right->width / 2, 0)) {
+ sprintf (msg, "To bad, player Two looses. Score is %d / %d", score_left, score_right);
+ mode = 2;
+ } else {
+ cblock_right = drawblock (board_right, blocks, nb_blocks, cblock_right, ¤t_right, &xblock_right, &yblock_right, &next);
+ boardwindow (nextblock, 1);
+ displayblock (nextblock, blocks + next, -1, -1);
+ }
+ }
+ int isempty = addline (board_right, nbholes);
+ if (!isempty) {
+ sprintf (msg, "Shame, player Two looses. Score is %d / %d", score_left, score_right);
+ mode = 2;
+ }
+ penalty_right--;
+ }
+ }
+
break;
case 2:
freeblock (cblock_left);