}
}
+void scorewindow (int xoffset, int yoffset, int length, int score, int level)
+{
+ set_color (black);
+ _dobound (length + 7, 2, xoffset, yoffset);
+ set_color (white);
+
+ char fmt[12], msg[32];
+ sprintf (fmt, "%% %dd", length);
+
+ sprintf (msg, "score: ");
+ sprintf (msg + strlen (msg), fmt, score);
+ mvaddstr (yoffset, xoffset, msg);
+
+ sprintf (msg, "level: % 3d", level);
+ mvaddstr (yoffset + 1, xoffset, msg);
+}
+
+void nextwindow (block_t *blocks, int nb, int xoffset, int yoffset, int next)
+{
+ int height = maxblockheight (blocks, nb);
+ int width = maxblockwidth (blocks, nb) + 2;
+
+ set_color (black);
+ _dobound (width, height, xoffset, yoffset);
+ set_color (white);
+
+ int i, j;
+ for (i = 0; i < width; i++) {
+ for (j = 0; j < height; j++) {
+ mvaddch (yoffset + j, xoffset + i, ' ');
+ }
+ }
+
+ block_t *block = blocks + next;
+ for (i = 0; i < block->width; i++) {
+ for (j = 0; j < block->height; j++) {
+ if (*getcell (block, i, j) == '.') {
+ _set_symb_color ('0' + block->color);
+ mvaddch (yoffset + (height - block->height) / 2 + j, xoffset + (width - block->width) / 2 + i, ' ');
+ set_color (white);
+ }
+ }
+ }
+}
+
void displayblock (board_t *board, block_t *block, int x, int y)
{
int i, j;
void boardwindow (board_t *board);
+void scorewindow (int xoffset, int yoffset, int length, int score, int level);
+
+void nextwindow (block_t *blocks, int nb, int xoffset, int yoffset, int next);
+
void displayblock (board_t *board, block_t *block, int x, int y);
char *savewindow (int length, int xoffset, int yoffset);
return newblock;
}
+int maxblockheight (block_t *blocks, int nb)
+{
+ int i;
+ int height = 0;
+ for (i = 0; i < nb; i++) {
+ if (height < (blocks + i)->height) {
+ height = (blocks + i)->height;
+ }
+ }
+ return height;
+}
+
+int maxblockwidth (block_t *blocks, int nb)
+{
+ int i;
+ int width = 0;
+ for (i = 0; i < nb; i++) {
+ if (width < (blocks + i)->width) {
+ width = (blocks + i)->width;
+ }
+ }
+ return width;
+}
+
void freeblock (block_t *block)
{
if (block) {
block_t *copyblock (block_t *block);
+int maxblockheight (block_t *blocks, int nb);
+
+int maxblockwidth (block_t *blocks, int nb);
+
void freeblock (block_t *block);
block_t *rotateblock (block_t *block, int rot);
int height = 20;
int width = 9;
+int nbdigit = 5;
+int maxscor = 100000;
+
int savelen = 12;
int xoffset = 1;
int yoffset = 1;
/* window positions */
int xboard = board->xoffset = xoffset + 1;
int yboard = board->yoffset = xoffset + 1;
- int xhelp = xboard + xoffset + 1 + board->xsize;
- int yhelp = yboard - 1;
+ int xscore = xboard + xoffset + 2 + board->xsize;
+ int yscore = yboard;
+ int xnext = xscore;
+ int ynext = yscore + xoffset + maxblockheight (blocks, nb_blocks);
+ int xhelp = xnext - 1;
+ int yhelp = ynext + 1 + maxblockheight (blocks, nb_blocks) + xoffset;
int xsave = max (xboard + (board->xsize - savelen) / 2, 1);
int ysave = yboard + (board->ysize - 1) / 2;
char *savename = NULL;
/* window positions */
int xmsg = xboard;
- int ymsg = max (yboard + xoffset + 1 + board->ysize, yhelp + lhelp + yoffset + 1);
+ int ymsg = max (yboard + xoffset + 1 + board->ysize, yhelp + lhelp + yoffset);
int lmsg = xhelp - xmsg + strmaxlen (help, '\n');
/* event loop */
+ int level = 1;
int mode = 0;
- int speed = 5000;
+ int score = 0;
int settle = 0;
+ int speed = 5000;
int stop = 0;
struct timeval tend = {0, 0};
while (!stop) {
switch (mode) {
case 0:
halfdelay (0);
+ nextwindow (blocks, nb_blocks, xnext, ynext, current);
sprintf (msg, "Get ready player One");
break;
case 1:
mode = 2;
sprintf (msg, "End of game");
}
+ nextwindow (blocks, nb_blocks, xnext, ynext, next);
break;
case 2:
freeblock (cblock);
msgwindow (msg, xmsg, ymsg, lmsg);
boardwindow (board);
+ scorewindow (xscore, yscore, nbdigit, score, level);
if (mode == 1) {
displayblock (board, cblock, xblock, yblock);
}