上期我们讲了推箱子小游戏,这期我们应粉丝要求更新了推箱子小游戏
烦死了,这玩意更新啥我都不知道
V2.0更新内容:
1.更新了关卡(目前只有两关)
2.优化了地图输出方式
3.添加了标题
4.添加了加载进度条
关卡
其实就是将命名字符变量a时独立再创建一个整数函数去判断你要选哪一个地图再去更改数组内容和,然后再将游戏环节也单独放在一个函数里面
地图输出方式
其实就是将puts这种不大稳定的方式改成了两重嵌套for加上printf,再将算法优化
添加了标题
用system函数title命名exe窗口本地临时管理员权限命名
添加了加载进度条
用for加上Sleep的形式简单的做了一个加载进度条,但是在加载同时也会去设定变量
最重要的环节,大家喜欢看的,总代码!V2.0版本!
#include <iostream>
#include <cstring>
#include <windows.h>
#include <conio.h>
#include <cstdio>
using namespace std;
int gk=1;
int bj=11;
char b;
int x = 3, y = 2;
int main();
char a[11][11]=
{
"##########",
"## ##",
"## ## N ##",
"# o #",
"# # ### #",
"### #X #",
"##########"
};
int game()
{
Sleep(1000);
system("cls");
system("color 06");
while(true)
{
system("cls");
//for(int i = 0; i < 10; i++)
//{
// puts(a[i]);
//}
for (int i=0;i<10;i++)
{
for (int j=0;j<10;j++)
{
printf("%c",a[i][j]);
}
printf("\n");
}
printf("你是‘o’,你要把箱子(‘N’)推到放箱子的地点(‘X’)!");//往上按‘w’,往下按‘s’,往左按‘a’,往右按‘d’,请用英文输入!
printf("往上按‘w’,往下按‘s’,往左按‘a’,往右按‘d’,请用英文输入!");
b = getch();
if(b == 'w') {
if(a[x - 1][y] != '#')
{
if(a[x - 1][y] == 'N')
{
if(a[x - 2][y] != '#')
{
a[x - 2][y] = 'N';
a[x][y] = ' ';
x--;
a[x][y] = 'o';
}
}
else
{
a[x][y] = ' ';
x--;
a[x][y] = 'o';
}
}
}
if(b == 's') {
if(a[x + 1][y] != '#') {
if(a[x + 1][y] == 'N')
{
if(a[x + 2][y] != '#')
{
a[x + 2][y] = 'N';
a[x][y] = ' ';
x++;
a[x][y] = 'o';
}
}
else {
a[x][y] = ' ';
x++;
a[x][y] = 'o';
}
}
}
if(b == 'a') {
if(a[x][y - 1] != '#')
{
if(a[x][y - 1] == 'N')
{
if(a[x][y - 2] != '#')
{
a[x][y - 2] = 'N';
a[x][y] = ' ';
y--;
a[x][y] = 'o';
}
}
else {
a[x][y] = ' ';
y--;
a[x][y] = 'o';
}
}
}
if(b == 'd') {
if(a[x][y + 1] != '#') {
if(a[x][y + 1] == 'N')
{
if(a[x][y + 2] != '#')
{
a[x][y + 2] = 'N';
a[x][y] = ' ';
y++;
a[x][y] = 'o';
}
}
else
{
a[x][y] = ' ';
y++;
a[x][y] = 'o';
}
}
}
if(a[5][6] == ' ') a[5][6]='X';
if(a[5][6] == 'N')
{
system("cls");
system("color 07");
cout << "恭喜你挑战成功!" << endl;
getch();
return 0;
}
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
if(a[i][j] == 'N')
{
if(a[i - 1][j] == '#' && a[i][j + 1] == '#')
{
system("cls");
for (int i=0;i<10;i++)
{
for (int j=0;j<10;j++)
{
printf("%c",a[i][j]);
}
printf("\n");
}
Sleep(3000);
system("cls");
system("color 07");
cout << "你输了,箱子进入了死角!" << endl;
getch();
return 0;
}
if(a[i - 1][j] == '#' && a[i][j - 1] == '#')
{
system("cls");
for (int i=0;i<10;i++)
{
for (int j=0;j<10;j++)
{
printf("%c",a[i][j]);
}
printf("\n");
}
Sleep(3000);
system("cls");
system("color 07");
cout << "你输了,箱子进入了死角!" << endl;
getch();
return 0;
}
if(a[i + 1][j] == '#' && a[i][j - 1] == '#')
{
system("cls");
for (int i=0;i<10;i++)
{
for (int j=0;j<10;j++)
{
printf("%c",a[i][j]);
}
printf("\n");
}
Sleep(3000);
system("cls");
system("color 07");
cout << "你输了,箱子进入了死角!" << endl;
getch();
return 0;
}
if(a[i + 1][j] == '#' && a[i][j + 1] == '#')
{
system("cls");
for(int i = 0; i < 10; i++) puts(a[i]);
Sleep(3000);
system("cls");
system("color 07");
cout << "你输了,箱子进入了死角!" << endl;
getch();
return 0;
}
}
}
}
}
return 0;
}
int dt(int sum)
{
if(sum==1)
{
char a[11][11]=
{
"##########",
"## ##",
"## ## N ##",
"# o #",
"# # ### #",
"### #X #",
"##########"
};
x = 3;
y = 2;
game();
}
else if (sum==2)
{
char a[11][11]=
{
"##########",
"# #",
"# ### N #",
"#o# #",
"# # ######",
"### X #",
"##########"
};
x = 3;
y = 1;
game();
}
}
int main()
{
system("title 推箱子小游戏");
cout << "欢迎来到推箱子游戏!" << endl;
printf("请选择关卡:(1-废铁,2-青铜):");
scanf("%d",&gk);
cout << "加载中。。。" << endl;
for (int i=1;i<=10;i++)
{
printf("■");
Sleep(250);
}
printf("\n");
printf("加载成功!\n");
switch(gk)
{
case 1:bj=11;dt(1);
case 2:bj=11;dt(2);
}
}