Esempio n. 1
0
void movedown()
{
  if(gblock[2].y < 16)
  {
    if(tiles[gblock[2].y+1][gblock[2].x].color != BLACK)
    {
      tiles[gblock[2].y][gblock[2].x].copyblock(&gblock[2]);
      tiles[gblock[1].y][gblock[1].x].copyblock(&gblock[1]);
      tiles[gblock[0].y][gblock[0].x].copyblock(&gblock[0]);
      if(gblock[2].y < 3)
      {
        clearboard();
        printf("game over\nyour score: %i\n", score);
      }
      else
      releaseblock();
      
    }  
    else
    {
      gblock[0].y++;
      gblock[1].y++;
      gblock[2].y++;
    }
  }
  else
  {
    tiles[gblock[2].y][gblock[2].x].copyblock(&gblock[2]);
    tiles[gblock[1].y][gblock[1].x].copyblock(&gblock[1]);
    tiles[gblock[0].y][gblock[0].x].copyblock(&gblock[0]);
    releaseblock();
  }
}
Esempio n. 2
0
void cmd_edit(char *s)
{
#if 0
    char str[80];
    int color = WHITE;

    board->flags = 0;

    for(;;)
    {
	fgets(str, 80, stdin);
	if (!strcmp(str,"#\n"))
	    clearboard();
	else if (!strcmp(str, ".\n"))
	    break;
	else if (!strcmp(str, "c\n"))
	    color=opp(color);
	else if (!strcmp(str, "C\n"))
	    color=opp(color);
	else
	{
	    int f, r;
	    chesspiece p;
	    f = str[1]-'a';
	    r = str[2]-'1';
	    p = lookup(str[0]);
	    if (color==WHITE) p &= ~(1);
	    else p |= 1;
	    setpiece(f,r,p);
	}
    }

    countmaterial();

    /* set up castling rights */
    if ((board->kings[WHITE]==E1)&&(getpiece__(H1)==WROOK))
	board->flags |= wkc;
    if ((board->kings[WHITE]==E1)&&(getpiece__(A1)==WROOK))
	board->flags |= wqc;
    if ((board->kings[BLACK]==E8)&&(getpiece__(H8)==BROOK))
	board->flags |= bkc;
    if ((board->kings[BLACK]==E8)&&(getpiece__(A8)==BROOK))
	board->flags |= bqc;

    compute_hash();
#endif
}
Esempio n. 3
0
void init() {
	pos.row = 1;
	pos.col = 6;
	clearboard();
}
Esempio n. 4
0
static void game(void) {
    char c;
    int counter = sspeed, rs, a, blocks = 0, paused = 0;

    gamescreen();
    clearboard();

    nexts = rnd()%28;
    nextc = rnd()%7 + 1;
    newshape();
    score = view = 0;
    if (view) drawview(nexts, nextc);
    level = 1;
    speed = sspeed;
    printscore();
    printlevel();

    for(;;) {
        if (paused) {
            gametick();
            c = tgetchar();
            switch(c) {
            case 'q':
                goto stopgame;
            case 'p':
                paused = 0;
                moveto(68,5); setbg(black);
                printf("           ");
                normal();
                flush();
            default:
                break;
            }
            continue;
        }

        if (counter <= 0) {
            counter = 14 - speed;
            if (shapefits(current.s, current.x, current.y+1)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.y++;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                                current.y-3);
            } else {
                markboard(current.s, current.color, current.x, current.y);
                checkboard(current.y);
                incrscore(1);
                newshape();
                if (!shapefits(current.s, current.x, current.y)) goto stopgame;
                blocks++;
                if (blocks == blocksperlevel) {
                    blocks = 0;
                    incrlevel(1);
                }
                if (view) drawview(nexts, nextc);
            }
        }
        counter--;

        moveto(1,24);
        flush();
        gametick();
        c = tgetchar();
        switch(c) {
        case 'q':
            goto stopgame;
        case 'j':
            if (shapefits(current.s, current.x-1, current.y)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.x--;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                              current.y-3);
            }
            break;
        case 'l':
            if (shapefits(current.s, current.x+1, current.y)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.x++;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                              current.y-3);
            }
            break;
        case 'k':
            rs = (current.s & ~0x03) | ((current.s + 1) & 0x03);
            if (shapefits(rs, current.x, current.y)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.s = rs;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                              current.y-3);
            }
            break;
        case ' ':
            for (a=1; ; a++) {
                if (!shapefits(current.s, current.x, current.y+a))
                    break;
            }
            if (shapefits(current.s, current.x, current.y+a-1)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.y += a-1;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                              current.y-3);
            }
            incrscore(view ? (a-1) * 3 / 4 : a-1);
            break;
        case 'n':
            view ^= 1;
            if (view) drawview(nexts, nextc);
            else clearview();
            break;
        case 'p':
            paused = 1;
            moveto(68,5); setfg(white); setbg(blue);
            printf(" PAUSED!!! ");
            moveto(1,24);
            flush();
        default:
            break;
        }
    }

stopgame:
    setbg(white);
    rect(20,8,60,12);
    setbg(red);
    frect(21,9,59,11);
    setfg(white);
    bold();
    moveto(30,10);
    printf(" G A M E    O V E R ");
    moveto(1,24);
    flush();

    for(;;) {
        c = tgetchar();
        if (c > 0) return;
    }
}