You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

316 lines
6.3 KiB

6 years ago
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<windows.h>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define M 100
#define N 100
#define Road 1
#define Wall 0
#define Des 3
#define Player 4
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
COORD coord; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>*/
short map[N][M];/*<2A><>ͼ */
int x,y;/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
int m=21,n=21;/*ʵ<>ʵ<EFBFBD>ͼ<EFBFBD><CDBC>С */
int flag; /*
<EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>
1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ
3<EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><EFBFBD><EFBFBD>Ϸ
*/
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void mune();
void print();
void Print(char);
void up();
void down();
void right();
void left();
void gotc();
void Map_1();
void xy();
void HideCursor();
void chu();
char des(int,int);
void dig(char,int,int);
void make(int,int);
void CreateMaze();
void win();
void end();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int main()
{
HideCursor();
system("title <20>Թ<EFBFBD><D4B9><EFBFBD>Ϸ");
flag=0;
while(1){
if(flag==0) mune();
if(flag==1){
coord.X = 2;
coord.Y = 1;
xy(); //<2F><><EFBFBD><EFBFBD>Ļָ<C4BB><D6B8>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼλ<CABC><CEBB>
if(n==21) system("mode con cols=42 lines=22");
else if(n==31) system("mode con cols=62 lines=32");
else if(n==41) system("mode con cols=82 lines=42");
print(n,m);
gotc();
}
if(flag==2){
win();
flag=0;
}
if(flag==3){
end();
break;
}
}
return 0;
}
6 years ago
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void print()/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
{
system("color F5");
system("cls");
int i,j;
for(i=0;i<n;i++){
for(j=0;j<m;j++)
{
if(map[i][j]==Road) printf(" "); /*1 ·*/
else if(map[i][j]==Wall) printf("<EFBFBD><EFBFBD>");/*0 ǽ*/
else if(map[i][j]==Des) printf("<EFBFBD><EFBFBD>");/*3 <20>յ<EFBFBD>*/
else if(map[i][j]==Player) printf("<EFBFBD><EFBFBD>");/*4 <20><><EFBFBD><EFBFBD>*/
}
printf("\n");
}
}
/*<2A><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>*/
void up()
{
if(map[x-1][y]==3) flag=2;
if(map[x-1][y]==1){
xy(x,y);
printf(" ");
map[x-1][y]=4;
map[x][y]=1;
x--;
coord.Y--; xy();
printf("<EFBFBD><EFBFBD>");
}
}
void down()
{
if(map[x+1][y]==3) flag=2;
if(map[x+1][y]==1){
xy(x,y);
printf(" ");
map[x+1][y]=4;
map[x][y]=1;
x++;
coord.Y++; xy();
printf("<EFBFBD><EFBFBD>");
}
}
void right()
{
if(map[x][y+1]==3) flag=2;
if(map[x][y+1]==1){
xy(x,y);
printf(" ");
map[x][y+1]=4;
map[x][y]=1;
y++;
coord.X+=2; xy();
printf("<EFBFBD><EFBFBD>");
}
}
6 years ago
void left()
{
if(map[x][y-1]==3) flag=2;
if(map[x][y-1]==1){
xy(x,y);
printf(" ");
map[x][y-1]=4;
map[x][y]=1;
y--;
coord.X-=2; xy();
printf("<EFBFBD><EFBFBD>");
}
}
/*<2A><><EFBFBD>˵<EFBFBD>*/
void mune()
{
system("color F6");
system("mode con cols=50 lines=15");
x=1;y=1; flag=0;
system("cls");
printf("\n\n\n <20>Թ<EFBFBD><D4B9><EFBFBD>Ϸ\n\n");
printf(" <20><><EFBFBD>˵<EFBFBD>\n");
printf(" 1:<3A><><EFBFBD><EFBFBD><EFBFBD>Ѷ<EFBFBD> {<7B>Ѷȵȼ<C8B5>:1(Ĭ<><C4AC>)/2/3}\n");
printf(" 2:<3A><>ʼ<EFBFBD><CABC>Ϸ\n");
printf(" 3:<3A>˳<EFBFBD><CBB3><EFBFBD>Ϸ\n");
printf(" 0:<3A>˻ز˵<D8B2>\n");
printf("\nTips:\n<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>Ӣ<EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>)<29><><EFBFBD><EFBFBD> <20><>Ϸ<EFBFBD>лص<D0BB><D8B5>˵<EFBFBD><CBB5><EFBFBD><EFBFBD>ϵ<EFBFBD>\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>WASD<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD> <20><>:<3A><><EFBFBD><EFBFBD> <20><>:<3A>յ<EFBFBD>") ;
while(1){
switch(getch())
{
case '3': flag=3;break;
case '2': CreateMaze();flag=1;break;
default: break;
case '1':{
coord.X = 0;
coord.Y = 14;
xy();printf(" ");
xy();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѷȣ<EFBFBD>");
switch(getch()){
case '1':n=21; m=21;printf("<EFBFBD>Ѷȵȼ<EFBFBD>1<EFBFBD>޸ijɹ<EFBFBD><EFBFBD><EFBFBD>");break;
case '2':n=31; m=31;printf("<EFBFBD>Ѷȵȼ<EFBFBD>2<EFBFBD>޸ijɹ<EFBFBD><EFBFBD><EFBFBD>");break;
case '3':n=41; m=41;printf("<EFBFBD>Ѷȵȼ<EFBFBD>3<EFBFBD>޸ijɹ<EFBFBD><EFBFBD><EFBFBD>");break; //...
default: printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>");
}
break;
}
}
if(flag==1||flag==2||flag==3) break;
}
}
6 years ago
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
void gotc()
{
while(1)
{
flag=1;
switch(getch())
{
case '*': flag=4;break;
case '3': flag=3;break;
case '0': flag=0;break;
case 'w':case 'W': Print('w');break;
case 'a':case 'A': Print('a');break;
case 's':case 'S': Print('s');break;
case 'd':case 'D': Print('d');break;
}
if(flag==0||flag==2||flag==3||flag==4) break;
}
}
/*<2A><><EFBFBD>µ<EFBFBD>ͼ*/
void Print(char d)
{
xy(x,y);
switch(d){
case 'W':case 'w':up();break;
case 'S':case 's':down();break;
case 'A':case 'a':left();break;
case 'D':case 'd':right();break;
}
}
6 years ago
/*<2A><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>*/
void xy(){
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>̨<EFBFBD><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
HANDLE ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
//<2F><><EFBFBD>ù<EFBFBD><C3B9><EFBFBD>λ<EFBFBD><CEBB>
SetConsoleCursorPosition(ConsoleHandle, coord);
}
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļָ<C4BB><D6B8> */
void HideCursor() {
CONSOLE_CURSOR_INFO cursor_info = { 1,0 };
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
void win()
{
system("cls");
system("color 73");
system("mode con cols=38 lines=13");
printf("\n <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> ");
printf("\n <20><> <20><> <20><> <20><> <20><> <20><> ");
printf("\n <20><> <20><> <20><> <20><> <20><> ");
printf("\n <20><> <20><> <20><> <20><> <20><> ");
printf("\n <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \n");
printf("\n <20><> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> ");
printf("\n <20><> <20><> <20><> <20><> <20><><EFBFBD><EFBFBD> <20><> ");
printf("\n <20><> <20><> <20><> <20><> <20><> <20><> <20><> ");
printf("\n <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD> ");
printf("\n <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> ");
system("pause");
}
6 years ago
void end()
{
system("mode con cols=50 lines=15");
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\n\n ллʹ<D0BB>ã<EFBFBD>\n\n\n\n");
printf(" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1812<31><32>\n 184018001207\n <20><><EFBFBD><EFBFBD>\n") ;
}
//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ͼ<EFBFBD><CDBC><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD>
/*׼<><D7BC><EFBFBD><EFBFBD><EFBFBD>ɵij<C9B5>ʼ<EFBFBD><CABC>*/
void chu()
{
int i,j;
for(i=0;i<n;i++)for(j=0;j<m;j++){
if(i%2==1&&j%2==1) map[i][j]=1;
else map[i][j]=0;
}
i=rand()%(n-3);
j=rand()%(m-3);
if(i%2==0) i++;
if(j%2==0) j++;
map[i][j]=2;
make(i,j);
}
6 years ago
//<2F>õ<EFBFBD><C3B5><EFBFBD>λ<EFBFBD>ҿ<EFBFBD><D2BF>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ھ<EFBFBD>(<28><><EFBFBD>ھ<EFBFBD><DABE><EFBFBD>)
char des(int x1,int y1)
{
char a[5];
int k=0;
if(x1>1&&map[x1-2][y1]==1) a[k++]='w';
if(x1<n-2&&map[x1+2][y1]==1) a[k++]='s';
if(y1>1&&map[x1][y1-2]==1) a[k++]='a';
if(y1<m-2&&map[x1][y1+2]==1) a[k++]='d';
if(k==0) return 'e';
return a[rand()%k];
}
//<2F><><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD><EFBFBD>ھ<EFBFBD><DABE><EFBFBD>·
void dig(char d,int x2,int y2)
{
switch(d){
case 'w':map[x2-1][y2]=2;map[x2-2][y2]=2;break;
case 's':map[x2+1][y2]=2;map[x2+2][y2]=2;break;
case 'a':map[x2][y2-1]=2;map[x2][y2-2]=2;break;
case 'd':map[x2][y2+1]=2;map[x2][y2+2]=2;break;
}
}
//<2F><><EFBFBD>ɵ<EFBFBD>ͼ<EFBFBD>ĵݹ<C4B5>
void make(int x3,int y3)
{
char d;
while(des(x3,y3)!='e'){
d=des(x3,y3);
dig(d,x3,y3);
switch(d){
case 'w':make(x3-2,y3);break;
case 's':make(x3+2,y3);break;
case 'a':make(x3,y3-2);break;
case 'd':make(x3,y3+2);break;
}
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
void CreateMaze()
{
int i,j;
srand(time(NULL));
chu();
for(i=0;i<n;i++)for(j=0;j<m;j++){
if(i==0||j==0||i==n-1||j==m-1) map[i][j]=Wall;
if(map[i][j]==2) map[i][j]=Road;
}
map[1][1]=Player;
map[n-2][m-2]=Des;
}