开发工具:
文件大小: 6kb
下载次数: 0
上传时间: 2009-06-29
详细说明: #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; i nt 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; } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.