【文件属性】:
文件名称:qiang ---tc
文件大小:6KB
文件格式:C
更新时间:2012-07-19 06:03:25
qiang
#include
#include
#include
#include
#include
#include
#define UP 1
#define DOWN 2
#define LEFT 3
#define RIGHT 4
#define PI 3.141592653
struct MyPcaman
{
int x;
int y;
int radius;
int direction;
}aPcaman;
int isOver;
void init(void);
void movingPcaman(void);
void initPcaman(void);
void drawPcaman(void);
void clearPcaman(void);
void movePcaman(void);
int main()
{
init();
movingPcaman();
closegraph();
return 0;
}
void init()
{
#define WALL 1
#define BEAN 0
#define N 10
char buffer[100];
int sence[N][N];
int a,b,c,d,k,i;
int gdriver,gmode;
FILE *fp;
gdriver = DETECT;
initgraph(&gdriver,&gmode,".");
setbkcolor(BLACK);
cleardevice();
fp=fopen("E:\\123.txt","rt");
fscanf(fp,"%d,%d,%d,%d\n",&a,&b,&c,&d);
i=0;
while(fgets(buffer,100,fp)!=NULL)
{
for(k=0;buffer[k]!='\n';k++)
{
sence[k][i]=buffer[k]-'0';
if(sence[k][i]==1)
{
setcolor(GREEN);
rectangle(48*k,48*i,48*(k+1),48*(i+1));
aPcaman.x =aPcaman.x;
aPcaman.y =aPcaman.y;
}
if(sence[k][i]==0)
{
setcolor(YELLOW);
circle(k*48+24,i*48+24,10);
setfillstyle(1,YELLOW);
floodfill(k*48+24,i*48+24,YELLOW);
}
}
i++;
}
initPcaman();
}
void initPcaman()
{
aPcaman.x =72;
aPcaman.y = 72;
aPcaman.radius = 15;
aPcaman.direction = RIGHT;
isOver = 0;
}
void movingPcaman()
{
int i;
int key;
while(!isOver)
{
drawPcaman();
for(i=0;i<15;i++)
delay(5000);
while(bioskey(1))
{
key = bioskey(0);
switch(key)
{
case 0x4800:
aPcaman.direction = UP;
break;
case 0x5000:
aPcaman.direction = DOWN;
break;
case 0x4b00:
aPcaman.direction = LEFT;
break;
case 0x4d00:
aPcaman.direction = RIGHT;
break;
case 0x011b:isOver = 1;
break;
}
}
clearPcaman();
movePcaman();
}
getch();
}
void drawPcaman()
{ switch(aPcaman.direction)
{
case RIGHT: setcolor(YELLOW);
arc(aPcaman.x,aPcaman.y,45,315,aPcaman.radius);
line(aPcaman.x,aPcaman.y,aPcaman.x+cos(PI/4)*15,aPcaman.y-sin(PI/4)*15);
line(aPcaman.x,aPcaman.y,aPcaman.x+cos(PI/4)*15,aPcaman.y+sin(PI/4)*15);
break;
case UP: setcolor(YELLOW);
arc(aPcaman.x,aPcaman.y,135,45,aPcaman.radius);
line(aPcaman.x,aPcaman.y,aPcaman.x-cos(PI/4)*15,aPcaman.y-sin(PI/4)*15);
line(aPcaman.x,aPcaman.y,aPcaman.x+cos(PI/4)*15,aPcaman.y-sin(PI/4)*15);
break;
case LEFT: setcolor(YELLOW);
arc(aPcaman.x,aPcaman.y,225,135,aPcaman.radius);
line(aPcaman.x,aPcaman.y,aPcaman.x-cos(PI/4)*15,aPcaman.y+sin(PI/4)*15);
line(aPcaman.x,aPcaman.y,aPcaman.x-cos(PI/4)*15,aPcaman.y-sin(PI/4)*15);
break;
case DOWN: setcolor(YELLOW);
arc(aPcaman.x,aPcaman.y,315,225,aPcaman.radius);
line(aPcaman.x,aPcaman.y,aPcaman.x+cos(PI/4)*15,aPcaman.y+sin(PI/4)*15);
line(aPcaman.x,aPcaman.y,aPcaman.x-cos(PI/4)*15,aPcaman.y+sin(PI/4)*15);
break;
}
}
void clearPcaman()
{
switch(aPcaman.direction)
{
case RIGHT: setcolor(BLACK);
setfillstyle(1,BLACK);
bar(aPcaman.x-20,aPcaman.y-20,aPcaman.x+20,aPcaman.y+20);
arc(aPcaman.x,aPcaman.y,45,315,aPcaman.radius);
line(aPcaman.x,aPcaman.y,aPcaman.x+cos(PI/4)*15,aPcaman.y-sin(PI/4)*15);
line(aPcaman.x,aPcaman.y,aPcaman.x+cos(PI/4)*15,aPcaman.y+sin(PI/4)*15);
break;
case UP: setcolor(BLACK);
setfillstyle(1,BLACK);
bar(aPcaman.x-20,aPcaman.y-20,aPcaman.x+20,aPcaman.y+20);
arc(aPcaman.x,aPcaman.y,135,45,aPcaman.radius);
line(aPcaman.x,aPcaman.y,aPcaman.x-cos(PI/4)*15,aPcaman.y-sin(PI/4)*15);
line(aPcaman.x,aPcaman.y,aPcaman.x+cos(PI/4)*15,aPcaman.y-sin(PI/4)*15);
break;
case LEFT: setcolor(BLACK);
setfillstyle(1,BLACK);
bar(aPcaman.x-20,aPcaman.y-20,aPcaman.x+20,aPcaman.y+20);
arc(aPcaman.x,aPcaman.y,225,135,aPcaman.radius);
line(aPcaman.x,aPcaman.y,aPcaman.x-cos(PI/4)*15,aPcaman.y+sin(PI/4)*15);
line(aPcaman.x,aPcaman.y,aPcaman.x-cos(PI/4)*15,aPcaman.y-sin(PI/4)*15);
break;
case DOWN: setcolor(BLACK);
setfillstyle(1,BLACK);
bar(aPcaman.x-20,aPcaman.y-20,aPcaman.x+20,aPcaman.y+20);
arc(aPcaman.x,aPcaman.y,315,225,aPcaman.radius);
line(aPcaman.x,aPcaman.y,aPcaman.x+cos(PI/4)*15,aPcaman.y+sin(PI/4)*15);
line(aPcaman.x,aPcaman.y,aPcaman.x-cos(PI/4)*15,aPcaman.y+sin(PI/4)*15);
break;
}
}
void movePcaman()
{
switch(aPcaman.direction)
{
case UP:
aPcaman.y-=48;
break;
case DOWN:aPcaman.y+=48;
break;
case LEFT:aPcaman.x-=48;
break;
case RIGHT:aPcaman.x+=48;
break;
}
if( ( aPcaman.x>=15&&aPcaman.x<=625)&&(aPcaman.y>=15 &&aPcaman.y<=465))
isOver = 0;
else
isOver = 1;
}