#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
//--------隐藏光标-----------
void HideCursor()
{
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
//--------gotoxy函数-----------
void gotoxy(int x,int y)//注意:x为列,y为行
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle,pos);
}
//定义方向
int x=9,y=1,nx,ny;
int dx[3]={-1,0,0};
int dy[3]={0,-1,1};
#define UP 0
#define LEFT 1
#define RIGHT 2
//定义地图
#define tims 5
#define hight 12
#define weight 50
int cf;
string mp[tims][hight][weight]={
{
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█","你"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ","门"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"}
}
,
{
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█","你"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ","门"},
{"█","█","█","█","█"," "," "," "," "," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█"," "," "," "," "," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█"," "," "," "," "," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█"," "," "," "," "," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█"," "," "," "," "," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"}
}
,
{
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█","你"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ","门"},
{"█","█","█","█","█","█"," "," "," "," "," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█","█"," "," "," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█"," "," "," "," "," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█"," "," "," "," "," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█"," "," "," "," "," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"}
}
,
{
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█","你"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ","门"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"," ","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"}
}
,
{
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "},
{"█","你"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ","门"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","×","█"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"},
{"█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█","█"}
}
};
string true_mp[tims][hight][weight];
//定义输赢
void gengxin()
{
for(int k=0;k<tims;k++)
{
for(int i=0;i<hight;i++)
{
for(int j=0;j<weight;j++)
{
true_mp[k][i][j]=mp[k][i][j];
}
}
}
}
string win(int X,int Y)
{
string f;
// 检查是否到达门
if(true_mp[cf][X][Y]=="门")
{
f="win";
}
//检测是否到达陷阱
if(X==11||true_mp[cf][X][Y]=="×")
{
f="lose";
}
return f;
}
bool ffffff;
int main()
{
system("cls"); // 清屏
gengxin();
while(1){
x=6;y=1;cf=0;
gengxin();
while(1)
{
HideCursor();
for(int i=0;i<hight;i++)
{
for(int j=0;j<weight;j++)
{
if(mp[cf][i][j]=="你")
{
mp[cf][i][j]=" ";
}
}
}
mp[cf][x][y]="你";
// 绘制地图
gotoxy(0,0);
for(int i=0;i<hight;i++)
{
for(int j=0;j<weight;j++)
{
cout<<mp[cf][i][j];
}
cout<<endl;
}
// 重力系统
if(x+1<hight && true_mp[cf][x+1][y]!="█")
{
int start;
if(start==0)
{
start=clock();
}
int end=clock();
if(end-start>=300){
mp[cf][x][y]=" ";
start=0;
x++;
mp[cf][x][y]="你";
}
}
//检测异变
if(y==4)
{
cf=1;
}
if(y==7)
{
cf=2;
}
if(y==27)
{
cf=3;
}
if(y==47)
{
cf=4;
}
//判断输赢
string f=win(x,y);
if(f=="win")
{
system("cls");
cout<<"你赢了";
Sleep(1000);
break;
ffffff=false;
}
else if(f=="lose")
{
system("cls");
cout<<"你输了";
Sleep(1000);
break;
ffffff=false;
}
// 处理输入
bool ff;
if(mp[cf][x+1][y]=="█")
{
ff=true;
}
else
{
ff=false;
}
if(kbhit())
{
char way=getch();
int WAY;
bool flag=true;
switch(way){
case ' ':
if(ff==true){
WAY=UP;
ff=false;
}
else
{
flag=false;
}
break;
case 'a':
WAY=LEFT;
break;
case 'd':
WAY=RIGHT;
break;
default:
flag=false;
break;
}
if(flag) {
nx=x+dx[WAY];
ny=y+dy[WAY];
if(nx>=0 && nx<hight && ny>=0 && ny<weight && mp[cf][nx][ny]!="█") {
mp[cf][x][y]=" "; // 清空旧位置
x=nx;
y=ny;
mp[cf][x][y]="你";
f = win(x,y); // 移动后立即判断
}
}
}
}
}
}
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
bool zuobi;
//--------隐藏光标-----------
void HideCursor()
{
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
//--------gotoxy函数-----------
void gotoxy(int x,int y)//注意:x为列,y为行
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle,pos);
}
int x[10]={5,5},y[10]={2,2},nx,ny;
int dx[3]={-1,0,0};
int dy[3]={0,-1,1};
#define UP 0
#define LEFT 1
#define RIGHT 2
#define tims 10
#define hight 10
#define weight 15
#define zongjushu 3
int ju=0,tu=0;
int start;
string mp[][tims][hight][weight]={
{
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," ","门"," ","■"},
{"■"," ","■","■","■","■","■","×","×","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"}
},
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","■","■","■","■","×","×","■","■","■","■","门"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"}
},
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," ","门","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","■","■","■","×","×","■","■","■","■","■","×"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■","▂","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"}
}
,
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," ","门","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," ","▂"," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," ","■"," ","■"},
{"■"," ","■","■","■","×","×","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■","▂","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"}
}
}
,
{
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," ","门","门","门","门","门","门","门","门","门","门"," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"}
}
,
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," ","门","门","门","门","门","门","门","门","门","门"," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"}
}
,
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," ","门","门","门","门","门","门","门","门","门","门"," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"}
}
,
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," ","门","门","门","门","门","门","门","门","门","门"," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"}
}
}
,
{
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," ","门"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"}
}
,
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," ","门"," ","■"},
{"■"," ","■"," "," "," "," "," "," "," "," "," ","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"}
}
,
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," ","■","门"," ","■"},
{"■"," ","■"," ","×","×","×","×","×","×","×","×","■"," ","■"},
{"■"," ","■"," ","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■"," ","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■"," ","■","■","■","■","■","■","■","■","■"," ","■"}
}
,
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," ","×","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","■"," ","■","×","×","×","×","×","门"," ","■"," ","■"},
{"■"," ","■"," ","■","■","■","■","■","■","■"," ","■"," ","■"},
{"■"," "," ","→"," "," "," "," "," "," "," ","←"," ","↑","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"}
}
}
};
//绘制地图
string true_mp[10][tims][hight][weight],gengxin_mp[10][tims][hight][weight];
void print()
{
gotoxy(0,0);
cout<<"第\033[34m"<<ju+1<<"\033[0m局\n";
for(int i=0;i<hight;i++)
{
for(int j=0;j<weight;j++)
{
if(mp[ju][tu][i][j]=="你")
{
cout<<"\033[36m";
}
if(mp[ju][tu][i][j]=="■")
{
cout<<"\033[33m";
}
if(mp[ju][tu][i][j]=="×")
{
cout<<"\033[31m";
}
if(mp[ju][tu][i][j]=="门")
{
cout<<"\033[32m";
}
cout<<mp[ju][tu][i][j];
cout<<"\033[0m";
}
cout<<endl;
}
if(zuobi)
{
cout<<"\n\n\n";
for(int i=0;i<hight;i++)
{
for(int j=0;j<weight;j++)
{
cout<<true_mp[ju][tu][i][j];
}
cout<<"\n";
}
}
}
//更新地图
int z;
void gengxin()
{
z=rand()%10+3;
for(int a=0;a<zongjushu;a++)
{
for(int k=0;k<tims;k++)
{
for(int i=0;i<hight;i++)
{
for(int j=0;j<weight;j++)
{
mp[a][k][i][j]=gengxin_mp[a][k][i][j];
true_mp[a][k][i][j]=mp[a][k][i][j];
}
}
}
}
x[0]=5,y[0]=2;
x[1]=5,y[1]=2;
x[2]=5,y[2]=2;
tu=0,zuobi=false;
system("cls");
}
bool ing=true;
//检测奇怪的东西
void check(int X,int Y)
{
// 检查是否到达门
if(true_mp[ju][tu][X][Y]=="门")
{
system("cls");
cout<<"你赢了";
Sleep(1000);
ju++;
zuobi=false;
tu=0;
if(ju>=zongjushu)
{
system("cls");
cout<<"恭喜你,通过了所有关卡\n";
cout<<"是否重新闯关?\n【Y】是\n【N】否";
char c;
while(1)
{
c=getch();
if(c=='y'||c=='n')
{
break;
}
}
if(c=='y')
{
ju=0;
gengxin();
}
else if(c=='n')
{
ing=false;
}
}
}
//检查是否掉进陷阱
if(true_mp[ju][tu][X][Y]=="×"||X==9)
{
system("cls");
cout<<"你输了";
Sleep(1000);
system("cls");
gengxin();
}
//检测是否碰到“▂”
if(true_mp[ju][tu][X][Y]=="▂")
{
x[ju]-=3;
mp[ju][tu][X][Y]="▂";
}
if(true_mp[ju][tu][X][Y]=="→")
{
true_mp[ju][tu][X][Y]=" ";
y[ju]+=7;
}
if(true_mp[ju][tu][X][Y]=="←")
{
true_mp[ju][tu][X][Y]=" ";
y[ju]-=10;
}
if(true_mp[ju][tu][X][Y]=="↑")
{
true_mp[ju][tu][X][Y]=" ";
for(int i=0;i<7;i++)
{
Sleep(100);
x[ju]--;
if(kbhit())break;
gotoxy(0,11);
cout<<i*100<<"毫秒";
print();
}
}
}
void FALL()
{
if(true_mp[ju][tu][x[ju]+1][y[ju]]=="■")start=0;
if(x[ju]+1<hight && x[ju]+1>0 && true_mp[ju][tu][x[ju]+1][y[ju]]!="■")
{
if(start==0)
{
start=clock();
}
int end=clock();
if(end-start>=300){
mp[ju][tu][x[ju]][y[ju]]=" ";
start=0;
x[ju]++;
mp[tu][ju][x[ju]][y[ju]]="你";
}
}
}
void change()
{
if(ju==0)
{
if(y[ju]<5)
{
tu=0;
}
if(y[ju]==5)
{
tu=1;
}
if(y[ju]==11)
{
tu=2;
}
if(x[ju]==7&&y[ju]==13)
{
tu=3;
}
}
if(ju==2)
{
if(x[ju]==4&&y[ju]==2)
{
tu=1;
}
if(y[ju]==3&&x[ju]!=8)
{
tu=2;
}
if(x[ju]==7&&y[ju]==1)
{
tu=3;
}
}
}
int main()
{
system("cls"); // 清屏
for(int a=0;a<zongjushu;a++)
{
for(int i=0;i<tims;i++)
{
for(int j=0;j<hight;j++)
{
for(int k=0;k<weight;k++)
{
gengxin_mp[a][i][j][k]=mp[a][i][j][k];
}
}
}
}
x[0]=5;y[0]=2;
x[1]=5,y[1]=2;
tu=0,ju=0;
gengxin();
while(1)
{
if(!ing){
system("cls");
cout<<"已结束";
return 0;
}
HideCursor();
for(int v=0;v<hight;v++)
{
for(int u=0;u<weight;u++)
{
if(mp[ju][tu][v][u]=="你")
{
mp[ju][tu][v][u]=" ";
}
if(true_mp[ju][tu][v][u]=="你")
{
true_mp[ju][tu][v][u]=" ";
}
}
}
mp[ju][tu][x[ju]][y[ju]]="你";
true_mp[ju][tu][x[ju]][y[ju]]="你";
// 绘制地图
print();
// 重力系统
FALL();
gotoxy(0,0);
//检测异变
change();
//检测
check(x[ju],y[ju]);
//判断是否能跳
bool tiao;
if(mp[ju][tu][x[ju]+1][y[ju]]=="■")
{
tiao=true;
}
else tiao=false;
//处理输入
for(int i=3;i<=12;i++)
{
true_mp[1][0][4][i]="×";
}
true_mp[1][0][4][0]="门";
if(_kbhit())
{
char way=_getch();
int WAY;
string s;
bool flag=true;
switch(tolower(way)) {
case ' ': {
if(tiao)
{
WAY=UP;
tiao=false;
}
else flag=false;
break;
}
case 'a': {
WAY = 1;
break;
}
case 'd': {
WAY = 2;
break;
}
case 'b': {
s = zuobi ? "■" : "×";
mp[ju][tu][x[ju]+1][y[ju]] = s;
true_mp[ju][tu][x[ju]+1][y[ju]] = s;
flag = false;
break;
}
case 'n': {
zuobi = true;
flag = false;
break;
}
case 'm': {
zuobi = false;
flag = false;
gotoxy(0,11);
for(int i=0;i<=15;i++)
cout<<" \n";
break;
}
case 13: { // Enter键
true_mp[ju][tu][x[ju]][y[ju]] = "×";
break;
}
default: {
flag = false;
break;
}
}
if(flag){
nx=x[ju]+dx[WAY];
ny=y[ju]+dy[WAY];
if(nx>=0 && nx<hight && ny>=0 && ny<weight && true_mp[ju][tu][nx][ny]!="■") {
mp[ju][tu][x[ju]][y[ju]]=" "; // 清空旧位置
x[ju]=nx;
y[ju]=ny;
mp[ju][tu][x[ju]][y[ju]]="你";
check(x[ju],y[ju]); // 移动后立即判断
}
}
}
}
}
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
//--------隐藏光标-----------
void HideCursor()
{
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
//--------gotoxy函数-----------
void gotoxy(int x,int y)//注意:x为列,y为行
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle,pos);
}
int x[10]={5},y[10]={2},nx,ny;
int dx[3]={-1,0,0};
int dy[3]={0,-1,1};
#define UP 0
#define LEFT 1
#define RIGHT 2
#define tims 10
#define hight 10
#define weight 15
#define zongjushu 1
int ju=0,tu=0;
string mp[][tims][hight][weight]={
{
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," ","门"," ","■"},
{"■"," ","■","■","■","■","■","×","×","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
},
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","■","■","■","■","×","×","■","■","■","■","门"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
},
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," ","门","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," ","■","■","■","×","×","■","■","■","■","■","×"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■","弹","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
},
{
{"■","■","■","■","■","■","■","■","■","■","■","■","■","■","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," ","门","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," "," "," "," ","弹"," ","■"},
{"■"," ","你"," "," "," "," "," "," "," "," "," ","■"," ","■"},
{"■"," ","■","■","■","×","×","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■","弹","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
{"■"," ","■","■","■","■","■","■","■","■","■","■","■"," ","■"},
},
}
};
string true_mp[10][tims][hight][weight],gengxin_mp[10][tims][hight][weight];
//更新地图
void gengxin()
{
for(int a=0;a<zongjushu;a++)
{
for(int k=0;k<tims;k++)
{
for(int i=0;i<hight;i++)
{
for(int j=0;j<weight;j++)
{
mp[a][k][i][j]=gengxin_mp[a][k][i][j];
true_mp[a][k][i][j]=mp[a][k][i][j];
}
}
}
}
x[0]=5,y[0]=2;
tu=0,ju=0;
}
bool ing=true;
//检测奇怪的东西
void check(int X,int Y)
{
// 检查是否到达门
if(true_mp[ju][tu][X][Y]=="门")
{
system("cls");
cout<<"你赢了";
Sleep(1000);
ju++;
if(ju>=zongjushu)
{
system("cls");
cout<<"恭喜你,通过了所有关卡";
Sleep(1000);
system("cls");
cout<<"是否重新闯关?\n【Y】是\n【N】否";
char c=getch();
if(c!='n')
{
gengxin();
}
else
{
ing=false;
}
}
}
//检查是否掉进陷阱
if(true_mp[ju][tu][X][Y]=="×"||X==9)
{
system("cls");
cout<<"你输了";
Sleep(1000);
gengxin();
}
//检测是否碰到“弹”
if(true_mp[ju][tu][X][Y]=="弹")
{
x[ju]-=3;
mp[ju][tu][X][Y]="弹";
}
}
int main()
{
system("cls"); // 清屏
for(int a=0;a<zongjushu;a++)
{
for(int i=0;i<tims;i++)
{
for(int j=0;j<hight;j++)
{
for(int k=0;k<weight;k++)
{
gengxin_mp[a][i][j][k]=mp[a][i][j][k];
}
}
}
}
x[0]=5;y[0]=2;
tu=0,ju=0;
gengxin();
while(1)
{
if(!ing){
system("cls");
cout<<"已结束";
return 0;
}
HideCursor();
for(int i=0;i<hight;i++)
{
for(int j=0;j<weight;j++)
{
if(mp[ju][tu][i][j]=="你")
{
mp[ju][tu][i][j]=" ";
}
}
}
mp[ju][tu][x[ju]][y[ju]]="你";
// 绘制地图
gotoxy(0,0);
for(int i=0;i<hight;i++)
{
for(int j=0;j<weight;j++)
{
cout<<mp[ju][tu][i][j];
}
cout<<endl;
}
// 重力系统
if(x[ju]+1<hight && x[ju]+1>0 && true_mp[ju][tu][x[ju]+1][y[ju]]!="■")
{
int start;
if(start==0)
{
start=clock();
}
int end=clock();
if(end-start>=300){
mp[ju][tu][x[ju]][y[ju]]=" ";
start=0;
x[ju]++;
mp[tu][ju][x[ju]][y[ju]]="你";
}
}
//检测异变
if(ju==0)
{
if(y[ju]<5)
{
tu=0;
}
if(y[ju]==5)
{
tu=1;
}
if(y[ju]==11)
{
tu=2;
}
if(x[ju]==7&&y[ju]==13)
{
tu=3;
}
}
//检测
check(x[ju],y[ju]);
//判断是否能跳
bool tiao;
if(mp[ju][tu][x[ju]+1][y[ju]]=="■")
{
tiao=true;
}
else tiao=false;
//处理输入
if(kbhit())
{
char way=getch();
int WAY;
bool flag=true;
switch(way){
case ' ':
if(tiao)
{
WAY=UP;
tiao=false;
}
else flag=false;
break;
case 'a':
WAY=LEFT;
break;
case 'd':
WAY=RIGHT;
break;
default:
flag=false;
break;
}
if(flag){
nx=x[ju]+dx[WAY];
ny=y[ju]+dy[WAY];
if(nx>=0 && nx<hight && ny>=0 && ny<weight && mp[ju][tu][nx][ny]!="■") {
mp[ju][tu][x[ju]][y[ju]]=" "; // 清空旧位置
x[ju]=nx;
y[ju]=ny;
mp[ju][tu][x[ju]][y[ju]]="你";
check(x[ju],y[ju]); // 移动后立即判断
}
}
}
}
}