return 20 + 200 / (lines / 20 + 1);
}
-static int computepenalty (int nblines)
+/*
+int reparenextturn (board_t *board, block_t **blocks, int nb_blocks, block_t **pblock, int *pcurrent, int *pxblock, int *pyblock, int *pnext, int player, int *scores, board_t *winblock)
{
- return (nblines == 4) ? 4 : (nblines > 1) ? nblines - 1 : 0;
+ char msg[128] = {0};
+ int mode = 1:
+ if (!testvalidpos (board, blocks + *pnext , boardwidth / 2, 0)) {
+ sprintf (msg, "To bad, player %s looses. Score is %d / %d", (player == 0) ? "One" : "Two", scores[0], scores[1]);
+ msgwindow (msg, xmsg, ymsg, lmsg);
+ mode = 2;
+ } else {
+ *pblock = drawblock (board, blocks, nb_blocks, *pblock, pcurrent, pxblock, pyblock, pnext);
+ boardwindow (winblock, 1);
+ displayblock (winblock, blocks + *pnext, -1, -1);
+ }
+ return mode;
}
+*/
/* main function for two players */
int twoplayers (int width, int height, int scale)
int current_right = -1;
int lines = 0;
int next = -1;
- int score_left = 0;
- int score_right = 0;
+ int scores[2] = {0, 0};
setscale (board_left, scale);
setscale (board_right, scale);
/* Player one */
if (settle_left) {
- 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));
+ penalty_right = processsettlement (board_left, cblock_left, xblock_left, yblock_left, scores + 0, &lines, 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);
+ sprintf (msg, "To bad, player One looses. Score is %d / %d", scores[0], scores[1]);
mode = 2;
} else {
cblock_left = drawblock (board_left, blocks, nb_blocks, cblock_left, ¤t_left, &xblock_left, &yblock_left, &next);
/* Player two */
if (settle_right) {
- 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));
+ penalty_left = processsettlement (board_right, cblock_right, xblock_right, yblock_right, scores + 1, &lines, 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);
+ sprintf (msg, "To bad, player Two looses. Score is %d / %d", scores[0], scores[1]);
mode = 2;
} else {
cblock_right = drawblock (board_right, blocks, nb_blocks, cblock_right, ¤t_right, &xblock_right, &yblock_right, &next);
/* 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));
+ penalty_right += processsettlement (board_left, cblock_left, xblock_left, yblock_left, scores + 0, &lines, 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);
+ sprintf (msg, "To bad, player One looses. Score is %d / %d", scores[1], scores[0]);
mode = 2;
} else {
cblock_left = drawblock (board_left, blocks, nb_blocks, cblock_left, ¤t_left, &xblock_left, &yblock_left, &next);
}
int isempty = addline (board_left, nbholes);
if (!isempty) {
- sprintf (msg, "Shame, player One looses. Score is %d / %d", score_right, score_left);
+ sprintf (msg, "Shame, player One looses. Score is %d / %d", scores[1], scores[0]);
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));
+ penalty_left += processsettlement (board_right, cblock_right, xblock_right, yblock_right, scores + 1, &lines, 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);
+ sprintf (msg, "To bad, player Two looses. Score is %d / %d", scores[0], scores[1]);
mode = 2;
} else {
cblock_right = drawblock (board_right, blocks, nb_blocks, cblock_right, ¤t_right, &xblock_right, &yblock_right, &next);
}
int isempty = addline (board_right, nbholes);
if (!isempty) {
- sprintf (msg, "Shame, player Two looses. Score is %d / %d", score_left, score_right);
+ sprintf (msg, "Shame, player Two looses. Score is %d / %d", scores[0], scores[1]);
mode = 2;
}
penalty_right--;
boardwindow (board_left, 0);
boardwindow (board_right, 0);
- scorewindow (xscore, yscore, nbdigit, score_left, score_right, (lines / 20) + 1);
+ scorewindow (xscore, yscore, nbdigit, scores[0], scores[1], (lines / 20) + 1);
int newspeed = 10 + 4900 / (lines / 20 + 1);
if (newspeed < speed) {
speed = newspeed;