| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1068 人关注过本帖
标题:请求大神帮忙看一下,为什么编译通过,却不能正常运行
只看楼主 加入收藏
小萌
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-8-18
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
请求大神帮忙看一下,为什么编译通过,却不能正常运行
delay(speed)->Sleep(speed)  key=bioskey(0)->key=getch()这里不知道错不错,不改编译器不通过。帮忙看看,谢谢啦
#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<dos.h>
#include<conio.h>
#include <time.h>
#include <windows.h>

#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
#define N 100
int i,key;
int speed;
void GameOver();
void Play();
void dwall();
void wall(int x, int y);
int Speed();

void gotoxy(int x,int y)
{
COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
}
struct FOOD
{
    int x;
    int y;
    int flag;
}food;
struct Snake
{
    int x[N];
    int y[N];
    int node;                                                            /*蛇的节数*/
    int dir;                                                            /*蛇移动方向*/
    int life;                                                            /*标志是死是活*/
}snake;
void wall(int x, int y)
{
    int sizx=9;
    int sizy=9;
    setcolor(WHITE);
    line(x,y,x+sizx,y);
    line(x,y+1,x+sizx-1,y+1);
    line(x,y,x,y+sizy);
    line(x+1,y,x+1,y+sizy-1);
    setcolor(RED);
    line(x+1,y+sizy,x+sizx,y+sizy);
    line(x+2,y+sizy-1,x+sizx,y+sizy-1);
    line(x+sizx-1,y+2,x+sizx-1,y+sizy-1);
    line(x+sizx,y+1,x+sizx,y+sizy);
    cleardevice();
    setfillcolor(LIGHTRED);
    setfillstyle(BS_SOLID);
    bar(x+2,y+2,x+sizx-2,y+sizy-2);
}
void dwall()
{
    int j;
    for(j=50;j<=600;j+=10)
    {
        wall(j,40);
        wall(j,451);
    }
    for(j=40;j<=450;j+=10)
    {
        wall(50,j);
        wall(601,j);
    }
}
int Speed()
{
    int m;
    gotoxy(20,10);
    printf("level 1\n");
    gotoxy(20,12);
    printf("level 2\n");
    gotoxy(20,14);
    printf("level 3\n\t\tplease choose:");
    scanf("%d",&m);
    switch(m)
    {
        case 1:
            return 60000;
        case 2:
            return 40000;
        case 3:
            return 20000;
        default:
            cleardevice();
            Speed();
    }   
}
void Play(void)
{
    srand((unsigned long)time(NULL));
    food.flag=1;
    snake.life=0;
    snake.dir=1;
    snake.x[0]=300;
    snake.y[0]=240;
    snake.x[1]=290;
    snake.y[1]=240;
    snake.node=2;
    do
    {
        while(!kbhit())
        {
            if(food.flag==1)
            do
            {
                food.x=rand()%520+60;
                food.y=rand()%370+60;
                food.flag=0;
            }while(food.x%10!=0||food.y%10!=0);
            if(food.flag==0)
            {
                setcolor(GREEN);
                setlinestyle(PS_DASHDOT,3,0,0);
                rectangle(food.x, food.y, food.x+10, food.y+10);
            }
            for (i=snake.node-1;i>0;i--)
            {
                snake.x[i]=snake.x[i-1];
                snake.y[i]=snake.y[i-1];
            }
            switch(snake.dir)
            {
                case 1:
                    snake.x[0]+=10;
                    break;
                case 2:
                    snake.x[0]-=10;
                    break;
                case 3:
                    snake.y[0]-=10;
                    break;
                case 4:
                    snake.x[0]+=10;
                    break;
            }
            for(i=3;i<snake.node;i++)
            {
                if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])
                {
                    GameOver();
                    snake.life=1;
                    break;
                }
            }
            if(snake.x[0]<60||snake.x[0]>590||snake.y[0]<50||snake.y[0]>440)
            {
                GameOver();
                snake.life=1;
                break;
            }
            if(snake.x[0]==food.x&&snake.y[0]==food.y)
            {
                setcolor(BLACK);
                rectangle(food.x, food.y, food.x+10, food.y+10);
                snake.node++;
                food.flag=1;
            }
            setcolor(RED);
            for(i=0;i<snake.node;i++)
            {
                setlinestyle(PS_SOLID,1,0,0);
                rectangle(snake.x[i],snake.y[i],snake.x[i]+10,snake.y[i]+10);
            }
            Sleep(speed);
            setcolor(BLACK);
            rectangle(snake.x[snake.node-1],snake.y[snake.node-1],snake.x[snake.node-1]+10,snake.y[snake.node-1]+10);
        }
        if(snake.life==1)
            break;
        key=getch();
        if(key==UP&&snake.dir!=4)
            snake.dir=3;
        else if(key==DOWN&&snake.dir!=3)
            snake.dir=4;
        else if(key==RIGHT&&snake.dir!=2)
            snake.dir=1;
        else if(key==LEFT&&snake.dir!=1)
            snake.dir=2;
    }while(key!=ESC);
}
void GameOver(void)
{
    cleardevice();
    setcolor(RED);
    settextstyle(32, 0, _T("宋体"));
    outtextxy(0,0,_T("GAME OVER, BYE BYE"));
    Sleep(3);
}
void main()
{
    initgraph(640,640);
    speed=Speed();
    cleardevice();
    dwall();
    Play();
    getch();
    closegraph();
}
搜索更多相关主题的帖子: include speed 
2016-08-18 17:16
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
收藏
得分:0 
代码不全,编都编不过,帮不了你
2016-08-18 17:46
小萌
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-8-18
收藏
得分:0 
是全的啊,根据TC书上编的
2016-08-25 17:39
ehszt
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:40
帖 子:1745
专家分:3216
注 册:2015-12-2
收藏
得分:0 
贪吃蛇?这个要dos环境才能运行的,下一个dosbox
2016-08-25 17:43
快速回复:请求大神帮忙看一下,为什么编译通过,却不能正常运行
数据加载中...
 
   



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

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