《Go Away》
一个自创的迷宫游戏。
这不是一般的迷宫游戏,你不能走你走过的路,因为你后面有一个人在追你,如果你走进了死路,你就over了。
游戏各方面还不全面,敬请评论。
代码如下:
#include<iostream>
#include<cstring>
#include<conio.h>
using namespace std;
const int maxn=10;
int x_player,y_player;
int x_police,y_police;
int i,j;
char move_player;
bool ground[maxn][maxn];
bool went[maxn][maxn];
bool game;
int go;
void first()
{
game=true;
go=20;
x_player=2;
y_player=2;
x_police=1;
y_police=2;
memset(ground,true,sizeof(ground));
ground[1][2]=true;
ground[10][9]=true;
ground[3][3]=false;
ground[3][4]=false;
ground[3][5]=false;
ground[3][5]=false;
ground[3][6]=false;
ground[3][7]=false;
ground[3][8]=false;
ground[4][6]=false;
ground[5][4]=false;
ground[5][6]=false;
ground[5][7]=false;
ground[5][8]=false;
ground[5][9]=false;
ground[6][2]=false;
ground[6][4]=false;
ground[6][6]=false;
ground[7][4]=false;
ground[7][9]=false;
ground[8][4]=false;
ground[8][5]=false;
ground[8][6]=false;
ground[8][7]=false;
ground[9][7]=false;
for(i=1;i<=10;i++)
for(j=1;j<=10;j++)
{
if((i==1&&j==2)||(i==10&&j==9))
continue;
if(i>1&&i<10&&j>1&&j<10)
continue;
else
ground[i][j]=false;
}
}
void map()
{
system("cls");
cout<<"Your score: "<<go<<endl;
for(i=1;i<=10;i++)
{
for(j=1;j<=10;j++)
{
if(i==x_player&&j==y_player)
cout<<'@';
else if(i==x_police&&j==y_police)
cout<<'&';
else
{
if(ground[i][j]==false)
cout<<'#';
else
cout<<' ';
}
}
cout<<endl;
}
}
void move()
{
if(kbhit())
{
move_player=getch();
if(move_player=='w')
{
if(ground[x_player-1][y_player]==false) move();
else if(x_player-1==x_police&&y_player==y_police) move();
else
{
x_police=x_player;
y_police=y_player;
x_player--;
go--;
}
}
else if(move_player=='s')
{
if(ground[x_player+1][y_player]==false) move();
else if(x_player+1==x_police&&y_player==y_police) move();
else
{
x_police=x_player;
y_police=y_player;
x_player++;
go--;
}
}
else if(move_player=='a')
{
if(ground[x_player][y_player-1]==false) move();
else if(x_player==x_police&&y_player-1==y_police) move();
else
{
x_police=x_player;
y_police=y_player;
y_player--;
go--;
}
}
else if(move_player=='d')
{
if(ground[x_player][y_player+1]==false) move();
else if(x_player==x_police&&y_player+1==y_police) move();
else
{
x_police=x_player;
y_police=y_player;
y_player++;
go--;
}
}
map();
}
}
void die()
{
bool lost=true;
if(ground[x_player-1][y_player]==true&&(x_player-1!=x_police||y_player!=y_police))
lost=false;
if(ground[x_player+1][y_player]==true&&(x_player+1!=x_police||y_player!=y_police))
lost=false;
if(ground[x_player][y_player-1]==true&&(x_player!=x_police||y_player-1!=y_police))
lost=false;
if(ground[x_player][y_player+1]==true&&(x_player!=x_police||y_player+1!=y_police))
lost=false;
if(lost==true||go==0)
{
cout<<"Welcome to police station!"<<endl;
game=false;
}
}
void win()
{
if(x_player==10&&y_player==9)
{
cout<<"You win!"<<endl;
game=false;
}
}
int main()
{
int a;
cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
cout<<"$ ##### # $"<<endl;
cout<<"$ # # # ### $"<<endl;
cout<<"$ # ## ### # # # # # # # # $"<<endl;
cout<<"$ # # # # ##### # # # ### # # $"<<endl;
cout<<"$ ##### ### # # # # ### ### $"<<endl;
cout<<"$ # $"<<endl;
cout<<"$ ### $"<<endl;
cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
cout<<" Made by Peter Winchester"<<endl;
cout<<endl;
cout<<" You are a criminal, a policeman"<<endl;
cout<<"is running after you. You have to"<<endl;
cout<<"leave this house before the police-"<<endl;
cout<<"man catches you."<<endl;
cout<<" The @ is you and the & is the"<<endl;
cout<<"policeman."<<endl;
cout<<" Use a, s, d, w to move."<<endl;
cout<<" Can you go away?"<<endl;
cout<<" Please input 1 to start game."<<endl;
cin>>a;
if(a==1)
{
first();
map();
while(game==true)
{
move();
win();
if(game==true) die();
}
}
cout<<"Game over!";
return 0;
} 


SHEIN希音公司福利 284人发布