/*迷宫游戏*/
/*进入tc运行游戏,按上下左右键控制,任何时候按ESC键退出*/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#define LEFT 120
#define TOP 40
#define RIGHT 520
#define BOTTOM 440
#define SMALL 20
int b[20][20]; /*用来保存地图信息*/
b[20][20]={{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,1,1,1,1},
{1,0,1,0,0,1,0,0,1,0,1,0,1,1,0,1,0,0,0,1},
{1,0,1,0,1,1,0,1,1,0,1,0,1,0,0,1,0,1,0,1},
{1,0,0,0,0,1,0,0,1,0,0,0,1,0,1,1,0,1,0,1},
{1,1,1,0,1,1,1,0,1,1,1,1,0,0,1,0,0,1,0,1},
{1,1,0,0,1,1,0,0,1,0,0,1,0,1,1,0,1,0,0,1},
{1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,1},
{1,0,1,1,0,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1},
{1,0,1,0,0,1,1,0,0,1,0,0,1,1,0,0,1,0,1,1},
{1,0,0,0,1,1,0,1,0,0,0,1,1,0,1,0,1,0,0,1},
{1,0,1,1,1,0,0,1,1,1,0,1,1,0,1,0,1,1,0,1},
{1,0,0,1,0,0,1,0,1,0,0,1,0,0,0,0,1,0,0,1},
{1,1,0,1,1,0,1,0,0,1,0,1,1,1,0,1,1,0,1,1},
{1,0,0,0,1,0,1,1,0,1,0,1,0,0,0,1,0,0,0,1},
{1,0,1,0,1,0,0,0,0,1,0,0,0,1,1,0,0,1,0,1},
{1,0,1,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1},
{1,0,1,1,0,0,0,0,1,0,1,1,0,0,1,0,0,0,1,1},
{1,0,0,0,0,1,0,1,1,0,0,0,0,1,1,0,1,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
void drawcake(int x,int y) /*划方块*/
{
setfillstyle(SOLID_FILL,BLUE);
bar(LEFT+1+x*SMALL,TOP+1+y*SMALL,RIGHT-1-19*SMALL+x*SMALL,BOTTOM-1-19*SMALL+y*SMALL);
}
void draw(int x,int y) /*划小方块*/
{
setfillstyle(SOLID_FILL,RED);
bar(LEFT+5+x*SMALL,TOP+5+y*SMALL,RIGHT-5-19*SMALL+x*SMALL,BOTTOM-5-19*SMALL+y*SMALL);
}
void undraw(int x,int y) /*擦去小方块*/
{
setfillstyle(SOLID_FILL,BLACK);
bar(LEFT+5+x*SMALL,TOP+5+y*SMALL,RIGHT-5-19*SMALL+x*SMALL,BOTTOM-5-19*SMALL+y*SMALL);
}
main()
{
int gr=DETECT,gm,k=0,i,j,x=1,y=1,ch;
float f;
initgraph(&gr,&gm,"");
cleardevice();
setbkcolor(0);
for(i=0;i<20;i++)
for(j=0;j<20;j++)
if(b[i][j]==1)drawcake(j,i);
draw(x,y);
do{
ch=bioskey(0);
switch(ch)
{
case 19200: /*按向左键*/
if(b[y][x-1]==0)
{
undraw(x,y);
b[y][x]=0;
x--;
draw(x,y);
b[y][x]=2;
break;
}
case 19712: /*按向右键*/
if(b[y][x+1]==0)
{
undraw(x,y);
b[y][x]=0;
x++;
draw(x,y);
b[y][x]=2;
break;
}
case 18432: /*按向上键*/
if(b[y-1][x]==0)
{
undraw(x,y);
b[y][x]=0;
y--;
draw(x,y);
b[y][x]=2;
break;
}
case 20480: /*按向下键*/
if(b[y+1][x]==0)
{
undraw(x,y);
b[y][x]=0;
y++;
draw(x,y);
b[y][x]=2;
break;
}
}
if(b[18][18]==2)ch=283;
}while(ch!=283);
if(b[18][18]==2)printf(" 恭贺你成功地走出了迷宫!");
getch();
}
/*此程序所有权归计算机网络安全研究协会,另外我编有地图编辑器,以后再发*/
/*柳云飞2004-11-3*/
/*c语言并不难,只要你认真学,对他感兴趣*/
/*进入tc运行游戏,按上下左右键控制,任何时候按ESC键退出*/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#define LEFT 120
#define TOP 40
#define RIGHT 520
#define BOTTOM 440
#define SMALL 20
int b[20][20]; /*用来保存地图信息*/
b[20][20]={{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,1,1,1,1},
{1,0,1,0,0,1,0,0,1,0,1,0,1,1,0,1,0,0,0,1},
{1,0,1,0,1,1,0,1,1,0,1,0,1,0,0,1,0,1,0,1},
{1,0,0,0,0,1,0,0,1,0,0,0,1,0,1,1,0,1,0,1},
{1,1,1,0,1,1,1,0,1,1,1,1,0,0,1,0,0,1,0,1},
{1,1,0,0,1,1,0,0,1,0,0,1,0,1,1,0,1,0,0,1},
{1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,1},
{1,0,1,1,0,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1},
{1,0,1,0,0,1,1,0,0,1,0,0,1,1,0,0,1,0,1,1},
{1,0,0,0,1,1,0,1,0,0,0,1,1,0,1,0,1,0,0,1},
{1,0,1,1,1,0,0,1,1,1,0,1,1,0,1,0,1,1,0,1},
{1,0,0,1,0,0,1,0,1,0,0,1,0,0,0,0,1,0,0,1},
{1,1,0,1,1,0,1,0,0,1,0,1,1,1,0,1,1,0,1,1},
{1,0,0,0,1,0,1,1,0,1,0,1,0,0,0,1,0,0,0,1},
{1,0,1,0,1,0,0,0,0,1,0,0,0,1,1,0,0,1,0,1},
{1,0,1,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1},
{1,0,1,1,0,0,0,0,1,0,1,1,0,0,1,0,0,0,1,1},
{1,0,0,0,0,1,0,1,1,0,0,0,0,1,1,0,1,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
void drawcake(int x,int y) /*划方块*/
{
setfillstyle(SOLID_FILL,BLUE);
bar(LEFT+1+x*SMALL,TOP+1+y*SMALL,RIGHT-1-19*SMALL+x*SMALL,BOTTOM-1-19*SMALL+y*SMALL);
}
void draw(int x,int y) /*划小方块*/
{
setfillstyle(SOLID_FILL,RED);
bar(LEFT+5+x*SMALL,TOP+5+y*SMALL,RIGHT-5-19*SMALL+x*SMALL,BOTTOM-5-19*SMALL+y*SMALL);
}
void undraw(int x,int y) /*擦去小方块*/
{
setfillstyle(SOLID_FILL,BLACK);
bar(LEFT+5+x*SMALL,TOP+5+y*SMALL,RIGHT-5-19*SMALL+x*SMALL,BOTTOM-5-19*SMALL+y*SMALL);
}
main()
{
int gr=DETECT,gm,k=0,i,j,x=1,y=1,ch;
float f;
initgraph(&gr,&gm,"");
cleardevice();
setbkcolor(0);
for(i=0;i<20;i++)
for(j=0;j<20;j++)
if(b[i][j]==1)drawcake(j,i);
draw(x,y);
do{
ch=bioskey(0);
switch(ch)
{
case 19200: /*按向左键*/
if(b[y][x-1]==0)
{
undraw(x,y);
b[y][x]=0;
x--;
draw(x,y);
b[y][x]=2;
break;
}
case 19712: /*按向右键*/
if(b[y][x+1]==0)
{
undraw(x,y);
b[y][x]=0;
x++;
draw(x,y);
b[y][x]=2;
break;
}
case 18432: /*按向上键*/
if(b[y-1][x]==0)
{
undraw(x,y);
b[y][x]=0;
y--;
draw(x,y);
b[y][x]=2;
break;
}
case 20480: /*按向下键*/
if(b[y+1][x]==0)
{
undraw(x,y);
b[y][x]=0;
y++;
draw(x,y);
b[y][x]=2;
break;
}
}
if(b[18][18]==2)ch=283;
}while(ch!=283);
if(b[18][18]==2)printf(" 恭贺你成功地走出了迷宫!");
getch();
}
/*此程序所有权归计算机网络安全研究协会,另外我编有地图编辑器,以后再发*/
/*柳云飞2004-11-3*/
/*c语言并不难,只要你认真学,对他感兴趣*/