| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1439 人关注过本帖
标题:俄罗斯方块消除满格问题,消除一行后出了问题
只看楼主 加入收藏
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
结帖率:82.35%
收藏
已结贴  问题点数:5 回复次数:6 
俄罗斯方块消除满格问题,消除一行后出了问题
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define S1 60  //初始位置(S1,S1)
#define S2 20  //单位大小
#define M 18  //宽度多少单位
#define N 23  //高度多少单位
#define Width 600
#define Henght 700
IMAGE img,img1,img2,img3,img4,img5,img6,img7,img8,img9,img10,img11;
int b,f,p,q,q2,number,count1,count2,count3,c[5],d[5],cc[5],dd[5];
int Time=15;
int number2=0;
int count4=0;
int get=0;


struct Barrier
{
    int x;
    int y;
    IMAGE z;
}barrier[M+1][N+1],barrier2[M+1][N+1],coor1;
typedef struct Barrier coor;

//顺时针旋转90度函数

coor rotate(int x,int y,int x0,int y0)
{
    int x1,y1;
    x1=y0-y+x0;
    y1=x-x0+y0;
    coor1.x=x1;
    coor1.y=y1;
    return coor1;
}
void rotate2()
{
    for (b=0;b<4;b++)
    {
        c[b]=c[b]+S2*1/2;d[b]=d[b]+S2*1/2;
        rotate(c[b],d[b],c[4],d[4]);
        c[b]=coor1.x-S2*1/2;
        d[b]=coor1.y-S2*1/2;
    }
}

//左移右移函数
void  Move(int i)
{
    for (b=0;b<5;b++)
        c[b]=c[b]+S2*i;
}
//恢复变换前坐标的函数
void Restore()
{
    for (b=0;b<5;b++)
    {
        c[b]=cc[b];
        d[b]=dd[b];
    }
}
//判断旋转或左移或右移后是否重叠
void room()
{
    count2=0;
    for (b=0;b<4;b++)
        for (f=0;f<2;f++)
        {
            p=c[b];q=d[b]-(d[b]-S1)%S2+S2*f;
            if (barrier[(p-S1)/S2][(q-S1)/S2].x==p && barrier[(p-S1)/S2][(q-S1)/S2].y==q)
                count2++;
        }
    if (count2!=0)
        count1--;
}

//初始化图形函数

void Ding()
{
    c[0]=S1+9*S2;     d[0]=S1+S2;
    c[1]=c[0];         d[1]=d[0]+S2;
    c[2]=c[1];         d[2]=d[1]+S2;
    c[3]=c[1]+S2;     d[3]=d[1];
    c[4]=c[1]+(1.0/2)*S2;d[4]=d[1]+(1.0/2)*S2;
}
void RightL()
{
    c[0]=S1+9*S2;     d[0]=S1+S2;
    c[1]=c[0]+S2;     d[1]=d[0];
    c[2]=c[1];         d[2]=d[1]+S2;
    c[3]=c[1];         d[3]=d[2]+S2;
    c[4]=c[0]+S2*1.0/2;d[4]=d[0]+(3.0/2)*S2;
}
void LeftL()
{
    c[0]=S1+8*S2;     d[0]=S1+S2;
    c[1]=c[0];         d[1]=d[0]+S2;
    c[2]=c[0];         d[2]=d[1]+S2;
    c[3]=c[0]+S2;     d[3]=d[0];
    c[4]=c[0]+(3.0/2)*S2;d[4]=d[0]+(3.0/2)*S2;
}
void LeftZ()
{
    c[0]=S1+10*S2;   d[0]=S1+S2;
    c[1]=c[0];       d[1]=d[0]+S2;
    c[2]=c[0]-S2;    d[2]=d[1];
    c[3]=c[2];       d[3]=d[2]+S2;
    c[4]=c[2]+(1.0/2)*S2;d[4]=d[2]+(1.0/2)*S2;
}
void RightZ()
{
    c[0]=S1+8*S2;     d[0]=S1+S2;
    c[1]=c[0];         d[1]=d[0]+S2;
    c[2]=c[1]+S2;     d[2]=d[1];
    c[3]=c[2];         d[3]=d[2]+S2;
    c[4]=c[2]+(1.0/2)*S2;d[4]=d[2]+(1.0/2)*S2;
}
void Square()
{
    c[0]=S1+8*S2;     d[0]=S1+S2;
    c[1]=c[0]+S2;     d[1]=d[0];
    c[2]=c[0];         d[2]=d[0]+S2;
    c[3]=c[1];         d[3]=d[2];
}
void Yi()
{
    c[0]=S1+7*S2;d[0]=S1+S2;
    c[1]=c[0]+S2;d[1]=d[0];
    c[2]=c[1]+S2;d[2]=d[1];
    c[3]=c[2]+S2;d[3]=d[2];
   
}

//画边框

void Region()
{
    IMAGE img1;
    IMAGE img2;
    initgraph(Width,Henght);
    setbkcolor(GREEN);
    cleardevice();
    loadimage(&img3,"D:\\C共享\\俄罗斯方块\\images\\GameRegionRim2.jpg");
    putimage(S1,S1,&img3);
    getimage(&img3,S1,S1,S2,S2);
    loadimage(&img4,"D:\\C共享\\俄罗斯方块\\images\\square_blue.jpg");
    putimage(S1,S1,&img4);
    getimage(&img4,S1,S1,S2,S2);
    loadimage(&img5,"D:\\C共享\\俄罗斯方块\\images\\square_darkBlue.jpg");
    putimage(S1,S1,&img5);
    getimage(&img5,S1,S1,S2,S2);
    loadimage(&img6,"D:\\C共享\\俄罗斯方块\\images\\square_green.jpg");
    putimage(S1,S1,&img6);
    getimage(&img6,S1,S1,S2,S2);
    loadimage(&img7,"D:\\C共享\\俄罗斯方块\\images\\square_orange.jpg");
    putimage(S1,S1,&img7);
    getimage(&img7,S1,S1,S2,S2);
    loadimage(&img8,"D:\\C共享\\俄罗斯方块\\images\\square_purple.jpg");
    putimage(S1,S1,&img8);
    getimage(&img8,S1,S1,S2,S2);
    loadimage(&img9,"D:\\C共享\\俄罗斯方块\\images\\square_red.jpg");
    putimage(S1,S1,&img9);
    getimage(&img9,S1,S1,S2,S2);
    loadimage(&img10,"D:\\C共享\\俄罗斯方块\\images\\square_yellow.jpg");
    putimage(S1,S1,&img10);
    getimage(&img10,S1,S1,S2,S2);
    loadimage(&img2,"E:\\Image\\c.jpg",Width,Henght);
    putimage(0,0,&img2);
    getimage(&img,S1+S2,S1+S2,(M-1)*S2,(N-1)*S2);

    for (p=S1;p<S1+M*S2+1;p+=S2)
    {
        q=S1;
        putimage(p,q,&img3);
        barrier[(p-S1)/S2][(q-S1)/S2].x=p;
        barrier[(p-S1)/S2][(q-S1)/S2].y=q;
        q=S1+N*S2;
        putimage(p,q,&img3);
        barrier[(p-S1)/S2][(q-S1)/S2].x=p;
        barrier[(p-S1)/S2][(q-S1)/S2].y=q;
        
    }
    for (q=S1;q<S1+N*S2+1;q+=S2)
    {
        p=S1;
        putimage(p,q,&img3);
        barrier[(p-S1)/S2][(q-S1)/S2].x=p;
        barrier[(p-S1)/S2][(q-S1)/S2].y=q;
        p=S1+M*S2;
        putimage(p,q,&img3);
        barrier[(p-S1)/S2][(q-S1)/S2].x=p;
        barrier[(p-S1)/S2][(q-S1)/S2].y=q;
    }
    settextstyle(25, 0, _T("宋体"));
    outtextxy(20,600,_T("  Ver 1.0             Your Score :               Made By Yao"));
   
}

void RandNumber()
{
     number=(int)(rand()%7+4);
}


void Action()
{
    int a;
    char e;
    for (;;)
    {   
    count1=0;
    getimage(&img1,S1+S2,S1+S2,(M-1)*S2,(N-1)*S2);
    BeginBatchDraw();
    RandNumber();
    if (number==4)
    {img11=img4;    Yi();}   
    else if (number==5)
    {img11=img5;    LeftZ();    }  
    else if (number==6)
    {img11=img6;    Ding();     }
    else if (number==7)
    {img11=img7;    RightZ();     }
    else if (number==8)
    {img11=img8;    Square();}        
    else if (number==9)
    {img11=img9;    LeftL();}
    else
    {img11=img10;    RightL();  }

    for (a=0;;a++)
    {
        for (b=0;b<4;b++)
            putimage(c[b],d[b],&img11);
        if (kbhit())
        {
            e=getch();
            if (isascii(e))
                goto loop;
            else
loop:        e=getch();
            switch(e)
            {
                case 72:
                {
                    if (number==8)
                        goto loop2;
                    if (number==4)
                    {
                        count1++;
                        if (count1%2==1)
                        {
                            c[0]=c[0]+S2;d[0]=d[0]-S2;
                            c[1]=c[1];d[1]=d[1];
                            c[2]=c[2]-S2;d[2]=d[2]+S2;
                            c[3]=c[3]-2*S2;d[3]=d[3]+2*S2;
                        }
                        if (count1%2==0)
                        {
                            c[0]=c[0]-S2;d[0]=d[0]+S2;
                            c[1]=c[1];d[1]=d[1];
                            c[2]=c[2]+S2;d[2]=d[2]-S2;
                            c[3]=c[3]+2*S2;d[3]=d[3]-2*S2;
                        }
                    
                    }
                    else
                        rotate2();
                    room();
                    if (count2!=0)
                        Restore();
                    break;   
                }        
            case 75:
                {
                    Move(-1);
                    room();
                    if (count2!=0)
                        Restore();
                    break;
                }
            case 77:
                {
                    Move(1);
                    room();
                    if (count2!=0)
                        Restore();
                    break;
                }
            case 80:
                number2=20;
                break;
            }
            
        }
    //判断是否碰到下面的障碍物:
        if ((S2+a)%S2==0)
        {
            count2=0;
            for (b=0;b<4;b++)
            {
                p=c[b];q=d[b]+S2;
                if (barrier[(p-S1)/S2][(q-S1)/S2].x==p && barrier[(p-S1)/S2][(q-S1)/S2].y==q)
                {
                    for (f=0;f<4;f++)
                    {
                        p=c[f];q=d[f];
                        barrier[(p-S1)/S2][(q-S1)/S2].x=p;
                        barrier[(p-S1)/S2][(q-S1)/S2].y=q;
                        barrier[(p-S1)/S2][(q-S1)/S2].z=img11;
                    }
                    count2++;
                    break;
                }
               
            }
            if (count2!=0)
            break;
        }
loop2:        for (b=0;b<5;b++)
        {
            d[b]=d[b]+1;//
            cc[b]=c[b];//   切记 : 三者顺序不能颠倒
            dd[b]=d[b];//
            
        }
        FlushBatchDraw();
        if (number2>0)
            goto loop3;
        else
            Sleep(Time);
loop3:        number2--;
        putimage(S1+S2,S1+S2,&img1);
    }
    EndBatchDraw();

    //判断某一行是否填满

    for (q=1;q<N;q++)
    {
        count3=0;
        for (p=1;p<M;p++)
            if (barrier[p][q].x==S1+p*S2 && barrier[p][q].y==S1+q*S2)
                count3++;
        if (count3==M-1)
            break;
    }
    if (count3==M-1)
    {
        get=q-1;  //用来接收哪一行满了
        count4++;
        putimage(S1+S2,S1+S2,&img);
        for (p=1;p<M;p++)
            for (q=1;q<get;q++)
                if (barrier[p][q].x==S1+p*S2 && barrier[p][q].y==S1+q*S2)
                {
                    barrier2[p][q+1].x=S1+p*S2;
                    barrier2[p][q+1].y=S1+(q+1)*S2;
                    barrier2[p][q+1].z=barrier[p][q].z;
                    barrier[p][q].x=0;
                    barrier[p][q].y=0;
                }
        //擦除填满的一行
        for (p=1;p<M;p++)
        {
            barrier[p][get].x=0;
            barrier[p][get].x=0;
        }

        for (p=1;p<M;p++)
            for (q=1;q<get+1;q++)
                if (barrier2[p][q].x==S1+p*S2 && barrier2[p][q].y==S1+q*S2)
                {
                    barrier[p][q].x=barrier2[p][q].x;
                    barrier[p][q].y=barrier2[p][q].y;
                    barrier[p][q].z=barrier2[p][q].z;
                }
        for (p=1;p<M;p++)
            for (q=1;q<N;q++)
                putimage(barrier[p][q].x,barrier[p][q].y,&barrier[p][q].z);        
    }
    }   
}




void main()
{
    srand((unsigned)time(NULL));
    Region();
    Action();
    getch();
}
搜索更多相关主题的帖子: 俄罗斯方块 include number 
2014-05-04 23:24
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
收藏
得分:0 
想了好长时间,不知原因在哪,求大神指教,
2014-05-04 23:26
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
收藏
得分:0 
我觉得没有错 barrier数组明明有些方块的
2014-05-04 23:28
tremere
Rank: 6Rank: 6
来 自:火星
等 级:侠之大者
帖 子:223
专家分:432
注 册:2013-3-11
收藏
得分:4 

极品菜鸟,来学习啦,啦啦啦啦啦啦啦。。。
2014-05-05 08:35
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
收藏
得分:0 
我找出来了get=q,而不是q+1,但是除了这个错,还有错存在;
2014-05-05 10:09
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
收藏
得分:0 
打错了,q-1
2014-05-05 10:11
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
收藏
得分:0 
怎么删除这个帖子。必须结贴吗?
2014-05-05 13:19
快速回复:俄罗斯方块消除满格问题,消除一行后出了问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038350 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved