undefined
为游戏狂~~!! 大家努力编哈!
#include<stdio.h> #include<conio.h> #define LEFT 0x4b00 #define RIGHT 0x4d00 #define DOWN 0x5000 #define UP 0x4800 #define ESC 0x011b #define X 6 #define Y 5 /*--------------------------迷宫地图-------------------------*/ int horizontal=1,vertical=0; ; int length=20,width=70; char person=2,map[20][70]={ {"######################################################################"}, {" # # ##"}, {"# ##################### # ####### # ################################ #"}, {"# # # ## # # # ### #"}, {"# # ##################### ## # ## # ############ ############# ### #"}, {"# # ## # ###### ## # # # #"}, {"# ########################## # ## ####### ############# ##### #"}, {"# # # # ####### # # # # # #"}, {"# # # #################### # # ### ####### ######### # # # # #"}, {"# # # # # # # ############# # ### #"}, {"# # # # ### # ######## # ### # ##### ############ ####### #"}, {"# # ######## # # ### ####### # # ### # # ### #"}, {"# # # # ## # ## ### ### # # # # # # ############ #### # #"}, {"# # # #### # # # ######## #### # # # # ######## #"}, {"# # # # ####### # ######## ## #### ## # # ################# # #"}, {"# # #### # # ## ## # ##### #"}, {"# # ###################################################### # #"}, {"# ####### # # # # # ######## # # ### ##### ## # #"}, {"# # # # # ## # # # # # *"}, {"######################################################################"} }; /*------------------------------------------------------------*/ void execute();/*执行函数声明*/ void maps(); /*地图函数声明*/ void interface_main();/*主界面*/ void interface_options();/*胜利语*/ void interface_last(); /*退出语*/ void up(); /*向上执行函数声明*/ void down(); /*向下执行函数声明*/ void left(); /*向左执行函数声明*/ void right(); /*向右执行函数声明*/ void soul(); /*灵魂函数声明*/ void main() /*主函数*/ { map[1][0]=person; clrscr(); interface_main(); maps(); execute(); /*执行方向操作函数调用*/ interface_last(); /*退出语*/ getch(); } void interface_main() /*主界面函数*/ { textcolor(YELLOW); cprintf("--------------wlecome use----------------"); printf("\n"); cprintf(" time 09.07.20 "); printf("\n"); cprintf(" author snoopy "); printf("\n"); cprintf("ESC(shut)"); printf("\n"); } void interface_options() /*胜利语*/ { printf("congratulate pass a test ! ! ! ^-^"); getch(); exit(0); } void interface_last() /*退出语*/ { printf("good bay ! ! ! ^-^"); } void execute() /*方向执行函数*/ { int key=0; do { key=bioskey(0); if(key) { textcolor(LIGHTRED); if(key==UP) /*当按上按键时执行返回值为1*/ { up(); /*调用上方向执行函数*/ } if(key==DOWN) { down(); } if(key==LEFT) { left(); } if(key==RIGHT) { right(); } if(key==ESC) { exit(0); } key=0; soul(); /*调用灵魂函数*/ } }while(1); } void maps() /*迷宫输出函数*/ { int i,j; textcolor(WHITE); for(i=0;i<length;i++) { printf(" "); for(j=0;j<width;j++) { cprintf("%c",map[i][j]); } printf("\n"); } textcolor(LIGHTRED); gotoxy(X,Y+1); putch(2); gotoxy(X+69,Y+18); textcolor(13); putch('*'); } void up() /*上方向执行函数*/ { int t; if(map[horizontal-1][vertical]=='*') { map[horizontal-1][vertical]=map[horizontal][vertical]; map[horizontal][vertical]=' '; gotoxy(X+vertical,Y+horizontal-1); putch(2); gotoxy(X+vertical,Y+horizontal); putchar(' '); interface_options(); } if(map[horizontal-1][vertical]==' ') { horizontal=horizontal-1; t=map[horizontal][vertical]; map[horizontal][vertical]=map[horizontal+1][vertical]; map[horizontal+1][vertical]=t; gotoxy(X+vertical,Y+horizontal); putch(2); gotoxy(X+vertical,Y+horizontal+1); putchar(' '); gotoxy(1,2); putchar(' '); } } void down() /*下方向执行函数*/ { int t; if(map[horizontal+1][vertical]=='*') { map[horizontal+1][vertical]=map[horizontal][vertical]; map[horizontal][vertical]=' '; gotoxy(X+vertical,Y+horizontal+1); putch(2); gotoxy(X+vertical,Y+horizontal); putchar(' '); interface_options(); } if(map[horizontal+1][vertical]==' ') { horizontal=horizontal+1; t=map[horizontal][vertical]; map[horizontal][vertical]=map[horizontal-1][vertical]; map[horizontal-1][vertical]=t; gotoxy(X+vertical,Y+horizontal); putch(2); gotoxy(X+vertical,Y+horizontal-1); putchar(' '); gotoxy(1,2); putchar(' '); } } void left() /*左方向执行函数*/ { int t; if(map[horizontal][vertical-1]=='*') { map[horizontal][vertical-1]=map[horizontal][vertical]; map[horizontal][vertical]=' '; gotoxy(X+vertical-1,Y+horizontal); putch(2); gotoxy(X+vertical,Y+horizontal); putchar(' '); interface_options(); } if(map[horizontal][vertical-1]==' ') { vertical=vertical-1; t=map[horizontal][vertical]; map[horizontal][vertical]=map[horizontal][vertical+1]; map[horizontal][vertical+1]=t; gotoxy(X+vertical,Y+horizontal); putch(2); gotoxy(X+vertical+1,Y+horizontal); putchar(' '); gotoxy(1,2); putchar(' '); } } void right() /*右方向执行函数*/ { int t; if(map[horizontal][vertical+1]=='*') { map[horizontal][vertical+1]=map[horizontal][vertical]; map[horizontal][vertical]=' '; gotoxy(X+vertical,Y+horizontal); putch(2); gotoxy(X+vertical-1,Y+horizontal); putchar(' '); interface_options(); } if(map[horizontal][vertical+1]==' ') { vertical=vertical+1; t=map[horizontal][vertical]; map[horizontal][vertical]=map[horizontal][vertical-1]; map[horizontal][vertical-1]=t; gotoxy(X+vertical,Y+horizontal); putch(2); gotoxy(X+vertical-1,Y+horizontal); putchar(' '); gotoxy(1,2); putchar(' '); } } void soul() { textcolor(WHITE); if(map[18][63]==2) { map[18][67]='#'; gotoxy(X+67,Y+18); putch('#'); } if(map[18][65]==2) { map[18][64]='#'; map[1][68]=' '; gotoxy(X+64,Y+18); putch('#'); gotoxy(X+68,Y+1); putch(' '); } if(map[18][58]==2) { map[18][67]=' '; map[18][64]=' '; gotoxy(X+67,Y+18); putch(' '); gotoxy(X+64,Y+18); putch(' '); } if(map[16][68]==2) { map[15][68]='#'; map[4][68]='#'; gotoxy(X+68,Y+15); putch('#'); gotoxy(X+68,Y+4); putch('#'); } if(map[18][68]==2) { map[18][69]='#'; map[5][69]='*'; map[5][67]=' '; map[11][2]=' '; gotoxy(X+69,Y+18); putch('#'); gotoxy(X+69,Y+5); textcolor(13); putch('*'); gotoxy(X+67,Y+5); putch(' '); gotoxy(X+2,Y+11); putch(' '); } if(map[5][65]==2) { map[5][67]='#'; map[9][67]=' '; map[9][66]=' '; gotoxy(X+67,Y+5); putch('#'); gotoxy(X+67,Y+9); putch(' '); gotoxy(X+66,Y+9); putch(' '); } if(map[9][66]==2) { map[9][67]='#'; map[14][67]=' '; gotoxy(X+67,Y+9); putch('#'); gotoxy(X+67,Y+14); putch(' '); } if(map[15][28]==2) { map[14][29]='#'; map[12][29]=' '; gotoxy(X+29,Y+14); putch('#'); gotoxy(X+29,Y+12); putch(' '); } if(map[12][36]==2) { map[10][36]='#'; map[11][38]=' '; gotoxy(X+36,Y+10); putch('#'); gotoxy(X+38,Y+11); putch(' '); } if(map[14][67]==2) { map[12][67]=' '; map[13][68]='#'; gotoxy(X+67,Y+12); putch(' '); gotoxy(X+68,Y+13); putch('#'); } if(map[7][59]==2) { map[7][60]='#'; gotoxy(X+60,Y+7); putch('#'); } if(map[9][58]==2) { map[9][59]='#'; gotoxy(X+59,Y+9); putch('#'); } if(map[13][58]==2) { map[12][59]='#'; gotoxy(X+59,Y+12); putch('#'); } if(map[12][67]==2) { map[5][69]='#'; map[1][69]='*'; gotoxy(X+69,Y+5); putch('#'); gotoxy(X+69,Y+1); textcolor(13); putch('*'); } gotoxy(1,2); putch(' '); }