| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1088 人关注过本帖
标题:俄罗斯方块编程的方块变形边界问题,求各位大佬
只看楼主 加入收藏
我是小白123
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-8-23
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
俄罗斯方块编程的方块变形边界问题,求各位大佬
#include <stdio.h>
#include <graphics.h>
#include <conio.h>

#define DOWN (0X8000+72)
#define SHANG (0X8000+80)
#define KEY_ENT 13
#define LEFT (0X8000+75)
#define RINT (0X8000+77)


IMAGE img;
IMAGE GAME;
void elsfklp(struct block *lp);
void elsfklp(struct block *lp);

int getkey()
{
    int ch = getch();
    if (ch==224)
    {
        return 0x8000+getch();
    }
    else if (ch==0)
    {
        return 0x4000+getch();
    }
    return ch;
}
int cloler[]={BLACK,YELLOW,RED};
char game[7][4][4][4]=
{
    //正L
    0,1,0,0,
    0,1,0,0,
    0,1,1,0,
    0,0,0,0,

    0,0,0,0,
    0,1,1,1,
    0,1,0,0,
    0,0,0,0,

    0,0,0,0,
    0,1,1,0,
    0,0,1,0,
    0,0,1,0,

    0,0,0,0,
    0,0,0,1,
    0,1,1,1,
    0,0,0,0,

    //反L
    0,0,1,0,
    0,0,1,0,
    0,1,1,0,
    0,0,0,0,
   
    0,0,0,0,
    0,1,0,0,
    0,1,1,1,
    0,0,0,0,
   
    0,0,0,0,
    0,1,1,0,
    0,1,0,0,
    0,1,0,0,
   
    0,0,0,0,
    0,1,1,1,
    0,0,0,1,
    0,0,0,0,

    //田
    0,0,0,0,
    0,1,1,0,
    0,1,1,0,
    0,0,0,0,
   
    0,0,0,0,
    0,1,1,0,
    0,1,1,0,
    0,0,0,0,

    0,0,0,0,
    0,1,1,0,
    0,1,1,0,
    0,0,0,0,

    0,0,0,0,
    0,1,1,0,
    0,1,1,0,
    0,0,0,0,
  //T

    0,0,0,0,
    0,0,1,0,
    0,1,1,1,
    0,0,0,0,
        
    0,0,0,0,
    0,0,1,0,
    0,0,1,1,
    0,0,1,0,
        
    0,0,0,0,
    0,1,1,1,
    0,0,1,0,
    0,0,0,0,
        
    0,0,0,0,
    0,0,1,0,
    0,1,1,0,
    0,0,1,0,
   
    //一

    0,0,0,0,
    0,0,1,0,
    0,0,1,0,
    0,0,1,0,
   
    0,0,0,0,
    0,0,0,0,
    0,1,1,1,
    0,0,0,0,
   
    0,0,0,0,
    0,0,1,0,
    0,0,1,0,
    0,0,1,0,
   
    0,0,0,0,
    0,0,0,0,
    0,1,1,1,
    0,0,0,0,

    //h

    0,0,0,0,
    0,0,1,0,
    0,0,1,1,
    0,0,0,1,
   
    0,0,0,0,
    0,0,1,1,
    0,1,1,0,
    0,0,0,0,
   
    0,0,0,0,
    0,0,1,0,
    0,0,1,1,
    0,0,0,1,
   
    0,0,0,0,
    0,1,1,0,
    0,1,1,0,
    0,0,0,0,

    //反h

    0,0,0,0,
    0,0,1,0,
    0,1,1,0,
    0,1,0,0,
   
    0,0,0,0,
    0,1,1,0,
    0,0,1,1,
    0,0,0,0,
   
    0,0,1,0,
    0,1,1,0,
    0,1,0,0,
    0,0,0,0,
   
    0,1,1,0,
    0,0,1,1,
    0,0,0,0,
    0,0,0,0,

};


struct block
{
    int x;//x坐标
    int y;//y坐标
    int tyle;//类型
    int bian;//方向
    int cloler1;//颜色
};


int  border(struct block *lp,int x,int y)
{
    int i,j;
    for (i=0;i<4;i++)
    {
        for (j=0;j<4;j++)
        {
            if (game[lp->tyle][lp->bian][i][j])
            {
                if (lp->x+j+x<0 || lp->x+j+x>=20 || lp->y+i+x>=19)
                {
                    return 0;
                }
            }
        }
    }
    return 1;
}
void inti(void)
{
    struct block lp;
    lp.x=5;
    lp.y=5;
    lp.tyle=0;
    lp.bian=0;
    lp.cloler1=3;
    int ch;
    initgraph(700,500);
    loadimage(&GAME,"456.jpg",700,500,true);
    BeginBatchDraw();
    while(1)
    {
        putimage(0,0,&GAME);
        fillrectangle(10,10,410,410);
    /*    bar(100,100,200,200);*/
        elsfklp(&lp);
        FlushBatchDraw();
        ch=getkey();
        switch(ch)
        {
        case DOWN:
            lp.bian++;
            break;
        case SHANG:
            if (border(&lp,0,1))
            {
                lp.y++;
            }   
            break;
        case LEFT:
            if (border(&lp,-1,0))
            {
                lp.x--;
            }
            break;
        case RINT:
            if (border(&lp,1,0))
            {
                lp.x++;
            }
            break;
        }
    }

    EndBatchDraw();
    closegraph();
}


void elsfklp(struct block *lp)
{
    int i,j;
    setcolor(cloler[lp->cloler1]);
    for (i=0;i<4;i++)
    {
        for (j=0;j<4;j++)
        {
            if (game[lp->tyle][lp->bian][j][i])
            {
                    bar3d(10+(lp->x+i)*20+1,10+(lp->y+j)*20+1,10+(lp->x+i+1)*20-1,10+(lp->y+j+1)*20-1,2,true);            
            }
        }
    }
}
int tupian()
{
    IMAGE img;
    int x=50;
    int ch;
    int i;
    int pos=0;
    char game[][30]={"开始游戏","继续游戏","帮助","设置","结束游戏"};
    MOUSEMSG mlous;
   
    int point[]={200,200,150,250,250,200,200};
    loadimage(&img,"123.jpg",700,500,true);
    BeginBatchDraw();
   
    while(1)
    {
        putimage(0,0,&img);
        settextstyle(50,20,"华文行楷");
        for (i=0;i<5;i++)
        {   
            setcolor(GREEN);
            if (pos==i)
            {
                setbkmode(OPAQUE);
            }
            else
            {
                setbkmode(TRANSPARENT);
            }
            outtextxy(x,50+50*i,game[i]);
        }
        FlushBatchDraw();
        ch=getkey();
        switch(ch)
        {
        case SHANG:
            if (pos<4)
            {
                pos++;
            }            
            break;
        case DOWN:
            if (pos>0)
            {
                pos--;
            }
        case KEY_ENT:
            EndBatchDraw();
            inti();
            break;
        }
        
    }
   
    while(1)
    {
        mlous=GetMouseMsg();
        switch(mlous.uMsg)
        {
        case WM_LBUTTONDOWN:
            
            break;
        }
        //     
        //         
    }
        closegraph();
    return 0;
}
int main()
{

//     while(1)
//     {
//        int ch;
//         ch=getch();
//         printf("%d",ch);        
//     }
    initgraph(700,500);
    tupian();
    return 0;
}
搜索更多相关主题的帖子: int struct return case break 
2018-08-23 14:24
no1xijin
Rank: 9Rank: 9Rank: 9
来 自:江西
等 级:贵宾
威 望:20
帖 子:211
专家分:1207
注 册:2015-7-8
收藏
得分:20 
百度一下看看

126邮箱联系方式:no1xijin@126. com
2018-08-24 14:10
我是小白123
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-8-23
收藏
得分:0 
回复 2楼 no1xijin
好吧
2018-08-24 14:11
快速回复:俄罗斯方块编程的方块变形边界问题,求各位大佬
数据加载中...
 
   



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

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