我自己编的一个迷宫游戏,呵呵……
一起学习一下~~~~
一共有3关,编地图麻烦就编了3关!!!
因为时间的关系界面化、倒记时都没加,有兴趣的朋友自己加!!!
呵呵……
下面是源代码
#include"stdio.h"
#include"bios.h"
#define LEFT 75
#define RIGHT 77
#define UPPER 72
#define DOWN 80
#define ESC 27
int djs()
{
int i,x=0,y=0;
printf("\n\t\t\tJu Li Tui Chu Shi Jian:");
for(i=9;i>=0;i--)
{
sleep(1);
printf("%d\b",i);
if(i==0)
exit(); //结束时间
}
}
/*
仅供参考学习! QQ:53242360
作者:编程小弟
*/
void show()
{
printf("\n\n\n\n\n\n\n");
printf("\t\t ********************************\n");
printf("\t\t * Huan Ying Play Mi Gong!!! *\n");
printf("\t\t * Maker:Lihong *\n");
printf("\t\t ********************************\n");
printf("\n\t\t Are You Ready \n");
printf("\t\t y/n ");
}
void gameover()
{
printf("\n\n\n\n\n\n\n");
printf("\t\t ********************************\n");
printf("\t\t * Game Over *\n");
printf("\t\t * *\n");
printf("\t\t * Huan Ying Xia Ci Zai Wan *\n");
printf("\t\t ********************************\n");
djs();
}
void D1()
{
printf("\t\t\t********************************\n");
printf("\t\t\t* Mi Gong You Xi *\n");
printf("\t\t\t* Di Yi Guan *\n");
printf("\t\t\t********************************\n");
}
void D2()
{
printf("\t\t\t********************************\n");
printf("\t\t\t* Mi Gong You Xi *\n");
printf("\t\t\t* Di Er Guan *\n");
printf("\t\t\t********************************\n");
}
void D3()
{
printf("\t\t\t********************************\n");
printf("\t\t\t* Mi Gong You Xi *\n");
printf("\t\t\t* Di San Guan *\n");
printf("\t\t\t********************************\n");
}
union keyboard
{
unsigned int KeyInfo;
char chKeyBit[2];
};
int GetKey(void)
{
union keyboard unKey1;
while(bioskey(1)==0);
unKey1.KeyInfo=bioskey(0);
return(unKey1.chKeyBit[0]==0?unKey1.chKeyBit[1]:unKey1.chKeyBit[0]);
}
int Tong()
{
clrscr();
printf("\n\n\n\n\n\n\t\t\tGong Xi Ni Tong Guan!!!\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1,1,0,1,0},/*15*/
{0,1,1,1,0,1,1,1,0,1,1,1,0,0,1,0,0,1,0,1,0,1,1,1,0,1,0,1,0,0,0,0,1,1,1,1,0,0,0,1,1,1,0,0,0,0,1,0,1,1,1,0,0,0,0,0,0,1,1,0},/*16*/
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,0,0,0,1,0,1,0,1,0,1,1,1,0,1,1,0,1,1,1,0,0,1,1,1,1,1,1,0,1,0,0,1,1,1,1,0,1,1,1,0},/*17*/
{0,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,0,1,0,1,1,1,0,1,0,1,1,1,1,1,0,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,1,1,0,0,1,0,0,1,1,1,0,1,0},/*18*/
{0,0,1,1,1,0,1,1,1,0,1,1,0,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0,0,0,0,0,1,1,0},/*19*/
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0} /*20*/
};
int i,j;
while(1)
{
D3();
for(i=0;i<20;i++)
{
gotoxy(10,5+i);
for(j=0;j<60;j++)
{
if(Map[i][j]==0)
printf("#");
if(Map[i][j]==1)
printf(" ");
if(Map[i][j]==2)
printf(" ");
}
}
if(Map[y-5][x-10]==2)
{
clrscr();
Tong();
}
gotoxy(x,y);
printf("*\b");
Key=GetKey();
if(Key==LEFT&&Map[y-5][x-1-10]!=0)
x--;
if(Key==RIGHT&&Map[y-5][x+1-10]!=0)
x++;
if(Key==UPPER&&Map[y-1-5][x-10]!=0)
y--;
if(Key==DOWN&&Map[y+1-5][x-10]!=0)
y++;
if(Key==ESC)
{
clrscr();
gameover();
break;
}
clrscr();
}
getch();
}
int Map2()
{
int Key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,0,0,0,0,0,0,1,0},/*06*/
{0,1,0,1,0,1,1,1,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0},/*07*/
{0,1,1,1,0,1,0,1,1,1,1,0,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,1,1,1,1,1,1,0,0,0,0,1,0,0},/*08*/
{0,0,0,0,0,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,1,1,1,1,0,0},/*09*/
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} /*20*/
};
int i,j;
while(1)
{
D2();
for(i=0;i<20;i++)
{
gotoxy(10,5+i);
for(j=0;j<60;j++)
{
if(Map[i][j]==0)
printf("#");
if(Map[i][j]==1)
printf(" ");
if(Map[i][j]==2)
printf(" ");
}
}
if(Map[y-5][x-10]==2)
{
clrscr();
Map3();
exit();
}
gotoxy(x,y);
printf("*\b");
Key=GetKey();
if(Key==LEFT&&Map[y-5][x-1-10]!=0)
x--;
if(Key==RIGHT&&Map[y-5][x+1-10]!=0)
x++;
if(Key==UPPER&&Map[y-1-5][x-10]!=0)
y--;
if(Key==DOWN&&Map[y+1-5][x-10]!=0)
y++;
if(Key==ESC)
{
clrscr();
gameover();
break;
}
clrscr();
}
getch();
}
Map1()
{
int Key,x=11,y=6;
int Map[20][60]={ /*第一個[]高,第二個[]寬*/
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,1,0,1,1,1,1,1,0,1,0,0},/*17*/
{0,1,0,0,0,0,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1,1,0,1,0,0,1,0,0,1,0,1,0,0,1,1,1,1,0,0,0,0,1,1,1,0,1,0,0,1,0,0,1,1,2},/*18*/
{0,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,0,1,0,0,1,1,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,1,1,1,0,0,1,1,1,0,0,0},/*19*/
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} /*20*/
};
int i,j;
while(1)
{
D1();
for(i=0;i<20;i++)
{
gotoxy(10,5+i);
for(j=0;j<60;j++)
{
if(Map[i][j]==0)
printf("#");
if(Map[i][j]==1)
printf(" ");
if(Map[i][j]==2)
printf(" ");
}
}
if(Map[y-5][x-10]==2)
{
clrscr();
Map2();
exit();
}
gotoxy(x,y);
printf("*\b");
Key=GetKey();
if(Key==LEFT&&Map[y-5][x-1-10]!=0)
x--;
if(Key==RIGHT&&Map[y-5][x+1-10]!=0)
x++;
if(Key==UPPER&&Map[y-1-5][x-10]!=0)
y--;
if(Key==DOWN&&Map[y+1-5][x-10]!=0)
y++;
if(Key==ESC)
{
clrscr();
gameover();
break;
}
clrscr();
}
getch();
}
main()
{
show();
printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
if(getchar()=='y')
{clrscr();
Map1();
}
else
exit();
}