C语言贪吃蛇问题.编译可以,运行不出来(有的人运行可以)

C语言贪吃蛇问题.编译可以,运行不出来(有的人运行可以)很奇怪.不知道为什么.编译通过.窗口闪动就关闭了编译环境win-tc机子32位机... C语言贪吃蛇问题.编译可以,运行不出来(有的人运行可以)
很奇怪. 不知道为什么. 编译通过. 窗口闪动就关闭了
编译环境win-tc 机子32位机
展开
 我来答
sunzhen_222
2007-10-14 · TA获得超过580个赞
知道小有建树答主
回答量:201
采纳率:0%
帮助的人:286万
展开全部
发一下源代码呀!

看看我以前写的你能运行不

#include<stdio.h>
#include<graphics.h>
#include<bios.h>
#include<stdlib.h>
#include<conio.h>

#define BC LIGHTBLUE
#define FC RED
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
#define ONE 0x231
#define TWO 0x332
#define THREE 0x433

void printsnake(int x,int y,int corlor);
void moveh(int *x,int *y,char (*p)[30],int dir);
void movet(int *tx,int *ty,char (*p)[30]);
void food(char (*p)[30]);
void level(char (*p)[30]);
void ashui();
void drawmat(char *mat,int matsize,int x,int y,int color);

void main()
{
int x,y,tx,ty,driver=DETECT,mode,key,key1,score=0;
char snake[40][30]={0};
char s[10];
initgraph(&driver,&mode,"");
ashui();
level(snake);
outtextxy(80,60,"score=0");
setcolor(RED);
rectangle(80,80,520,420) ;
rectangle(99,99,501,401) ;
setfillstyle(SOLID_FILL,BC);
floodfill(200,200,RED);
setfillstyle(SOLID_FILL,BROWN);
for(y=0;y<30;y++)
for(x=0;x<40;x++)
if(snake[x][y]==6)bar(100+10*x,100+10*y,110+10*x,110+10*y);
printsnake(2,15,FC);
printsnake(3,15,FC);
snake[2][15]=snake[3][15]=1;
food(snake);
key=RIGHT;
x=3;y=15;tx=2;ty=15;
for(;;)
{
if(bioskey(1))key1=bioskey(0);
if(key1==ESC)break;
if(key1==LEFT&&key!=RIGHT||key1==RIGHT&&key!=LEFT||key1==UP&&key!=DOWN||key1==DOWN&&key!=UP)key=key1;
moveh(&x,&y,snake,key);
if(snake[x][y]!=5)
{
movet(&tx,&ty,snake);
if(x<0||x>39||y<0||y>29)
{
printsnake(x,y,0);
break;
}
else if(snake[x][y])break;
}
else
{
food(snake);
score++;
sprintf(s,"score=%d",score);
setfillstyle(SOLID_FILL,0);
bar(80,60,150,75);
outtextxy(80,60,s);
}
delay(30000);
}
setcolor(YELLOW);
moveto(260,240);
outtext("GAME OVER!");
getch();
}

void printsnake(int x,int y,int corlor)
{
int xx,yy;
setfillstyle(SOLID_FILL,corlor);
setcolor(corlor);
xx=100+10*x+5;
yy=100+10*y+5;
circle(xx,yy,5);
floodfill(xx,yy,corlor);
}
void moveh(int *x,int *y,char (*p)[30],int dir)
{
int i,j;
i=*x;j=*y;
switch(dir)
{
case RIGHT:p[i][j]=1;(*x)++;break;
case UP:p[i][j]=2;(*y)--;break;
case LEFT:p[i][j]=3;(*x)--;break;
case DOWN:p[i][j]=4;(*y)++;break;
}
printsnake(*x,*y,FC);
}
void movet(int *tx,int *ty,char (*p)[30])
{
int i,j;
i=*tx;j=*ty;
printsnake(i,j,BC);
switch(p[i][j])
{
case 1:(*tx)++;break;
case 2:(*ty)--;break;
case 3:(*tx)--;break;
case 4:(*ty)++;break;
}
p[i][j]=0;
}
void food(char (*p)[30])
{
int x,y;
for(;;)
{
randomize();
x=random(40);
y=random(30);
if(!p[x][y])break;
}
printsnake(x,y,WHITE);
p[x][y]=5;
}
void level(char (*p)[30])
{
int key,i,x,y,l=0;
outtextxy(180,150,"press 1,2,3 to choose game level");
outtextxy(200,170,"1.Easy");
outtextxy(200,190,"2.Normal");
outtextxy(200,210,"3.Hard");
key=bioskey(0);
switch(key)
{
case ONE:l=0;break;
case TWO:l=15;break;
case THREE:l=30;break;
}
cleardevice();
setfillstyle(SOLID_FILL,BROWN);
for(i=0;i<l;i++)
{
for(;;)
{
x=random(40);
y=random(30);
if(y==15||x<6||p[x][y])continue;
p[x][y]=6;
break;
}
}
}

void drawmat(char *mat,int matsize,int x,int y,int color)
{
int i, j, k, n;
n = (matsize - 1) / 8 + 1;
for(j = 0; j < matsize; j++)
for(i = 0; i < n; i++)
for(k = 0;k < 8; k++)
if(mat[j * n + i] & (0x80 >> k))
putpixel(x + i * 8 + k, y + j, color);
}

void ashui()
{
char tan32K[]={
0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,
0x00,0x03,0x00,0x00,0x00,0x07,0x00,0x00,
0x00,0x07,0x80,0x00,0x00,0x0C,0x60,0x00,
0x00,0x18,0x30,0x00,0x00,0x38,0x1C,0x00,
0x00,0x73,0x0E,0x00,0x00,0xE1,0x83,0x80,
0x01,0x80,0x01,0xF0,0x03,0x03,0xF0,0xFE,
0x06,0x7E,0x70,0x3E,0x0C,0x00,0xC0,0x00,
0x30,0x00,0x80,0x00,0x40,0x01,0x00,0x00,
0x00,0x43,0xF8,0x00,0x00,0x7C,0x1C,0x00,
0x00,0x60,0x18,0x00,0x00,0x63,0x18,0x00,
0x00,0x63,0x18,0x00,0x00,0x63,0x18,0x00,
0x00,0x62,0x18,0x00,0x00,0x62,0x18,0x00,
0x00,0x46,0x18,0x00,0x00,0x04,0x00,0x00,
0x00,0x0C,0xC0,0x00,0x00,0x18,0x70,0x00,
0x00,0x30,0x38,0x00,0x00,0x60,0x1C,0x00,
0x01,0xC0,0x0C,0x00,0x02,0x00,0x04,0x00,
};
char chi32K[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,
0x00,0x00,0x70,0x00,0x00,0x00,0x70,0x00,
0x00,0x00,0x60,0x00,0x00,0x00,0xE0,0x00,
0x00,0x00,0xC1,0x80,0x00,0x01,0x9F,0xC0,
0x00,0xC1,0xFE,0x00,0x67,0xE3,0x00,0x00,
0x7C,0xE2,0x00,0x00,0x20,0xC4,0x00,0x00,
0x30,0xC8,0x00,0x00,0x30,0x80,0x38,0x00,
0x30,0x81,0xF8,0x00,0x17,0xC7,0x60,0x00,
0x1E,0x00,0x60,0x00,0x10,0x00,0xC0,0x00,
0x10,0x00,0xC0,0x00,0x00,0x00,0x80,0x08,
0x00,0x01,0x80,0x08,0x00,0x01,0x00,0x08,
0x00,0x01,0x00,0x08,0x00,0x03,0x00,0x18,
0x00,0x01,0x80,0x3C,0x00,0x01,0xFF,0xF8,
0x00,0x00,0x7F,0xE0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
char she32K[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x1C,0x00,0x01,0x80,0x0E,0x00,
0x01,0x80,0x06,0x00,0x01,0x80,0x02,0x00,
0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x70,
0x00,0x80,0x87,0xF8,0x00,0xBC,0xF8,0x30,
0x3F,0xCE,0xC0,0x60,0x18,0x8D,0x80,0x40,
0x18,0x89,0x80,0x00,0x08,0x89,0x30,0x40,
0x08,0xB8,0x10,0x60,0x0B,0xE0,0x10,0xE0,
0x0C,0x80,0x11,0xC0,0x00,0x88,0x13,0x00,
0x00,0x8C,0x1C,0x00,0x00,0x8C,0x10,0x00,
0x00,0xF6,0x30,0x08,0x03,0xC4,0x30,0x08,
0x7F,0x00,0x10,0x08,0x3C,0x00,0x10,0x18,
0x00,0x00,0x18,0x3C,0x00,0x00,0x0F,0xFC,
0x00,0x00,0x03,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
char a16S[]={
0x00,0x00,0x7B,0xFE,0x48,0x08,0x50,0x08,
0x60,0x08,0x53,0xE8,0x4A,0x28,0x4A,0x28,
0x4A,0x28,0x6B,0xE8,0x50,0x08,0x40,0x08,
0x40,0x08,0x40,0x08,0x40,0x28,0x40,0x10,
};
char shui16S[]={
0x01,0x00,0x01,0x00,0x01,0x08,0x01,0x10,
0x7D,0x20,0x05,0xC0,0x05,0x40,0x09,0x20,
0x09,0x20,0x11,0x10,0x11,0x18,0x21,0x0E,
0xC1,0x04,0x01,0x00,0x05,0x00,0x02,0x00,
};
char zuo16S[]={
0x08,0x80,0x0C,0x80,0x09,0x00,0x13,0xFE,
0x12,0x80,0x34,0x88,0x50,0xFC,0x90,0x80,
0x10,0x80,0x10,0x84,0x10,0xFE,0x10,0x80,
0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,
};
char pin16S[]={
0x00,0x00,0x0F,0xF0,0x08,0x10,0x08,0x10,
0x08,0x10,0x0F,0xF0,0x08,0x10,0x00,0x00,
0x7E,0xFC,0x42,0x84,0x42,0x84,0x42,0x84,
0x42,0x84,0x7E,0xFC,0x42,0x84,0x00,0x00,
};
drawmat(tan32K,32,150,180,BLUE);
drawmat(chi32K,32,300,180,BLUE);
drawmat(she32K,32,450,180,BLUE);
drawmat(a16S,16,350,250,RED);
drawmat(shui16S,16,370,250,RED);
drawmat(zuo16S,16,390,250,RED);
drawmat(pin16S,16,410,250,RED);
getch();
cleardevice();
}
标苦运先
2007-10-14 · TA获得超过107个赞
知道小有建树答主
回答量:242
采纳率:0%
帮助的人:135万
展开全部
最后添加getch()
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
广东杨子江
2007-10-14 · TA获得超过127个赞
知道小有建树答主
回答量:244
采纳率:0%
帮助的人:180万
展开全部
这个是系统兼容性的问题,像我的机子就是一个例子,不能运行一些图形函数.后来我问了一下高手,他们说是CPU的问题(也就是说跟系统不兼容).假如我没有搞错的话,你的CPU是AMD的,对吧,那就没办法了.你只能换CPU成Intel的.不然是不行的.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友dc23807
2007-10-14 · TA获得超过252个赞
知道小有建树答主
回答量:236
采纳率:0%
帮助的人:0
展开全部
To 广东杨子江:不可能intel的可以而amd的不行!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
Is_it_right
2007-10-14 · TA获得超过1031个赞
知道小有建树答主
回答量:410
采纳率:0%
帮助的人:405万
展开全部
加一句system("pause");
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式