C++#include<bits/stdc++.h>
#include<windows.h>
#include<cstring>
#include<conio.h>
#include<stdio.h>
/*
+--+
/ /|
+--+ +--+
| |/ /|
+--+--+ +
|##| |/
+--+--+
*/
using namespace std;
/*
0 空气
1 普通方块
*/
int Pos(long x,long y)
{
HANDLE direct=GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos={x,y};
SetConsoleCursorPosition(direct,pos);
}
int main()
{
// system("mode con cols=20 lines=5");
// system("mode con cols=40 lines=10");
// system("mode con cols=60 lines=15");
// system("mode con cols=80 lines=20");
// system("mode con cols=100 lines=25");
// system("mode con cols=120 lines=30");
// system("mode con cols=140 lines=35");
// system("mode con cols=160 lines=40");
// system("mode con cols=180 lines=45");
// system("mode con cols=200 lines=50");
system("mode con cols=200 lines=57");
string pin[200+1];
pin[0]="空 ";
pin[1]="橡原木 ";
pin[2]="云杉原木 ";
pin[3]="白桦原木 ";
pin[4]="丛林原木 ";
pin[5]="金合欢原木 ";
pin[6]="深色像原木 ";
pin[7]="白色混凝土 ";
pin[8]="橡木木板 ";
pin[9]="云杉木木板 ";
pin[10]="白桦木木板 ";
pin[11]="丛林木木板 ";
pin[12]="金合欢木木板";
pin[13]="深色像木木板";
pin[14]="橡木台阶 ";
pin[15]="云杉木台阶 ";
pin[16]="白桦木台阶 ";
pin[17]="丛林木台阶 ";
pin[18]="金合欢木台阶";
pin[19]="深色像木台阶";
int wu[9+1]={0,1,2,3,4,5,6,7,11,18},wupin=0,fx=0;
int xx,yy;
int size=150;
int ch,x=size/2,y=size/2,h=2,k=0;
int map[150+1][150+1][20+1]={{{0}}};
char coutm[150*2+1][150*3+1],cm[32][82];
for(int i=1;i<=31;i++) for(int j=1;j<=81;j++) cm[i][j]='a';
for(int i=1;i<=size;i++)
{
for(int j=1;j<=size;j++)
{
for(int k=1;k<=20;k++)
{
map[i][j][k]=0;
}
}
}
for(int i=1;i<=size;i++)
{
for(int j=1;j<=size;j++)
{
map[i][j][1]=1;
}
}
map[75][76][2]=1;
//开始
for(;;)
{
ch=_getch();
if(ch==119)
{
if(map[x-1][y][h]==0 && x>1)
{
x--;
}
else if(map[x-1][y][h]!=0 && map[x-1][y][h+1]==0)
{
x--;
h++;
}
}
else if(ch==115)
{
if(map[x+1][y][h]==0 && x<size)
{
x++;
}
else if(map[x+1][y][h]!=0 && map[x+1][y][h+1]==0)
{
x++;
h++;
}
}
else if(ch==97)
{
if(map[x][y-1][h]==0 && y>0)
{
y--;
}
else if(map[x][y-1][h]!=0 && map[x][y-1][h+1]==0)
{
y--;
h++;
}
}
else if(ch==100)
{
if(map[x][y+1][h]==0 && y<size)
{
y++;
}
else if(map[x][y+1][h]!=0 && map[x][y+1][h+1]==0)
{
y++;
h++;
}
}
if(ch==32)
{
if(map[x][y][h+1]==0) h++;
fx=1;
}
else if(ch==9)
{
if(map[x][y][h-1]==1) fx=0;
else h--;
}
if(ch>=48 && ch<=57)
{
k=ch-48;
}
if(ch==105)
{
map[x-1][y][h]=wu[k];
}
else if(ch==107)
{
map[x+1][y][h]=wu[k];
}
else if(ch==106)
{
map[x][y-1][h]=wu[k];
}
else if(ch==108)
{
map[x][y+1][h]=wu[k];
}
else if(ch==117)
{
system("cls");
int mc=7;
int m=1;
for(;;)
{
system("cls");
for(int i=mc+7;i>mc-7;i--)
{
if(i>=1 && i<=200) cout<<i<<" "<<pin[i];
if(i==mc) cout<<" <<<<";
cout<<endl<<endl<<endl;
}
cout<<endl<<endl;
cout<<wu[m]<<endl<<endl;
for(int i=1;i<=m;i++) cout<<" ";
cout<<"==============";
for(int i=k;i<10;i++) cout<<" ";
cout<<endl;
for(int i=0;i<=9;i++)
{
cout<<" "<<pin[wu[i]]<<" ";
}
cout<<" 确定"<<endl;
for(int i=1;i<=m;i++) cout<<" ";
cout<<"==============";
for(int i=k;i<10;i++) cout<<" ";
cout<<endl;
cout<<" 0 1 2 3 4 5 6 7 8 9"<<endl;
cout<<endl<<" ←a d→ Enter=确定"<<endl<<endl;
cout<<" u=退出"<<endl;
Pos(30,10);
cout<<"↑";
Pos(30,11);
cout<<"i";
Pos(30,14);
cout<<"k";
Pos(30,15);
cout<<"↓";
ch=_getch();
if(ch==97)
{
if(m>1) m--;
}
if(ch==100)
{
if(m<9) m++;
}
if(ch==13)
{
wu[m]=mc;
}
if(ch==105)
{
if(mc<200) mc++;
}
if(ch==107)
{
if(mc>1) mc--;
}
if(ch==117)
{
break;
}
}
system("cls");
for(int i=1;i<=31;i++) for(int j=1;j<=81;j++) cm[i][j]=' ';
}
if(fx==0)
{
for(int i=h;i>=1;i--)
{
h=i;
if(map[x][y][h-1]!=0) break;
}
}
for(int i=1;i<=size*2;i++)
{
for(int j=1;j<=size*3;j++)
{
coutm[i][j]=' ';
}
}
for(int i=1;i<=size;i++)
{
for(int j=1;j<=size;j++)
{
for(int k=2;k<=20;k++)
{
xx=1+(i-1)*2-k*2;
yy=1+(j-1)*3-i*2;
if(i==x && j==y && k==h)
{
coutm[1+(x-1)*2-h*2][1+(y-1)*3-x*2+1]='R';
}
else if(map[i][j][k]>=1 && map[i][j][k]<=6)
{
coutm[xx][yy-1]='|';
coutm[xx][yy+2]='|';
coutm[xx-1][yy]='-';
coutm[xx-1][yy+1]='-';
coutm[xx+1][yy]='-';
coutm[xx+1][yy+1]='-';
coutm[xx-1][yy-1]='+';
coutm[xx-1][yy+2]='+';
coutm[xx+1][yy-1]='+';
coutm[xx+1][yy+2]='+';
coutm[xx-2][yy]='/';
coutm[xx-2][yy+3]='/';
coutm[xx][yy+3]='/';
coutm[xx-3][yy+1]='+';
coutm[xx-3][yy+2]='-';
coutm[xx-3][yy+3]='-';
coutm[xx-3][yy+4]='+';
coutm[xx-2][yy+4]='|';
coutm[xx-1][yy+4]='+';
coutm[xx][yy+3]='/';
coutm[xx][yy]='@';
coutm[xx][yy+1]='@';
coutm[xx-2][yy+1]='@';
coutm[xx-2][yy+2]='@';
coutm[xx-1][yy+3]='@';
}
else if(map[i][j][k]==7)
{
coutm[xx][yy-1]='|';
coutm[xx][yy+2]='|';
coutm[xx-1][yy]='-';
coutm[xx-1][yy+1]='-';
coutm[xx+1][yy]='-';
coutm[xx+1][yy+1]='-';
coutm[xx-1][yy-1]='+';
coutm[xx-1][yy+2]='+';
coutm[xx+1][yy-1]='+';
coutm[xx+1][yy+2]='+';
coutm[xx-2][yy]='/';
coutm[xx-2][yy+3]='/';
coutm[xx][yy+3]='/';
coutm[xx-3][yy+1]='+';
coutm[xx-3][yy+2]='-';
coutm[xx-3][yy+3]='-';
coutm[xx-3][yy+4]='+';
coutm[xx-2][yy+4]='|';
coutm[xx-1][yy+4]='+';
coutm[xx][yy+3]='/';
coutm[xx][yy]=' ';
coutm[xx][yy+1]=' ';
coutm[xx-2][yy+1]=' ';
coutm[xx-2][yy+2]=' ';
coutm[xx-1][yy+3]=' ';
}
else if(map[i][j][k]>=8 && map[i][j][k]<=13)
{
coutm[xx][yy-1]='|';
coutm[xx][yy+2]='|';
coutm[xx-1][yy]='-';
coutm[xx-1][yy+1]='-';
coutm[xx+1][yy]='-';
coutm[xx+1][yy+1]='-';
coutm[xx-1][yy-1]='+';
coutm[xx-1][yy+2]='+';
coutm[xx+1][yy-1]='+';
coutm[xx+1][yy+2]='+';
coutm[xx-2][yy]='/';
coutm[xx-2][yy+3]='/';
coutm[xx][yy+3]='/';
coutm[xx-3][yy+1]='+';
coutm[xx-3][yy+2]='-';
coutm[xx-3][yy+3]='-';
coutm[xx-3][yy+4]='+';
coutm[xx-2][yy+4]='|';
coutm[xx-1][yy+4]='+';
coutm[xx][yy+3]='/';
coutm[xx][yy]='-';
coutm[xx][yy+1]='-';
coutm[xx-2][yy+1]='/';
coutm[xx-2][yy+2]='/';
coutm[xx-1][yy+3]='|';
}
else if(map[i][j][k]>=14 && map[i][j][k]<=19)
{
/*
+--+
/ /+
+--+/
+--+
*/
coutm[xx+1][yy-1]='+';
coutm[xx+1][yy]='-';
coutm[xx+1][yy+1]='-';
coutm[xx+1][yy+2]='+';
coutm[xx][yy-1]='+';
coutm[xx][yy]='-';
coutm[xx][yy+1]='-';
coutm[xx][yy+2]='+';
coutm[xx][yy+3]='/';
coutm[xx-1][yy]='/';
coutm[xx-1][yy+1]=' ';
coutm[xx-1][yy+2]=' ';
coutm[xx-1][yy+3]='/';
coutm[xx-1][yy+4]='+';
coutm[xx-2][yy+1]='+';
coutm[xx-2][yy+2]='-';
coutm[xx-2][yy+3]='-';
coutm[xx-2][yy+4]='+';
}
}
}
}
Pos(1,1);
// cout<<x<<","<<y<<","<<h<<endl;
printf("%3d,%3d,%2d\n",x,y,h);
for(int i=(1+(x-1)*2-h*2+1)-15,j=1;i<=(1+(x-1)*2-h*2+1)+15,j<=31;i++,j++)
{
for(int k=(1+(y-1)*3-x*2)-40,l=1;k<=(1+(y-1)*3-x*2)+40,l<=81;k++,l++)
{
if(cm[j][l]!=coutm[i][k])
{
Pos(l,j);
cout<<coutm[i][k];
}
}
}
for(int i=(1+(x-1)*2-h*2+1)-15,j=1;i<=(1+(x-1)*2-h*2+1)+15,j<=31;i++,j++)
{
for(int k=(1+(y-1)*3-x*2)-40,l=1;k<=(1+(y-1)*3-x*2)+40,l<=81;k++,l++)
{
cm[j][l]=coutm[i][k];
}
}
Pos(1,35);
cout<<"==============================================================================================================================================";
Pos(1,36);
for(int i=1;i<=k;i++) cout<<" ";
cout<<"+------------+";
for(int i=k;i<=10;i++) cout<<" ";
Pos(1,38);
for(int i=0;i<=9;i++)
{
if(i==k) cout<<"|"<<pin[wu[i]]<<"|";
else cout<<" "<<pin[wu[i]]<<" ";
}
Pos(1,39);
for(int i=1;i<=k;i++) cout<<" ";
cout<<"+------------+";
for(int i=k;i<=10;i++) cout<<" ";
Pos(1,40);
cout<<" 0 1 2 3 4 5 6 7 8 9 u=...";
Pos(1,43);
cout<<" w i Tab";
Pos(1,44);
cout<<"a s d 控制移动 j k l 控制放置 空格 飞";
Pos(1,45);
}
return 0;
}