当前位置:首页 » 《随便一记》 » 正文

C++还原经典游戏----推箱子_zzr17147的博客

29 人参与  2022年03月06日 16:32  分类 : 《随便一记》  评论

点击全文阅读


老样子,直接上代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<windows.h>
#include<conio.h>
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<<Chinese[i]<<Chinese[i+1];
Sleep(50);
}
system("cls");
}
system("cls");
}
int main(){
system("color 6");
print();
while(true)
{
bool p=false;
main_print();
while(game<=10)
{
map_print();
while(total!=all[game-1])
{
move();
if(p==true)
break;
}
if(p==true)
break;
MAX[game]=max(MAX[game],step);
b[game]=true;
total=0;
step=0;
game++;
}
}
return 0; 
}


点击全文阅读


本文链接:http://zhangshiyu.com/post/35841.html

主菜  接上  老样子  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1