#include <stdio.h>
#include <bios.h>
#include <conio.h>
#define ESC 0x011b
#define UP 0×4800
#define DOWN 0×5000
#define LEFT 0x4b00
#define RIGHT 0x4d00
typedef struct
{ int x;
int y;
}point;
char map[10][20]=
{ “####################”,
“## #”,
“# ######### # # #”,
“# #### # ###”,
“# # ### # ##”,
“# # ##### # # #”,
“# # ## # #”,
“# ##### # ## # #”,
“# # #”,
“####################”
};
DrawMan(int x,int y)
{ gotoxy(x+10,y+5);
printf(“%c\b”,2);
}
DrawSpace(int x,int y)
{ gotoxy(x+10,y+5);
printf(” “);
}
DrawWall(int x,int y)
{ gotoxy(x+10,y+5);
textcolor(RED);
putch(219);
}
void DrawMap()
{ int x,y;
for(y=0;y<10;++y)
for(x=0;x<20;++x)
if(map[y][x]==’#') DrawWall(x,y);
gotoxy(38,2);
textcolor(RED);
printf(“Man Game”);
gotoxy(48,6);
printf(“play game:”);
gotoxy(48,8);
printf(“push key move man!”);
gotoxy(48,10);
printf(“push Esc Exit game!”);
}
void main()
{ point man={1,1},des={18,8};
int key=0;
clrscr();
DrawMap();
DrawMan(man.x,man.y);
textcolor(YELLOW);
gotoxy(des.x+10,des.y+5);
putch(‘*’);
while(key!=ESC)
{ key=bioskey(0);
switch(key)
{ case UP:
if(map[man.y-1][man.x]==’#') break;
DrawSpace(man.x,man.y);
–man.y;
DrawMan(man.x,man.y);
case DOWN:
if(map[man.y+1][man.x]==’#') break;
DrawSpace(man.x,man.y);
++man.y;
DrawMan(man.x,man.y);
case LEFT:
if(map[man.y][man.x-1]==’#') break;
DrawSpace(man.x,man.y);
–man.x;
DrawMan(man.x,man.y);
case RIGHT:
if(map[man.y][man.x+1]==’#') break;
DrawSpace(man.x,man.y);
++man.x;
DrawMan(man.x,man.y);
}
if(man.x==des.x&&man.y==des.y)
{ gotoxy(38,14);
printf(“success!”);
getch();
key=ESC;
}
}
}
>> 本文固定链接: http://www.vcgood.com/archives/3424
>> 转载请注明: chiwei1989 2010年09月19日 于 C语言帝国 发表
你没有把键盘输入参数加进去 你把主函数参数加进去就可以了