#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
#define red SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); //红色
#define green SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
#define nop SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY); //原色
#define white SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); //白色
#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
int wi, wj;
int sum = 1;
int game_num = 1;
struct node{
int x, y;
}bg[]={{0, 0}, {6, 7}, {6, 7}, {6, 7}, {8, 11}, {8, 11}, {8, 11}, {8, 11}, {8, 11}, {8, 11}, {10, 21}, {10, 21}, {10, 21}, {10, 21}};
int bx[]={0, 1, 1, 2, 2, 2, 2, 3, 3, 5, 3, 10, 17, 9};
char op;
int player_i, player_j;
int vis[1010][1010];
map<int, vector<string> > mp=
{
{1, {
"wwwwwwwww",
"wwwwwwwww",
"www ww",
"ww e ww",
"ww b ww",
"ww p ww",
"wwwwwwwww",
"wwwwwwwww"}},
{2, {
"wwwwwwwww",
"wwwwwwwww",
"wwww eww",
"ww www",
"ww b ww",
"www p ww",
"wwwwwwwww",
"wwwwwwwww"}},
{3, {
"wwwwwwwww",
"wwwwwwwww",
"wwe eww",
"ww www",
"ww b b ww",
"www p ww",
"wwwwwwwww",
"wwwwwwwww"}},
{4, {
"wwwwwwwwwwwww",
"wwwwwwwwwwwww",
"wwewe ww",
"ww ww b ww",
"ww w ww",
"ww ww b ww",
"ww w ww",
"ww pw ww",
"wwwwwwwwwwwww",
"wwwwwwwwwwwww"}},
{5, {
"wwwwwwwwwwwww",
"wwwwwwwwwwwww",
"wwe eww",
"wwwww wwwwww",
"ww w ww",
"ww b wb ww",
"wwwwww ww",
"wwp ww",
"wwwwwwwwwwwww",
"wwwwwwwwwwwww"}},
{6, {
"wwwwwwwwwwwww",
"wwwwwwwwwwwww",
"wwp w ww",
"ww w b ww",
"ww w ww",
"ww e w ww",
"ww w b ww",
"wwe w ww",
"wwwwwwwwwwwww",
"wwwwwwwwwwwww"}},
{7, {
"wwwwwwwwwwwww",
"wwwwwwwwwwwww",
"wwp ww ww",
"ww eww b ww",
"ww eww b ww",
"ww eww b ww",
"ww ww",
"ww ww",
"wwwwwwwwwwwww",
"wwwwwwwwwwwww"}},
{8, {
"wwwwwwwwwwwww",
"wwwwwwwwwwwww",
"wwe eww",
"ww wwwww ww",
"ww w b ww",
"ww bb w ww",
"ww wwwww ww",
"wwe pww",
"wwwwwwwwwwwww",
"wwwwwwwwwwwww"}},
{9, {
"wwwwwwwwwwwww",
"wwwwwwwwwwwww",
"ww ww",
"ww b ww",
"wwb ee bb ww",
"ww ee ww",
"ww b ww",
"ww pww",
"wwewwwwwwwwww",
"wwwwwwwwwwwww"}},
{10, {
"wwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwww",
"wwe b w ww",
"ww w ww",
"wwwwwwwwrwwww ww",
"ww w e ww",
"ww w ww",
"wwe w r b ww",
"ww w b w ww",
"ww w w pww",
"wwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwww"}},
{11, {
"wwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwww",
"ww wew wew wew wew weww",
"ww wbw wbw wbw wbw wbww",
"ww w w w w w w w w w ww",
"ww r r r r r r r r r ww",
"ww w w w w w w w w w ww",
"ww w w w w w w w w w ww",
"wwbw wbw wbw wbw wbw ww",
"wwew wew wew wew wewpww",
"wwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwww"}},
{12, {
"wwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwww",
"ww eeeeeeeeeeeeeeeee ww",
"ww ww",
"ww ww",
"wwwww wwwww",
"ww ww",
"ww ww",
"ww bbbbbbbbbbbbbbbbb ww",
"ww pww",
"wwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwww"}},
{13, {
"wwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwww",
"wweeee e r eww",
"ww w ww",
"wwbbbbb w bww",
"ww wwwwwwww ww",
"wwwwwrww wwrwwwww",
"ww w ww",
"ww w ww",
"ww e b web pww",
"wwwwwwwwwwwwwwwwwwwwwww"}},
};
char gt[1010][1010]={
"#######################",
"#_____________________#",
"#| | | | | | | | | | |#",
"#######################"
};
int gt_top = 0;
int game_mulu[20]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
string mulu[100]{
" ++=========推箱子2.1.3=========++",
"",
" -> 选择关卡 按↑(w)和↓(s)选择项目, ",
" 游戏规则 按空格键确认。 ",
" 退出游戏"
};
string geng[100]={
"++======================================++",
"||推箱子2.1.3版本更新通知: ||",
"||囊括2.1.2版本所有功能, ||",
"||在2.1.2版本的基础上增加了游戏规则 ||",
"||敬请期待3.0版本的更新!!! ||",
"++======================================++"
};
class Point: public COORD
{
public:
Point(int X=0,int Y=0)
{
this->X=Y; this->Y=X;
}
};
void hideCursor(){
HANDLE sreen=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(sreen, &CursorInfo);
CursorInfo.bVisible = false;
SetConsoleCursorInfo(sreen, &CursorInfo);
}
void gotoxy(int x,int y)
{
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Point(x,y));
}
int sui(){
int x = rand();
return x%10;
}
void clear(){
for(int i = 0; i <= 50; i++){
gotoxy(i, 0);
cout << " ";
}
gotoxy(0, 0);
}
void lode(){
gotoxy(0, 0);
cout << "正在加载地图...\n";
cout << "----------------------------------------------------------------------------------------------------\n";
gotoxy(3, 0);
cout << "----------------------------------------------------------------------------------------------------";
int x = 0;
while(x < 100){
gotoxy(2, x);
green
cout << "▉";
Sleep(sui());
x++;
white
gotoxy(0, 20);
cout << "(" << x << " %)";
}
Sleep(sui()*20);
white
clear();
}
void printm(){
for(int i = 0; i < 5; i++){
gotoxy(i, 0);
cout << mulu[i] << endl;
}
for(int i = 0; i < 6; i++){
gotoxy(i+6, 0);
cout << geng[i] << endl;
}
}
void printgm(){
system("cls");
white
cout << "选择关卡\n";
for(int i = 1; i <= 13; i++){
if(i%5 == 1){
cout << "\n\n";
}
cout << setw(5);
if(i == game_num){
red
}else{
white
}
cout << game_mulu[i];
}
cout << endl << endl;
cout << " 按 z 键返回主菜单";
}
void init(){
for(int i = 1; i <= wi; i++){
for(int j = 1; j <= wj; j++){
gotoxy(i, j-1);
if(mp[game_num][i][j] == 'w'){
printf("#");
}else if(mp[game_num][i][j] == 'e'){
printf("O");
}else if(mp[game_num][i][j] == 'b'){
printf("·");
}else if(mp[game_num][i][j] == 'p'){
printf("@");
player_i = i;
player_j = j;
}else if(mp[game_num][i][j] == ' '){
printf(" ");
}else if(mp[game_num][i][j] == 'f'){
printf("0");
}else if(mp[game_num][i][j] == 'q'){
cout << "%";
}else if(mp[game_num][i][j] == 'r'){
cout << "Q";
}else if(mp[game_num][i][j] == 'F'){
cout << "F";
}
}
cout << endl;
}
}
bool check(){
int x = 0;
for(int i = 1; i <= wi; i++){
for(int j = 1; j <= wj; j++){
if(mp[game_num][i][j] == 'f'){
if(vis[i][j] == 0){
for(int l = wj; l >= 1; l--){
int f = 0;
for(int k = wi; k >= 1; k--){
if(mp[game_num][k][l] == 'r'){
mp[game_num][k][l] = ' ';
f = 1;
break;
}
}
if(f){
break;
}
}
}
x++;
vis[i][j] = 1;
}
if(mp[game_num][i][j] == 'F'){
}
}
}
if(x == bx[game_num]){
return true;
}
return false;
}
void move(int x, int y){
if(mp[game_num][player_i+x][player_j+y] == ' '){
mp[game_num][player_i+x][player_j+y] = 'p';
mp[game_num][player_i][player_j] = ' ';
player_i = player_i+x;
player_j = player_j+y;
}else if(mp[game_num][player_i+x][player_j+y] == 'b'){
if(mp[game_num][player_i+2*x][player_j+2*y] == 'w'){
}else if(mp[game_num][player_i+2*x][player_j+2*y] == 'e'){
mp[game_num][player_i+2*x][player_j+2*y] = 'f';
mp[game_num][player_i+x][player_j+y] = 'p';
mp[game_num][player_i][player_j] = ' ';
player_i = player_i+x;
player_j = player_j+y;
}else if(mp[game_num][player_i+2*x][player_j+2*y] == 'b'){
if(mp[game_num][player_i+3*x][player_j+3*y] == 'w'){
}else if(mp[game_num][player_i+3*x][player_j+3*y] == 'e'){
mp[game_num][player_i+3*x][player_j+3*y] = 'f';
mp[game_num][player_i+2*x][player_j+2*y] = 'b';
mp[game_num][player_i+x][player_j+y] = 'p';
mp[game_num][player_i][player_j] = ' ';
player_i = player_i+x;
player_j = player_j+y;
}else if(mp[game_num][player_i+3*x][player_j+3*y] == 'b'){
}else{
mp[game_num][player_i+3*x][player_j+3*y] = 'b';
mp[game_num][player_i+2*x][player_j+2*y] = 'b';
mp[game_num][player_i+x][player_j+y] = 'p';
mp[game_num][player_i][player_j] = ' ';
player_i = player_i+x;
player_j = player_j+y;
}
}else if(mp[game_num][player_i+2*x][player_j+2*y] == 'f'){
if(mp[game_num][player_i+3*x][player_j+3*y] == 'w'){
}else if(mp[game_num][player_i+3*x][player_j+3*y] == 'e'){
mp[game_num][player_i+3*x][player_j+3*y] = 'f';
mp[game_num][player_i+2*x][player_j+2*y] = 'f';
mp[game_num][player_i+x][player_j+y] = 'p';
mp[game_num][player_i][player_j] = ' ';
player_i = player_i+x;
player_j = player_j+y;
}else if(mp[game_num][player_i+3*x][player_j+3*y] == 'b'){
}else{
mp[game_num][player_i+3*x][player_j+3*y] = 'b';
mp[game_num][player_i+2*x][player_j+2*y] = 'f';
mp[game_num][player_i+x][player_j+y] = 'p';
mp[game_num][player_i][player_j] = ' ';
player_i = player_i+x;
player_j = player_j+y;
}
}else{
mp[game_num][player_i+2*x][player_j+2*y] = 'b';
mp[game_num][player_i+x][player_j+y] = 'p';
mp[game_num][player_i][player_j] = ' ';
player_i = player_i+x;
player_j = player_j+y;
}
}else if(mp[game_num][player_i+x][player_j+y] == 'e'){
mp[game_num][player_i+x][player_j+y] = 'q';
mp[game_num][player_i][player_j] = ' ';
player_i = player_i+x;
player_j = player_j+y;
}else if(mp[game_num][player_i+x][player_j+y] == 'f'){
if(mp[game_num][player_i+2*x][player_j+2*y] == 'w'){
}else{
mp[game_num][player_i+2*x][player_j+2*y] = 'b';
mp[game_num][player_i+x][player_j+y] = 'q';
mp[game_num][player_i][player_j] = ' ';
player_i = player_i+x;
player_j = player_j+y;
}
}else if(mp[game_num][player_i][player_j] == 'q'){
if(mp[game_num][player_i+x][player_j+y] == ' '){
mp[game_num][player_i+x][player_j+y] = 'p';
mp[game_num][player_i][player_j] = 'e';
player_i = player_i+x;
player_j = player_j+y;
}else if(mp[game_num][player_i+x][player_j+y] == 'b'){
if(mp[game_num][player_i+2*x][player_j+2*y] == 'w'){
}else if(mp[game_num][player_i+2*x][player_j+2*y] == 'e'){
mp[game_num][player_i+2*x][player_j+2*y] = 'f';
mp[game_num][player_i+x][player_j+y] = 'p';
mp[game_num][player_i][player_j] = 'e';
player_i = player_i+x;
player_j = player_j+y;
}else if(mp[game_num][player_i+2*x][player_j+2*y] == 'b'){
if(mp[game_num][player_i+3*x][player_j+3*y] == 'w'){
}else if(mp[game_num][player_i+3*x][player_j+3*y] == 'e'){
mp[game_num][player_i+3*x][player_j+3*y] = 'f';
mp[game_num][player_i+2*x][player_j+2*y] = 'b';
mp[game_num][player_i+x][player_j+y] = 'p';
mp[game_num][player_i][player_j] = 'e';
player_i = player_i+x;
player_j = player_j+y;
}else if(mp[game_num][player_i+3*x][player_j+3*y] == 'b'){
}else{
mp[game_num][player_i+3*x][player_j+3*y] = 'b';
mp[game_num][player_i+2*x][player_j+2*y] = 'b';
mp[game_num][player_i+x][player_j+y] = 'p';
mp[game_num][player_i][player_j] = 'e';
player_i = player_i+x;
player_j = player_j+y;
}
}else{
mp[game_num][player_i+2*x][player_j+2*y] = 'b';
mp[game_num][player_i+x][player_j+y] = 'p';
mp[game_num][player_i][player_j] = 'e';
player_i = player_i+x;
player_j = player_j+y;
}
}else if(mp[game_num][player_i+x][player_j+y] == 'e'){
mp[game_num][player_i+2*x][player_j+2*y] = 'q';
mp[game_num][player_i+x][player_j+y] = 'e';
player_i = player_i+x;
player_j = player_j+y;
}else if(mp[game_num][player_i+x][player_j+y] == 'f'){
if(mp[game_num][player_i+2*x][player_j+2*y] == 'w'){
}else{
mp[game_num][player_i+2*x][player_j+2*y] = 'b';
mp[game_num][player_i+x][player_j+y] = 'q';
mp[game_num][player_i][player_j] = 'e';
player_i = player_i+x;
player_j = player_j+y;
}
}
}else if(mp[game_num][player_i+x][player_j+y] == 'F'){
gt_top++;
gt[2][gt_top*2] = 'F';
mp[game_num][player_i+x][player_j+y] = 'p';
mp[game_num][player_i][player_j] = ' ';
player_i = player_i+x;
player_j = player_j+y;
}
}
void game_on(){
hideCursor();
while(1){
wi = bg[game_num].x;
wj = bg[game_num].y;
gotoxy(0, 0);
cout << "level " << game_num << endl;
init();
if(kbhit()){
char ch = getch();
switch(ch){
case 'w': case 'W': case 72:
move(-1, 0); break;
case 's': case 'S': case 80:
move(1, 0); break;
case 'a': case 'A': case 75:
move(0, -1); break;
case 'd': case 'D': case 77:
move(0, 1); break;
}
}else{
if(check()){
int back = 0;
memset(vis, 0, sizeof(vis));
game_num++;
clear();
gotoxy(2, 10);
cout << "你赢了";
gotoxy(3, 10);
cout << "是否继续游戏";
Sleep(1000);
gotoxy(4, 5);
cout << "按 任意 键继续游戏, 按 空格 键返回菜单";
while(!back){
if(kbhit()){
int op = getch();
switch(op){
case ' ':
back = 1;
return ;
default:
clear();
lode();
game_on();
break;
}
}
}
}
}
}
}
void on();
void game(){
system("cls");
printgm();
while(1){
if(kbhit()){
int back = 0;
char ch = getch();
switch(ch){
case 'w': case 'W': case 72:
if(game_num<=5){
break;
}
game_num-=5; break;
case 's': case 'S': case 80:
if(game_num>=9){
break;
}
game_num+=5; break;
case 'a': case 'A': case 75:
if(game_num==1){
break;
}
game_num--; break;
case 'd': case 'D': case 77:
if(game_num==13){
break;
}
game_num++; break;
case ' ':
clear();
gotoxy(3, 10);
cout << "开始游戏";
Sleep(1000);
gotoxy(4, 5);
cout << "按 任意 键继续游戏, 按 空格 键返回菜单";
while(!back){
if(kbhit()){
int op = getch();
switch(op){
case ' ':
back = 1;
break;
default:
clear();
lode();
game_on();
}
}
}
if(back == 1){
break;
}
case 'z':
clear();
on();
return ;
}
printgm();
}
}
}
void gui(){
clear();
cout << "推箱子规则: \n";
cout << "----------------------------------------------------------------\n";
cout << "本游戏由 Jackie_chen 制作\n";
cout << "# 为墙壁 不可通过\n";
cout << "@ 是玩家 ↑(w) ↓(s) ←(a) →(d) 控制方向\n";
cout << "O 是终点 把所有箱子推进终点即可获胜\n";
cout << ". 是箱子\n";
cout << "\n";
cout << " 按 z 退出";
while(true){
if(kbhit()){
char op = getch();
switch(op){
case 'z':
clear();
on();
return ;
}
}
}
}
void on(){
srand(time(0));
hideCursor();
printm();
while(1){
int f = 0;
if(kbhit()){
char ch = getch();
switch(ch){
case 'w': case 'W': case 72:
if(sum == 1){
break;
}
mulu[sum+1][15] = mulu[sum+1][16] = ' ';
mulu[sum][15] = '-';
mulu[sum][16] = '>';
printm();
sum--;
break;
case 's': case 'S': case 80:
if(sum == 3){
break;
}
mulu[sum+1][15] = mulu[sum+1][16] = ' ';
mulu[sum+2][15] = '-';
mulu[sum+2][16] = '>';
printm();
sum++;
break;
case ' ':
f = 1;
break;
}
}
if(f == 1){
break;
}
}
if(sum == 1){
game();
}else if(sum == 2){
gui();
}else if(sum == 3){
system("cls");
gotoxy(5, 30);
cout << "Game Over!!\n";
Sleep(3000);
return ;
}
}
int main(){
on();
}
/*
++======================================++
|| ||
|| ||
|| ||
|| ||
++======================================++
*/
1 个赞
大佬666
1 个赞
还有1.0
2.0
2.1
2.1.1
2.1.2
2.1.4
1 个赞
2.1.4还没修复好
1 个赞
有3.0吗
还没有
本蚂蚁发现有个地方多了个逗号,应该是字符串定义中一处的末尾!(我不是血红林蚁,你可以当我是火蚁!)