IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> C++还原经典游戏----推箱子 -> 正文阅读

[C++知识库]C++还原经典游戏----推箱子

老样子,直接上代码:

#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; 
}

  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2021-10-03 16:54:12  更:2021-10-03 16:55:15 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年12日历 -2024/12/29 3:54:41-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码
数据统计