游戏|C++还原经典游戏----推箱子
老样子,直接上代码:
#include
#include
#include
#include
#include
using namespace std;
bool b[101];
int MAX[101],step;
char map[101][101][101]={
{" ######"," #....#","###ZZZ.#","#H.Z**.#","#.Z***##","####..# "," #### "},
{" #### #####","##..# #...#","#.Z.####Z..#","#..Z****.Z.#","##....#.H.##"," ########## "},
{" ##### ","###..H# ","#..Z*.##","#..*Z*.#","###.ZZ.#"," #...##"," ##### "},
{" #### "," #**# "," ##.*## "," #..Z*# ","##.Z..##","#..#ZZ.#","#..H...#","########"},
{"########","#..#...#","#.Z**Z.#","#HZ*Z.##","#.Z**Z.#","#..#...#","########"},
{" ###### ","##....##","#.Z.ZZ.#","#******#","#.ZZ.Z.#","###.H###"," #### "},
{" ###### "," #....###"," #.Z....#","###.Z.##.#","#***.Z...#","#***Z#Z.##","####.#.Z.#"," #...H.#"," #######"},
{"###### ","#....# ","#.ZZZ## ","#..#**###","##..**Z.#"," #.H....#"," ########"},
{" ########"," #...#*.#"," ##..Z***#"," #..Z.#Z*#","##.##Z#.##","#...Z..Z.#","#...#....#","#######H.#"," ####"},
{" ####### "," #****.# ","###***Z###","#..Z#Z.Z.#","#.ZZ..#Z.#","#....#...#","####.H.###"," ##### "}};
char MAP[101][101][101]={
{" ######"," #....#","###ZZZ.#","#H.Z**.#","#.Z***##","####..# "," #### "},
{" #### #####","##..# #...#","#.Z.####Z..#","#..Z****.Z.#","##....#.H.##"," ########## "},
{" ##### ","###..H# ","#..Z*.##","#..*Z*.#","###.ZZ.#"," #...##"," ##### "},
{" #### "," #**# "," ##.*## "," #..Z*# ","##.Z..##","#..#ZZ.#","#..H...#","########"},
{"########","#..#...#","#.Z**Z.#","#HZ*Z.##","#.Z**Z.#","#..#...#","########"},
{" ###### ","##....##","#.Z.ZZ.#","#******#","#.ZZ.Z.#","###.H###"," #### "},
{" ###### "," #....###"," #.Z....#","###.Z.##.#","#***.Z...#","#***Z#Z.##","####.#.Z.#"," #...H.#"," #######"},
{"###### ","#....# ","#.ZZZ## ","#..#**###","##..**Z.#"," #.H....#"," ########"},
{" ########"," #...#*.#"," ##..Z***#"," #..Z.#Z*#","##.##Z#.##","#...Z..Z.#","#...#....#","#######H.#"," ####"},
{" ####### "," #****.# ","###***Z###","#..Z#Z.Z.#","#.ZZ..#Z.#","#....#...#","####.H.###"," ##### "}};
char under[101][10][2]={
{
{3,4},{5,3},{4,3},{4,4},{5,4}},
{
{4,3},{5,3},{6,3},{7,3}},
{
{4,2},{3,3},{5,3},{4,4}},
{
{3,1},{4,1},{4,2},{5,3}},
{
{3,2},{4,2},{3,3},{4,3},{3,4},{4,4}},
{
{1,3},{2,3},{3,3},{4,3},{5,3},{6,3}},
{
{1,4},{2,4},{3,4},{1,5},{2,5},{3,5}},
{
{4,3},{4,4},{5,4},{5,3}},
{
{7,1},{6,2},{7,2},{8,2},{7,3},{8,3}},
{
{2,1},{3,1},{4,1},{5,1},{3,2},{4,2},{5,2}}};
int zl[4][2]={
{-1,0},{1,0},{0,-1},{0,1}};
int total,game=1,all[101]={5, 4, 4, 4, 6, 6, 6, 4, 6, 7};
char Chinese[]="推箱子游戏正在努力加载中......";
int length[101][2]={
{6,7},
{5,11},
{6,7},
{7,7},
{6,7},
{6,7},
{8,9},
{6,8},
{8,9},
{8,9}};
int x[101]={3, 4, 1, 6, 3, 5, 7, 5, 7, 6};
int y[101]={1,8, 5, 3, 1, 4, 7, 3, 7, 5};
int X[101]={3,4, 1, 6, 3, 5, 7, 5, 7, 6};
int Y[101]={1,8, 5, 3, 1, 4, 7, 3, 7, 5};
char ch;
int way;
void main_print(){
while(true)
{
system("cls");
printf("主菜单\n");
for(int i=1;
i<=10;
i++)
{
if(game==i)
printf(" >> %d关 ",i+9);
else
printf(" %d关 ",i+9);
if(b[i]==true)
printf("已通过 ");
else
printf("未通过 ");
printf("最高纪录:%d步\n",MAX[i]);
}
ch=getch();
if(ch=='s' || ch=='S')
{
if(game<=9)
game++;
}
else if(ch=='w' || ch=='W')
{
if(game>=2)
game--;
}
else if(ch==' ')
break;
}
}
bool check(int i,int j){
for(int number=1;
number<=all[game-1];
number++)
if(under[game-1][number-1][0]==j && under[game-1][number-1][1]==i)
return true;
return false;
}
void OK(){
total=0;
for(int i=0;
i<=length[game-1][0];
i++)
for(int j=0;
j<=length[game-1][1];
j++)
if(check(i,j)==true)
if(map[game-1][i][j]=='Z')
total++;
}
void map_print(){
system("cls");
for(int i=0;
i<=length[game-1][0];
i++)
{
for(int j=0;
j<=length[game-1][1];
j++)
{
if(check(i,j)==true)
{
if(map[game-1][i][j]=='H')
printf("①");
else if(map[game-1][i][j]=='Z')
printf("㊣");
else if(map[game-1][i][j]=='.' || map[game-1][i][j]=='*')
printf("★");
}
else
{
if(map[game-1][i][j]=='H')
printf("①");
else if(map[game-1][i][j]=='Z')
printf("□");
else if(map[game-1][i][j]=='.')
printf(" ");
else if(map[game-1][i][j]=='*')
printf("★");
else if(map[game-1][i][j]=='#')
printf("█");
else if(map[game-1][i][j]==' ')
printf(" ");
}
}
printf("\n");
}
OK();
}
void move(){
ch=getch();
if(ch=='w' || ch=='W')
way=0;
else if(ch=='s' || ch=='S')
way=1;
else if(ch=='a' || ch=='A')
way=2;
else if(ch=='d' || ch=='D')
way=3;
else if(ch==' ')
{
main_print();
return;
}
else
{
for(int i=0;
i<=length[game-1][0];
i++)
strcpy(map[game-1][i],MAP[game-1][i]);
x[game-1]=X[game-1];
y[game-1]=Y[game-1];
step=0;
map_print();
return;
}
if(map[game-1][x[game-1]+zl[way][0]][y[game-1]+zl[way][1]]=='.' || map[game-1][x[game-1]+zl[way][0]][y[game-1]+zl[way][1]]=='*')
{
map[game-1][x[game-1]][y[game-1]]='.';
map[game-1][x[game-1]+zl[way][0]][y[game-1]+zl[way][1]]='H';
x[game-1]+=zl[way][0];
y[game-1]+=zl[way][1];
step++;
}
else if(map[game-1][x[game-1]+zl[way][0]][y[game-1]+zl[way][1]]=='Z' && map[game-1][x[game-1]+zl[way][0]+zl[way][0]][y[game-1]+zl[way][1]+zl[way][1]]!='Z' && map[game-1][x[game-1]+zl[way][0]+zl[way][0]][y[game-1]+zl[way][1]+zl[way][1]]!='#')
{
map[game-1][x[game-1]][y[game-1]]='.';
map[game-1][x[game-1]+zl[way][0]][y[game-1]+zl[way][1]]='H';
map[game-1][x[game-1]+zl[way][0]+zl[way][0]][y[game-1]+zl[way][1]+zl[way][1]]='Z';
x[game-1]+=zl[way][0];
y[game-1]+=zl[way][1];
step++;
}
map_print();
}
void print(){
for(int t=1;
t<=5;
t++)
{
for(int i=0;
Chinese[i];
i+=2)
{
cout<
【游戏|C++还原经典游戏----推箱子】
推荐阅读
- 游戏IP(立足于玩家情感的粉丝经济)
- opencv|opencv C++模板匹配的简单实现
- gitlab|gitlab 通过备份还原 admin/runner 500 Internal Server Error
- 人生游戏--是游戏,还是人生()
- 「按键精灵安卓版」关于全分辨率脚本的一些理解(非游戏app)
- C语言学习|第十一届蓝桥杯省赛 大学B组 C/C++ 第一场
- (小说)月流水几亿的火爆游戏养成记
- 游戏治愈了我无聊之症
- c++基础概念笔记
- 生活与游戏日记(第182篇)(〔成长瞬间〕关注解决问题2019.10)