[分享] 迷宫小游戏源代码
程序代码!#include"stdio.h"
#include"bios.h"
#include "conio.h"
#include "dos.h"
#include
#include
#define LEFT 75 /*左方向键的宏定义*/
#define RIGHT 77 /*右方向键的宏定义*/
#define UPPER 72 /*上方向键的宏定义*/
#define DOWN 80 /*下方向键的宏定义*/
#define ESC 27 /*ESC键的宏定义 */
void putchxy(int y,int x,char ch,char fc,char bc);
int djs()
{
int i,x=0,y=0;
printf("\n\t\t\tJu Li Tui Chu Shi Jian:"); /*游戏结束的倒记时6秒钟*/
for(i=6;i>=0;i--)
{
sleep(1);
printf("%d\b",i);
if(i==0)
exit(); /*结束时间*/
}
}
/*
void show()
{
textcolor(GREEN);
printf("\n\n\n\n\n\n\n\t\t ");
cprintf("********************************");
printf("\n\t\t "); /*游戏开始界面以及判断是否进入游戏*/
cprintf("* Huan Ying Play Mi Gong!!!*");
printf("\n\t\t ");
cprintf("* Maker:Lihong *");
printf("\n\t\t ");
cprintf("********************************");
printf("\n\t\t ");
cprintf(" Are You Ready ");
printf("\n\n\t\t ");
cprintf(" 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();
}
union keyboard /*定义读取键盘码的共用体类型*/
{
int KeyIn;
char KeyBit;
};
int GetKey() /*定义读取键盘码的函数*/
{
union keyboard unKey1; /*定义读取键盘码的共用体变量*/
unKey1.KeyIn=bioskey(0); /*读取按键信息*/
return(unKey1.KeyBit==0?unKey1.KeyBit:unKey1.KeyBit); /*返回ASCII码或扩
}
char far *screen=(char far* )0xb8000000;
void putchxy(int y,int x,char ch,char fc,char bc)/*写屏函数,刚学会的*/
{
screen[(x*160)+(y<<1)+0]=ch;
screen[(x*160)+(y<<1)+1]=(bc*16)+fc;
}
void printwall(int x,int y)
{
putchxy(x,y,100,GREEN,GREEN);
}
int Tong()
{
clrscr();
printf("\n\n\n\n\n\n\t\t\tGong Xi Ni Tong Guan!!!\n");
printf("\n\n\t\t\tChong Xin Kai Shi?\n\n\t\t\t\t y/n?\n\n"); /*游戏通关界面以及判断是否继续*/
printf("\t\t\t\t ");
if(getchar()=='Y'||getchar()=='y')
{clrscr();
Map1();
}
else
exit();
}
int Map3() /*第三关的地图*/
{
char Humen=2;
int Key,x=22,y=12;
int Map={ /*第一個[]高,第二個[]寬*/
{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},/*1*/
{0,1,1,1,1,1,0,1,0,0,1,1,1,0,0,0,1,1,1,0,0,1,0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,1,1,0,0,0,0,0,1,1,1,0,0,1,0,0,1,1,1,1,0,0},/*2*/
{0,1,0,0,0,1,0,1,0,0,1,0,1,0,0,0,1,0,1,0,1,1,1,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,1,0,1,1,1,1,1,1,0,1,0,0,0,1,1,1,0,0,1,1,0},/*3*/
{0,1,0,1,0,1,0,1,0,0,1,0,1,0,0,1,1,0,1,1,0,0,0,0,1,1,0,1,0,1,1,1,1,0,0,1,0,1,0,1,0,1,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,0,0},/*4*/
{0,1,1,1,0,1,0,1,0,0,1,0,1,0,1,1,0,0,0,0,1,1,1,0,1,0,1,1,0,0,1,0,0,1,1,1,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,1,1,0,1,0,1,1,0},/*5*/
{0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,0,1,1,1,0,1,0,1,1,0,1,1,1,0,1,1,1,0,0,0,0,1,1,0,1,1,1,0,1,1,0,1,0,0,1,0,1,0,1,0,0,0,0},/*6*/
{0,1,0,1,0,1,1,1,1,0,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1,0,1,1,0,1,0,1,0,0,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,1,1,0,0,1,0,0,0,1,0,1,0,1,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)
{
for(i=0;i<20;i++)
{
gotoxy(10,5+i);
for(j=0;j<60;j++)
{
if(Map==0)
printwall(j+9,i+4);
if(Map==1)
printf(" ");
if(Map==2)
printf(" ");
}
}
if(Map==2)
{
clrscr();
Tong();
}
gotoxy(x,y);
printf("%c\b",Humen);
Key=GetKey();
if(Key==LEFT&&Map!=0)
x--;
if(Key==RIGHT&&Map!=0)
x++;
if(Key==UPPER&&Map!=0)
y--;
if(Key==DOWN&&Map!=0)
y++;
if(Key==ESC)
{
clrscr();
gameover();
break;
}
clrsc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0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,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)
{
for(i=0;i<20;i++)
{
gotoxy(10,5+i);
for(j=0;j<60;j++)
{
if(Map==0)
printwall(j+9,i+4);
if(Map==1)
printf(" ");
if(Map==2)
printf(" ");
}
}
if(Map==2)
{
clrscr();
Map3();
exit();
}
gotoxy(x,y);
printf("%c\b",Humen);
Key=GetKey();
if(Key==LEFT&&Map!=0)
x--;
if(Key==RIGHT&&Map!=0)
x++;
if(Key==UPPER&&Map!=0)
y--;
if(Key==DOWN&&Map!=0)
y++;
if(Key==ESC)
{
clrscr();
gameover();
break;
}
clrscr();
}
getch();
}
Map1() /*第一关的地图*/
{
char Humen=2;
int Key,x=11,y=6; /*x,y为人物移动后坐标*/
int Map={ /*第一個[]高,第二個[]寬*/ /*用二维数组定义地图*/
{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,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表示墙1表示路2表示出口*/
int i,j;
while(1) /*反复进行求移动的坐标运算*/
{
for(i=0;i<20;i++) /*输出新地图*/
{
gotoxy(10,5+i);
for(j=0;j<60;j++)
{
if(Map==0)
printwall(j+9,i+4);
if(Map==1)
printf(" "); /*0,1,2分别用#," "," "符号代替*/
if(Map==2)
printf(" ");
}
}
if(Map==2)
{ /*如果人的坐标和目标坐标重合就进入下一关*/
clrscr();
Map2();
exit();
}
gotoxy(x,y);
textcolor(YELLOW); /*在起始(或移动后)的坐标输出人*/
cprintf("%c\b",Humen); /*人物用"*"号表示,并且光标退一格*/
Key=GetKey(); /*按读取的按键信息改变坐标如果改变的坐标和0重合则不改变*/
if(Key==LEFT&&Map!=0)
x--;
if(Key==RIGHT&&Map!=0)
x++;
if(Key==UPPER&&Map!=0)
y--;
if(Key==DOWN&&Map!=0)
y++; /*判断按ESC键句输出结束界面并退出游戏*/
if(Key==ESC)
{
clrscr();
gameover();
break;
}
clrscr();
}
getch();
}
main()
{
show(); /*调用游戏开始界面*/
printf("\b\b\b\b\b\b\b\b\b\b\b\b");
if(getchar()=='y') /*进行判断是否进入游戏*/
{clrscr(); /*如果选y则进入游戏反之结束游戏退出*/
Map1();
}
else
exit();
} 顶~~感觉算法最难 同感,算法很难呀! 谁无聊的,拿这个代码稍微修改一下,就是一个CrackMe。 超人
看来我要无聊一下了 :(eew没激情了
改这个还不如重写 什么游戏来的?
页:
[1]