#include<bits/stdc++.h>
#include<unistd.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#include<iostream>
#include<Windows.h>
using namespace std;
long long int world_map[30][30][30],
nventory_article[24],
synthesis_article_n[17][24]={
{0,2,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0},
{0,2,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0},
{0,2,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,2,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0},
{0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0},
{0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0},
{0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0},
{0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3},
{0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
},
synthesis_article_w[17]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4};//0:木镐 1:木斧 2:木剑 3~5:石具 6:木板
int player_x=1,player_y=1,player_z=0;
using namespace std;
void color(int n)//颜色
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), n);
return;
}
void synthesis_article(){
int article_number;
color(15);
cout<<"1:木镐 2:木斧 3:木剑"<<endl<<"4:石镐 5:石斧 6:石剑"<<endl<<"7:铁镐 8:铁斧 9:铁剑"<<endl<<"10:金镐 11:金斧 12:金剑"<<endl<<"13:钻镐 14:钻斧 15:钻剑"<<endl<<"16:木板";
cin>>article_number;
article_number--;
int article_number_i=0;
for(int i=0;i<24;i++){
if(nventory_article[i]>=synthesis_article_n[article_number][i]){
article_number_i++;
}
}
if(article_number_i==12){
for(int i=0;i<24;i++){
nventory_article[i]-=synthesis_article_n[article_number][i];
}
nventory_article[article_number+5]+=synthesis_article_w[article_number];
}else{
cout<<"材料不够";
}
cout<<endl;
sleep(1);
system("cls");
return;
}
void block_excavate(int excavate_x,int excavate_y,int excavate_z){
if(world_map[excavate_y][excavate_x][excavate_z]==1){
if(excavate_z==0){
world_map[excavate_y][excavate_x][excavate_z]=0;
nventory_article[0]+=4;
nventory_article[1]+=3;
nventory_article[2]+=6;
nventory_article[3]+=2;
}
else{
world_map[excavate_y][excavate_x][excavate_z]=-1;
nventory_article[0]+=4;
nventory_article[1]+=3;
nventory_article[2]+=6;
nventory_article[3]+=2;
}
}else if(world_map[excavate_y][excavate_x][excavate_z]==2){
if(nventory_article[5]>0 or nventory_article[8]>0 or nventory_article[11]>0 or nventory_article[14]>0 or nventory_article[17]>0){
if(excavate_z==0){
world_map[excavate_y][excavate_x][excavate_z]=0;
nventory_article[4]+=4;
}else{
world_map[excavate_y][excavate_x][excavate_z]=-1;
nventory_article[4]+=4;
}
}
}else if(world_map[excavate_y][excavate_x][excavate_z]==3){
world_map[excavate_y][excavate_x][excavate_z]=-1;
nventory_article[21]+=1;
}else if(world_map[excavate_y][excavate_x][excavate_z]==4){
world_map[excavate_y][excavate_x][excavate_z]=-1;
nventory_article[22]+=1;
}else if(world_map[excavate_y][excavate_x][excavate_z]==5){
world_map[excavate_y][excavate_x][excavate_z]=-1;
nventory_article[23]+=1;
}
return;
}
void Out_article(int n){
color(15);
if(n==0) cout<<"木头:"<<nventory_article[n];
else if(n==1) cout<<"木棍:"<<nventory_article[n];
else if(n==2) cout<<"树叶:"<<nventory_article[n];
else if(n==3) cout<<"苹果:"<<nventory_article[n];
else if(n==4) cout<<"石头:"<<nventory_article[n];
else if(n==5) cout<<"木镐:"<<nventory_article[n];
else if(n==6) cout<<"木斧:"<<nventory_article[n];
else if(n==7) cout<<"木剑:"<<nventory_article[n];
else if(n==8) cout<<"石镐:"<<nventory_article[n];
else if(n==9) cout<<"石斧:"<<nventory_article[n];
else if(n==10) cout<<"石剑:"<<nventory_article[n];
else if(n==11) cout<<"铁镐:"<<nventory_article[n];
else if(n==12) cout<<"铁斧:"<<nventory_article[n];
else if(n==13) cout<<"铁剑:"<<nventory_article[n];
else if(n==14) cout<<"金镐:"<<nventory_article[n];
else if(n==15) cout<<"金斧:"<<nventory_article[n];
else if(n==16) cout<<"金剑:"<<nventory_article[n];
else if(n==17) cout<<"钻镐:"<<nventory_article[n];
else if(n==18) cout<<"钻斧:"<<nventory_article[n];
else if(n==19) cout<<"钻剑:"<<nventory_article[n];
else if(n==20) cout<<"木板:"<<nventory_article[n];
else if(n==21) cout<<"铁锭:"<<nventory_article[n];
else if(n==22) cout<<"金锭:"<<nventory_article[n];
else if(n==23) cout<<"钻石:"<<nventory_article[n];
return;
}
void world_map_c(){
synthesis_article_n;
int sth=-1;
srand((unsigned int)time(NULL));
for(int k=0;k<30;k++){
for(int i=0;i<30;i++)
for(int j=0;j<30;j++){
if(k==0){
sth=rand()%5;
if(sth<=2){
world_map[i][j][k]=0;
}else if(sth==3){
world_map[i][j][k]=1;
}else{
world_map[i][j][k]=2;
}
}else{
if(world_map[i+1][j][k]==3 or world_map[i-1][j][k]==3 or world_map[i][j+1][k]==3 or world_map[i][j-1][k]==3 or world_map[i][j][k+1]==3 or world_map[i][j][k-1]==3){
sth=rand()%7;
if(sth<=2){
world_map[i][j][k]=2;
}else if(sth==6 or sth==3 and k>=3){
world_map[i][j][k]=3;
}else if(sth==4 and k>=7){
world_map[i][j][k]=4;
}else if(sth==5 and k>=14){
world_map[i][j][k]=5;
}else{
world_map[i][j][k]=2;
}
}else if(world_map[i+1][j][k]==4 or world_map[i-1][j][k]==4 or world_map[i][j+1][k]==4 or world_map[i][j-1][k]==4 or world_map[i][j][k+1]==4 or world_map[i][j][k-1]==4){
sth=rand()%7;
if(sth<=2){
world_map[i][j][k]=2;
}else if(sth==6 and k>=3){
world_map[i][j][k]=3;
}else if(sth==4 or sth==3 and k>=7){
world_map[i][j][k]=4;
}else if(sth==5 and k>=14){
world_map[i][j][k]=5;
}else{
world_map[i][j][k]=2;
}
}else{
sth=rand()%7;
if(sth<=3){
world_map[i][j][k]=2;
}else if(sth==6 and k>=3){
world_map[i][j][k]=3;
}else if(sth==4 and k>=7){
world_map[i][j][k]=4;
}else if(sth==5 and k>=14){
world_map[i][j][k]=5;
}else{
world_map[i][j][k]=2;
}
}
}
}
}
return;
}
void world_map_s(){
for(int i=0;i<30;i++){
for(int j=0;j<30;j++){
if(i==player_y and j==player_x){
color(240);
cout<<"我";
}else if(world_map[i][j][player_z]==0){
color(175);
cout<<"草";
}else if(world_map[i][j][player_z]==1){
color(162);
cout<<"树";
}else if(world_map[i][j][player_z]==2){
color(135);
cout<<"石";
}else if(world_map[i][j][player_z]==3){
color(120);
cout<<"铁";
}else if(world_map[i][j][player_z]==4){
color(230);
cout<<"金";
}else if(world_map[i][j][player_z]==5){
color(185);
cout<<"钻";
}else if(world_map[i][j][player_z]==-1){
color(0);
cout<<" ";
}
}
Out_article(i);
cout<<endl;
}
cout<<endl<<endl;
for(int i=0;i<30;i++){
if(i==player_z){
color(240);
cout<<"我";
}else if(world_map[player_y][player_x][i]==0){
color(175);
cout<<"草";
}else if(world_map[player_y][player_x][i]==1){
color(162);
cout<<"树";
}else if(world_map[player_y][player_x][i]==2){
color(135);
cout<<"石";
}else if(world_map[player_y][player_x][i]==3){
color(120);
cout<<"铁";
}else if(world_map[player_y][player_x][i]==4){
color(230);
cout<<"金";
}else if(world_map[player_y][player_x][i]==5){
color(185);
cout<<"钻";
}else if(world_map[player_y][player_x][i]==-1){
color(0);
cout<<" ";
}
// cout<<endl;
}
color(0);
cout<<' ';
return;
}
void world_map_p(){
while(1){
char into;
into=getch();
system("cls");
if(into=='a') player_x--;
else if(into=='d') player_x++;
else if(into=='w') player_y--;
else if(into=='s') player_y++;
else if(into=='q') player_z--;
else if(into=='e') player_z++;
else if(into=='t') block_excavate(player_x,player_y-1,player_z);
else if(into=='g') block_excavate(player_x,player_y+1,player_z);
else if(into=='f') block_excavate(player_x-1,player_y,player_z);
else if(into=='h') block_excavate(player_x+1,player_y,player_z);
else if(into=='r') block_excavate(player_x,player_y,player_z-1);
else if(into=='y') block_excavate(player_x,player_y,player_z+1);
else if(into=='b') {
system("cls");
synthesis_article();
}
else break;
world_map_s();
}
return;
}
int main()
{
world_map_c();
world_map_p();
return 1;
}