#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <windows.h>
#include <conio.h>
using namespace std;
char a[25][25] = {"##########",
"# ##",
"# O O##",
"##O#### #",
"# O#",
"# **# O #",
"# **# #",
"##########",
};
void Prepare() {
system("color c1");
HANDLE hOut;
CONSOLE_CURSOR_INFO curInfo;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
curInfo.dwSize = 1;
curInfo.bVisible = 0;
SetConsoleCursorInfo(hOut, &curInfo);
SetConsoleTitle("推箱子(第二关)(照样支持电脑)");
}
void Set() {
HANDLE hOut;
COORD pos = {0, 0};
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
}
void Welcome() {
printf("\n\n 欢迎游玩:");
printf("\n\n 推 箱 子 (第 二 关)");
printf("\n\n 请按任意键开始");
getch();
system("cls");
}
int main() {
Prepare();
Welcome();
int x = 3, y = 2;
char ch;
int cnt = 0;
for (int i = 0; i <= 6; i++)
puts(a[i]);
while (1) {
ch = getch();
if (ch == -32) {
ch = getch();
if (ch == 80) {
if (a[x + 1][y] == ' ') {
a[x][y] = ' ';
x++;
a[x][y] = 'S';
} else if (a[x + 1][y] == 'O') {
if (a[x + 2][y] == ' ') {
a[x][y] = ' ';
x++;
a[x][y] = 'S';
a[x + 1][y] = 'O';
} else if (a[x + 2][y] == '*') {
a[x][y] = ' ';
x++;
a[x][y] = 'S';
a[x + 1][y] = ' ';
cnt++;
}
}
} else if (ch == 72) {
if (a[x - 1][y] == ' ') {
a[x][y] = ' ';
x--;
a[x][y] = 'S';
} else if (a[x - 1][y] == 'O') {
if (a[x - 2][y] == ' ') {
a[x][y] = ' ';
x--;
a[x][y] = 'S';
a[x - 1][y] = 'O';
} else if (a[x - 2][y] == '*') {
a[x][y] = ' ';
x--;
a[x][y] = 'S';
a[x - 1][y] = ' ';
cnt++;
}
}
} else if (ch == 75) {
if (a[x][y - 1] == ' ') {
a[x][y] = ' ';
y--;
a[x][y] = 'S';
} else if (a[x][y - 1] == 'O') {
if (a[x][y - 2] == ' ') {
a[x][y] = ' ';
y--;
a[x][y] = 'S';
a[x][y - 1] = 'O';
} else if (a[x][y - 2] == '*') {
a[x][y] = ' ';
y--;
a[x][y] = 'S';
a[x][y - 1] = ' ';
cnt++;
}
}
} else if (ch == 77) {
if (a[x][y + 1] == ' ') {
a[x][y] = ' ';
y++;
a[x][y] = 'S';
} else if (a[x][y + 1] == 'O') {
if (a[x][y + 2] == ' ') {
a[x][y] = ' ';
y++;
a[x][y] = 'S';
a[x][y + 1] = 'O';
} else if (a[x][y + 2] == '*') {
a[x][y] = ' ';
y++;
a[x][y] = 'S';
a[x][y + 1] = ' ';
cnt++;
}
}
}
}
Set();
for (int i = 0; i <= 6; i++)
puts(a[i]);
if (cnt == 5)
break;
}
printf("恭喜通过了第二关!请开启下个程序,进入第三关!!!");
Sleep(1000);
return 0;
}
推箱子后续