先献上代码:
#include<bits/stdc++.h>
using namespace std;
//变量
const int l=250;
int xl,yl;
int x,y,x_box,y_box,x_Tun,y_Tun;
char I,g[l][l],F;
char gt[l][l];
int _x,_y,_x_box,_y_box;
//准备
void Set(){
for(int i=1;i<=xl;i++){
for(int j=1;j<=yl;j++){
gt[i][j]=':';
}
}
}
void Input(){
for(int i=1;i<=xl;i++){
for(int j=1;j<=yl;j++){
cin>>g[i][j];
if(g[i][j]=='*'){
x_box=i;y_box=j;
gt[i][j]='*';
g[i][j]='.';
}else if(g[i][j]=='@'){
x=i;y=j;
gt[i][j]='@';
g[i][j]='.';
}else if(g[i][j]=='O'){
x_Tun=i;y_Tun=j;
}else{}
}
}
}
//移动
int Move_x(int x_){
if(I=='w') return x_-1;
else if(I=='s') return x_+1;
else return x_;
}
int Move_y(int y_){
if(I=='a') return y_-1;
else if(I=='d') return y_+1;
else return y_;
}
//检测
int Det_key(){
if(I=='w' || I=='a' || I=='s' || I=='d') return 1;
else return 0;
}
char Pull(){
if(x_box+1==x && y_box==y){
return 'w';
}else if(x_box-1==x && y_box==y){
return 's';
}else if(x_box==x && y_box+1==y){
return 'a';
}else if(x_box==x && y_box-1==y){
return 'd';
}else{
return '?';
}
}
int W(){
if(I=='a' || I=='d'){
if(Pull()=='a' || Pull()=='d'){
return 0;
}else{
return 1;
}
}
if(I=='w' || I=='s'){
if(Pull()=='w' || Pull()=='s'){
return 0;
}else{
return 1;
}
}
}
int Wall(){
int nx,ny;
nx=Move_x(x);
ny=Move_y(y);
if(g[nx][ny]=='#' || nx<1 || nx>xl || ny<1 || ny>yl) return 0;
else return 1;
}
int Wall_box(){
int nx=x_box,ny=y_box;
if(W()==0){
nx=Move_x(nx);
ny=Move_y(ny);
}
if(g[nx][ny]=='#' || nx<1 || nx>xl || ny<1 || ny>yl) return 0;
else return 1;
}
bool Win(){
if(x_box==x_Tun && y_box==y_Tun) return true;
else return false;
}
int Ft(){
if(Pull()==I && F!='q') return 0;
else return 1;
}
bool R(){
int p=Wall()+Wall_box()+Det_key()+Ft();
if(p==4) return true;
else return false;
}
//变化
void Draw(){
system("cls");
cout<<"@是你操作的小人\n*是箱子\nO是你的目标\n#是墙\n当输出方向时用wasd\n输出推动时q为推动,e为不推动\n";
for(int i=1;i<=xl;i++){
for(int j=1;j<=yl;j++){
if(gt[i][j]!=':') cout<<gt[i][j];
else cout<<g[i][j];
}
cout<<endl;
}
}
void Change(){
gt[_x_box][_y_box]=':';
gt[_x][_y]=':';
gt[x][y]='@';
gt[x_box][y_box]='*';
}
//3
int main(){
cout<<"@是你操作的小人\n*是箱子\nO是你的目标\n#这个是墙\n当输出方向时用wasd\n输出推动时q为推动,e为不推动\n";
cin>>xl>>yl;
Set();
Input();
do{
do{
Draw();
cout<<"方向:"<<endl;
cin>>I;
cout<<"推动:"<<endl;
cin>>F;
}while(R()==false);
if(W()==0 && F=='q'){
_x_box=x_box;_y_box=y_box;
x_box=Move_x(_x_box);
y_box=Move_y(_y_box);
}
_x=x;x=Move_x(_x);
_y=y;y=Move_y(_y);
Change();
}while(Win()==false);
Draw();
cout<<"胜利!";
return 0;
}
游戏输入的参数依次是是列数、行数、之后是地图
给大家提供一些关卡(建议直接复制)
第一关:新手教程:
1 9
@*......O
第二关:新手教程2:
1 9
O......*@
第三关:大宫殿!!!
5 5
@*...
.....
.....
.....
....O
第四关:这里有根大柱子!
5 5
.....
..#..
..#..
..#..
@*#..
第五关:我怎么在绕圈?
5 8
.......O
..####..
.*####..
..####..
@.......
第六关:误入童话镇
1 15
@*............O
第七关:出现了!九转大肠
10 8
.......O
........
..######
..######
........
........
######..
######..
.......
@*......
第八关:我是荆轲!
6 6
@.....
#####.
......
.#####
..*..O
第九关:这是什么???
2 11
@#...#.....
...#...#.*O
第十关(boss关1):荆轲刺秦王
3 3
@.*
.#.
..O
后续关卡进我主页看更新情况qwq
5358

被折叠的 条评论
为什么被折叠?



