⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 game_russia.c

📁 一款在tc下可直接运行的俄罗斯方块小游戏
💻 C
📖 第 1 页 / 共 2 页
字号:
                setcolor(BLACK);
                line(21.4*16,17*16,23.9*16,17*16);
            }
            
            else
            {
                line(21.4*16,17*16,23.9*16,17*16);
                setcolor(BLACK);
                line(6*16,17*16,8.5*16,17*16);
            }
        }
        if(bioskey(1))
        {
            key=bioskey(0);
            if(key==UP||key==DOWN)
            {
                setcolor(BLACK);
                settextstyle(0,0,4);
                outtextxy(6.5*16,15*16,le);
                outtextxy(21.9*16,15*16,sp);
            }
            if(key==ENTER)
                break;
            else if(key==UP)
            {
                if(left==1)
                {
                    level--;
                    if(level==-1)
                        level=9;
                }
                else
                {
                    speed--;
                    if(speed==-1)
                        speed=9;
                }
            }
            else if(key==DOWN)
            {
                if(left==1)
                {
                    level++;
                    if(level==10)
                        level=0;
                    
                }
                else
                {
                    speed++;
                    if(speed==10)
                        speed=0;
                }
            }
            
            else if(key==LEFT||RIGHT)
                left*=-1;
            setcolor(YELLOW);
            sp[0]=speed+'0';
            le[0]=level+'0';
            settextstyle(0,0,4);
            outtextxy(6.5*16,15*16,le);
            outtextxy(21.9*16,15*16,sp);
        }
    }
    setcolor(YELLOW);
    sp[0]=speed+'0';
    le[0]=level+'0';
    settextstyle(0,0,4);
    outtextxy(6.5*16,15*16,le);
    outtextxy(21.9*16,15*16,sp);
    setcolor(BLACK);
    line(21.4*16,17*16,23.9*16,17*16);
    line(6*16,17*16,8.5*16,17*16);
    settextstyle(0,0,2);
    outtextxy(500,340,"PRESS");
    outtextxy(500,360,"ENTER");
    outtextxy(500,380," TO  ");
    outtextxy(500,400,"START");
}


void level_change(void)         /*根据高度随机确定方块是否存在*/
{
    int i,j;
    setcolor(WHITE);
    for(i=1;i<=10;i++)
        for(j=1;j<=level;j++)
            if(random(2))
            {
                board[i-1][20-j]=1;
                
                draw_little_block(i+MAPXOFT,21-j+MAPYOFT);
            }
}





void draw_block(int x,int y,int style,int way)
/*此x,y为虚拟坐标,为19中形式中的一种:0~18中的一个
x,y为10*20的方格的坐标,下标从1开始
way为1表填充,为0表清除*/
{
    int x1=x+MAPXOFT,y1=y+MAPYOFT;
    int i;
    if(way==1)
        setcolor(WHITE);
    else
        setcolor(BLACK);
    for(i=0;i<=6;i+=2)
        draw_little_block(x1+shapes[style].xy[i],y1+shapes[style].xy[i+1]);
    if(sign==1)
        sign=0;
}






void draw_little_block(int x,int y)/*此处仅在10*20的游戏版内画小方块,若在外,不画之。*/
{
    if((x>=10&&x<20&&y>=6&&y<26)||sign)
    {
        rectangle(x*16,y*16,x*16+16,y*16+16);
        circle(x*16+8,y*16+8,4);
    }
}


int check_block(int x,int y,int style)/*此处检查在(x,y)处放置一方块是否可以,若是,则返回1,否则返回0*/
{
    int x1=x+MAPXOFT,y1=y+MAPYOFT;
    int x2,y2,i;
    for(i=0;i<=6;i+=2)
    {
        x2=x1+shapes[style].xy[i];
        y2=y1+shapes[style].xy[i+1];
        if(x2>=10&&x2<20&&y2<26&&(y2<6||board[x2-10][y2-6]==0))
            continue;
        else
            break;
    }
    if(i==8)
        return 1;
    else
        return 0;
}

void speed_change(void)        /*此为变速函数,当分数超过一级时,即加一。*/
{
    if(score>=(sp[0]-'0')*100&&(sp[0]-'0')<9)
    {
        settextstyle(0,0,4);
        setcolor(BLACK);
        outtextxy(21.9*16,15*16,sp);
        sp[0]++;
        speed++;
        settextstyle(0,0,4);
        setcolor(YELLOW);
        outtextxy(21.9*16,15*16,sp);
    }
}

void score_change(int count)        /*count为消去的行数,据此来改变score的值*/
{
    int score_inc[4]={1,3,7,13};
    int i;
    
    setcolor(BLACK);
    settextstyle(0,0,3);
    outtextxy((MAPXOFT+21)*16,(MAPYOFT+6)*16,sc);/*此处将原有的分数盖掉*/
    
    score+=score_inc[count-1];
    sc[4]+=score_inc[count-1];
    for(i=4;i>=1;i--)
    {
        
        sc[i-1]+=(sc[i]-'0')/10;
        sc[i]-=(sc[i]-'0')/10*10;
    }
    setcolor(YELLOW);
    settextstyle(0,0,3);
    outtextxy((MAPXOFT+21)*16,(MAPYOFT+6)*16,sc);      /*输出新分数*/
}



void kill_line(int y)/*消去的函数,消去若干行并改变分数和速度*/
{
    int count=0,i,t=1,j,k;
    for(;y>=1&&t<=4;y--,t++)
    {
        for(i=1;i<=10;i++)
            if(!board[i-1][y-1])
                break;
            if(i==11)
            {
                count++;
                for(k=1;k<=10;k++)
                {
                    setcolor(BLACK);
                    draw_little_block(k+MAPXOFT,y+MAPYOFT);
                }
                for(j=y-1;j>=1;j--)
                    for(k=1;k<=10;k++)
                    {
                        board[k-1][j]=board[k-1][j-1];
                        if(board[k-1][j])
                        {
                            setcolor(BLACK);
                            draw_little_block(k+MAPXOFT,j+MAPYOFT);
                            setcolor(WHITE);
                            draw_little_block(k+MAPXOFT,j+1+MAPYOFT); 
                        }
                    }
                    renovate();
		    delay(1000);
                    y++;
            }
            
    }
    
    if(count>0)
    {
        
        setcolor(CYAN);
        settextstyle(0,0,3);
        outtextxy(500,370,"Good!");
        TimerCounter=0;
        while(1)
            if(TimerCounter>3)
            {
                TimerCounter=0;
                break;
            }
            
            setcolor(BLACK);
            settextstyle(0,0,3);
            outtextxy(500,370,"Good!");
            
            
            score_change(count);
            speed_change();
    }
}

void fill_board(int x,int y, int style) /*当一方块停止时,将中相应的值改为1*/
{
    
    int x1,y1,i;
    for(i=0;i<=6;i+=2)
    {
        x1=x+shapes[style].xy[i];
        y1=y+shapes[style].xy[i+1];
        board[x1-1][y1-1]=1;
    }
}

int change(int *i,int *j,int key)/*控制方块移动、变形的函数*/
{
    int key1;
    if(key==UP&&check_block(*i,*j,shapes[style].next))
    {
        draw_block(*i,*j,style,0);
        style=shapes[style].next;
        draw_block(*i,*j,style,1);
    }
    else if(key==LEFT&&check_block(*i-1,*j,style))
    {
        draw_block(*i,*j,style,0);
        (*i)--;
        draw_block(*i,*j,style,1);
    }
    else if(key==RIGHT&&check_block(*i+1,*j,style))
    {
        draw_block(*i,*j,style,0);
        (*i)++;
        draw_block(*i,*j,style,1);
    }
    else if(key==DOWN&&check_block(*i,*j+1,style))
    {
        draw_block(*i,*j,style,0);
        (*j)++;
        draw_block(*i,*j,style,1);
        speed0=9;
    }
    else if(key==ENTER)
    {
        while(1)
        {
            
            if(bioskey(1))
                key1=bioskey(0);
            if(key1==ENTER)
                break;
        }
    }
    else if(key==ESC)
        return 1;
    else if(key==21040)
          {
        sign=1;
        draw_block(MAPXOFT1,MAPYOFT1,style1,0);
        style1=16;
        sign=1;
        draw_block(MAPXOFT1,MAPYOFT1,style1,1);
    }
    return 0;
}


void renovate(void)    /*刷新屏幕*/
{
    int i,j;
    setcolor(WHITE);
    for(i=1;i<=10;i++)
        for(j=1;j<=20;j++)
            if(board[i-1][j-1]==1)
                draw_little_block(i+MAPXOFT,j+MAPYOFT);
            
            setcolor(YELLOW);
            rectangle(10*16,6*16,20*16,26*16);
            
            
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -