推箱子2.0

#include<bits/stdc++.h>
#include<conio.h>
#include<windows.h>
using namespace std;
int wi, wj;
int game = 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, 8};
char op;
int player_i, player_j;
int vis[1010][1010];
/*
w: #    墙
p: @   玩家
b: .   箱子
e: O   终点
q: %  被玩家
    覆盖的终点
f: 0  被箱子
    覆盖的终点
r: Q    门
F: F   钥匙
K: @  被玩家
    拾取的钥匙
*/
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;
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){
	HANDLE hOut = NULL;
	COORD pos;
	pos.X = x;
	pos.Y = y;
	SetConsoleCursorPosition(hOut, pos);
}
void init(){
	for(int i = 1; i <= wi; i++){
		for(int j = 1; j <= wi; j++){
			gotoxy(i, j);
			if(mp[game][i][j] == 'w'){
				printf("#");
			}else if(mp[game][i][j] == 'e'){
				printf("O");
			}else if(mp[game][i][j] == 'b'){
				printf(".");
			}else if(mp[game][i][j] == 'p'){
				printf("@");
				player_i = i;
				player_j = j;
			}else if(mp[game][i][j] == ' '){
				printf(" ");
			}else if(mp[game][i][j] == 'f'){
				printf("0");
			}else if(mp[game][i][j] == 'q'){
				cout << "%";
			}else if(mp[game][i][j] == 'r'){
				cout << "Q";
			}else if(mp[game][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][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][k][l] == 'r'){
								mp[game][k][l] = ' ';
								f = 1;
								break;
							}
						}
						if(f){
							break;
						}
					}	
				}
				x++;
				vis[i][j] = 1;
			}
			if(mp[game][i][j] == 'F'){
				
			}
		}
	}
	if(x == bx[game]){
		return true;
	}
	return false;
}
void move(int x, int y){
	if(mp[game][player_i+x][player_j+y] == ' '){
		mp[game][player_i+x][player_j+y] = 'p';
		mp[game][player_i][player_j] = ' ';
		player_i = player_i+x;
		player_j = player_j+y;
	}else if(mp[game][player_i+x][player_j+y] == 'b'){
		if(mp[game][player_i+2*x][player_j+2*y] == 'w'){
			
		}else if(mp[game][player_i+2*x][player_j+2*y] == 'e'){
			mp[game][player_i+2*x][player_j+2*y] = 'f';
			mp[game][player_i+x][player_j+y] = 'p';
			mp[game][player_i][player_j] = ' ';
			player_i = player_i+x;
			player_j = player_j+y;
		}else if(mp[game][player_i+2*x][player_j+2*y] == 'b'){
			if(mp[game][player_i+3*x][player_j+3*y] == 'w'){
				
			}else if(mp[game][player_i+3*x][player_j+3*y] == 'e'){
				mp[game][player_i+3*x][player_j+3*y] = 'f';
				mp[game][player_i+2*x][player_j+2*y] = 'b';
				mp[game][player_i+x][player_j+y] = 'p';
				mp[game][player_i][player_j] = ' ';
				player_i = player_i+x;
				player_j = player_j+y;
			}else if(mp[game][player_i+3*x][player_j+3*y] == 'b'){
				
			}else{
				mp[game][player_i+3*x][player_j+3*y] = 'b';
				mp[game][player_i+2*x][player_j+2*y] = 'b';
				mp[game][player_i+x][player_j+y] = 'p';
				mp[game][player_i][player_j] = ' ';
				player_i = player_i+x;
				player_j = player_j+y;
			}
		}else if(mp[game][player_i+2*x][player_j+2*y] == 'f'){
			if(mp[game][player_i+3*x][player_j+3*y] == 'w'){
				
			}else if(mp[game][player_i+3*x][player_j+3*y] == 'e'){
				mp[game][player_i+3*x][player_j+3*y] = 'f';
				mp[game][player_i+2*x][player_j+2*y] = 'f';
				mp[game][player_i+x][player_j+y] = 'p';
				mp[game][player_i][player_j] = ' ';
				player_i = player_i+x;
				player_j = player_j+y;
			}else if(mp[game][player_i+3*x][player_j+3*y] == 'b'){
				
			}else{
				mp[game][player_i+3*x][player_j+3*y] = 'b';
				mp[game][player_i+2*x][player_j+2*y] = 'f';
				mp[game][player_i+x][player_j+y] = 'p';
				mp[game][player_i][player_j] = ' ';
				player_i = player_i+x;
				player_j = player_j+y;
			}
		}else{
			mp[game][player_i+2*x][player_j+2*y] = 'b';
			mp[game][player_i+x][player_j+y] = 'p';
			mp[game][player_i][player_j] = ' ';
			player_i = player_i+x;
			player_j = player_j+y;
		}
	}else if(mp[game][player_i+x][player_j+y] == 'e'){
		mp[game][player_i+x][player_j+y] = 'q';
		mp[game][player_i][player_j] = ' ';
		player_i = player_i+x;
		player_j = player_j+y;
	}else if(mp[game][player_i+x][player_j+y] == 'f'){
		if(mp[game][player_i+2*x][player_j+2*y] == 'w'){
			
		}else{
			mp[game][player_i+2*x][player_j+2*y] = 'b';
			mp[game][player_i+x][player_j+y] = 'q';
			mp[game][player_i][player_j] = ' ';
			player_i = player_i+x;
			player_j = player_j+y;
		}
	}else if(mp[game][player_i][player_j] == 'q'){
		if(mp[game][player_i+x][player_j+y] == ' '){
			mp[game][player_i+x][player_j+y] = 'p';
			mp[game][player_i][player_j] = 'e';
			player_i = player_i+x;
			player_j = player_j+y;
		}else if(mp[game][player_i+x][player_j+y] == 'b'){
			if(mp[game][player_i+2*x][player_j+2*y] == 'w'){
				
			}else if(mp[game][player_i+2*x][player_j+2*y] == 'e'){
				mp[game][player_i+2*x][player_j+2*y] = 'f';
				mp[game][player_i+x][player_j+y] = 'p';
				mp[game][player_i][player_j] = 'e';
				player_i = player_i+x;
				player_j = player_j+y;
			}else if(mp[game][player_i+2*x][player_j+2*y] == 'b'){
				if(mp[game][player_i+3*x][player_j+3*y] == 'w'){
					
				}else if(mp[game][player_i+3*x][player_j+3*y] == 'e'){
					mp[game][player_i+3*x][player_j+3*y] = 'f';
					mp[game][player_i+2*x][player_j+2*y] = 'b';
					mp[game][player_i+x][player_j+y] = 'p';
					mp[game][player_i][player_j] = 'e';
					player_i = player_i+x;
					player_j = player_j+y;
				}else if(mp[game][player_i+3*x][player_j+3*y] == 'b'){
					
					
				}else{
					mp[game][player_i+3*x][player_j+3*y] = 'b';
					mp[game][player_i+2*x][player_j+2*y] = 'b';
					mp[game][player_i+x][player_j+y] = 'p';
					mp[game][player_i][player_j] = 'e';
					player_i = player_i+x;
					player_j = player_j+y;
				}
			}else{
				mp[game][player_i+2*x][player_j+2*y] = 'b';
				mp[game][player_i+x][player_j+y] = 'p';
				mp[game][player_i][player_j] = 'e';
				player_i = player_i+x;
				player_j = player_j+y;
			}
		}else if(mp[game][player_i+x][player_j+y] == 'e'){
			mp[game][player_i+2*x][player_j+2*y] = 'q';
			mp[game][player_i+x][player_j+y] = 'e';
			player_i = player_i+x;
			player_j = player_j+y;
		}else if(mp[game][player_i+x][player_j+y] == 'f'){
			if(mp[game][player_i+2*x][player_j+2*y] == 'w'){
				
			}else{
				mp[game][player_i+2*x][player_j+2*y] = 'b';
				mp[game][player_i+x][player_j+y] = 'q';
				mp[game][player_i][player_j] = 'e';
				player_i = player_i+x;
				player_j = player_j+y;
			}
		}
	}else if(mp[game][player_i+x][player_j+y] == 'F'){
		gt_top++;
		gt[2][gt_top*2] = 'F';
		mp[game][player_i+x][player_j+y] = 'p';
		mp[game][player_i][player_j] = ' ';
		player_i = player_i+x;
		player_j = player_j+y;
	}
}
int main(){
	hideCursor();
	wi = bg[game].x;
	wj = bg[game].y;
	cout << "level " << game << endl;
	init();
	while(true){
		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()){
				memset(vis, 0, sizeof(vis));
				system("cls");
				init();
				game++;
				cout << "\n";
				cout << "win!\n";
				cout << "level " << game;
				sleep(3);
			}
			wi = bg[game].x;
			wj = bg[game].y;
			system("cls");
			cout << "level " << game << endl;
			init();
		}
	}
}

本蚂蚁已召集军团一起推了!