当前位置: 首页 > 工具软件 > 迷你任务 > 使用案例 >

Dev-C++5.11游戏创作之迷你世界2(进阶版)

龙星渊
2023-12-01

大家好啊!我系C++小盆友!今天把迷你世界升级了一下,顺便给大家分享一下。

这次呢,主要加了基岩斧,岩浆,还有不死药,界面也升级了一下,同时这里任务也开始开放了,希望大家玩得开心呦!

上代码

#include <bits/stdc++.h>
#include <windows.h>
#include <unistd.h>
#include <conio.h>
#define LIFE 15
#define HUNGRY 100
#define SPEED 1000
using namespace std;
//hamburger是汉堡,为迷你世界里的麦包什么的 , hungryl剩余饥饿 , speed玩家移动速度,暂时不使用
//wood木头物资 , stone石头物资 , metal金属物资 , diamond钻石物资
//und是当前玩家所在高度,便于判断一些稀有矿石出现点
//stoneAX、metalAX、diamondAX和goldAX各类斧头和镐子,需要合成
//undergroundMAP是当前底下矿洞可视区域,一旦移动,如不在map内,则重新随机
unsigned long long hamburger=10000, hungryl=100, speed=100;
long long life=9999;
unsigned long long wood=10, stone=10, metal=10, diamond=10, misterystone=100, jstone=100;
long long und=-2;
bool stoneAX=true, metalAX=true, diamondAX=false, goldAX=false, jstoneAX=false;
bool tl=false;
int undergroundMAP[10][10]= {0,0,0,0,0,0,0,0,0,0,
                             0,0,0,0,0,0,0,0,0,0,
                             0,0,0,0,0,0,0,0,0,0,
                             0,0,0,0,0,0,0,0,0,0,
                             0,0,0,0,0,0,0,0,0,0,
                             0,0,0,0,0,0,0,0,0,0,
                             0,0,0,0,0,0,0,0,0,0,
                             0,0,0,0,0,0,0,0,0,0,
                             0,0,0,0,0,0,0,0,0,0,
                             0,0,0,0,0,0,0,0,0,0
                            };
int nowp;//判断当前位置,更利于底下矿洞探索
unsigned long long x, y;//位置判断,便于输出

void HIDE() {
	CONSOLE_CURSOR_INFO cursor_info= {1,0};
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
void SetPos(int x,int y) {
	COORD pos;
	pos.X=y*2-1,pos.Y=x+1;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void stoDIG() {
	if(stoneAX==true&&metalAX==false) Sleep(50);
	else;
}
void metDIG() {
	if(stoneAX==true&&metalAX==false) Sleep(111);
	else if(metalAX=true&&diamondAX==false) Sleep(65);
	else;
}
void diaDIG() {
	if(metalAX==true&&diamondAX==false) Sleep(210);
	else if(diamondAX==true&&goldAX==false) Sleep(80);
	else if(jstoneAX==true);
	else;
}
void misDIG() {
	Sleep(10);
}
void jstAX() {
	for(int i=0; i<8; i++) {
		for(int j=0; j<8; j++) {
			switch(undergroundMAP[i][j]) {
				case 1:
					wood++;
					break;
				case 2:
					stone++;
					break;
				case 3:
					metal++;
					break;
				case 4:
					diamond++;
					break;
				case 5:
					diamond*=100;
					break;
				case 6:
					metal*=1000;
					break;
				case 7:
					if( !tl ) life--;
					break;
			}
			undergroundMAP[i][j]=0;
		}
	}
}
void golAX() {
	for(int i=0; i<10; i++) {
		for(int j=0; j<10; j++) {
			switch(undergroundMAP[i][j]) {
				case 1:
					wood++;
					break;
				case 2:
					stone++;
					break;
				case 3:
					metal++;
					break;
				case 4:
					diamond++;
					break;
				case 7:
					if( !tl ) life--;
					break;
			}
			undergroundMAP[i][j]=0;
		}
	}
}
void diaAX() {
	for(int i=x-2; i<=x+2; i++) {
		for(int j=y-2; j<=y+2; j++) {
			switch(undergroundMAP[i][j]) {
				case 1:
					wood++;
					break;
				case 2:
					stone++;
					stoDIG();
					break;
				case 3:
					metal++;
					metDIG();
					break;
				case 4:
					diamond++;
					diaDIG();
					break;
				case 7:
					if( !tl ) life--;
					break;
			}
			undergroundMAP[i][j]=0;
		}
	}
}
void metAX() {
	for(int i=x-1; i<=x+1; i++) {
		for(int j=y; j<=y+1; j++) {
			switch(undergroundMAP[i][j]) {
				case 1:
					wood++;
					break;
				case 2:
					stone++;
					stoDIG();
					break;
				case 3:
					metal++;
					metDIG();
					break;
				case 4:
					diamond++;
					diaDIG();
					break;
				case 7:
					if( !tl ) life--;
					break;
			}
			undergroundMAP[i][j]=0;
		}
	}
}
bool canGO(bool a1,bool a2,bool a3,bool a4,int pla) {
	if(pla<=3) {
		return 1;
	} else if(pla==4&&a2==true) {
		return 1;
	} else {
		return 0;
	}
}
void make() {
	system("cls");
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);
	cout<<" ____________________________________________________________________ "<<endl;
	cout<<"|                       合                 成                        |"<<endl;
	cout<<"|                                                                    |"<<endl;
	cout<<"|                              1. 铁斧                               |"<<endl;
	cout<<"|                             2. 钻石斧                              |"<<endl;
	cout<<"|                            3. 荒芜神斧                             |"<<endl;
	cout<<"|                           4. 神秘基岩斧                            |"<<endl;
	cout<<"|                             5. 不死药                              |"<<endl;
	cout<<"| 铁斧:有99.8%的概率挖掘3 ×3方格                                    |"<<endl;
	cout<<"| 钻石斧:有99.9%的概率挖掘5 ×5方格                                  |"<<endl;
	cout<<"| 荒芜神斧:有100%的概率挖掘全屏方格                                  |"<<endl;
	cout<<"| 神秘基岩斧:无可奉告                                                |"<<endl;
	cout<<"|  ________________________________________________________________  |"<<endl;
	cout<<"| |备注:请确认背包已有所有所需物品且斧子合成不需要使用已合成的斧子| |"<<endl;
	cout<<"|_|________________________________________________________________|_|"<<endl;
	cout<<"请输入:";
	char input=getch();
	switch(input) {
		case '1':
			if(metal>=4&&stoneAX!=false&&metalAX==false) {
				cout<<endl<<"已合成"<<endl;
				metalAX=true;
			} else if(metalAX==true) {
				cout<<endl<<"对不起!您的铁斧已经合成了,不能继续合成了呦!"<<endl;
			}
			break;
		case '2':
			if(diamond>=2&&metalAX!=false&&diamondAX==false) {
				cout<<endl<<"已合成"<<endl;
				diamondAX=true;
			} else if(diamondAX==true) {
				cout<<endl<<"对不起!您的钻石斧已经合成了,不能继续合成了呦!"<<endl;
			}
			break;
		case '3':
			if(wood>=30&&metal>=20&&diamond>=12&&diamondAX!=false&&goldAX==false) {
				cout<<endl<<"已合成"<<endl;
				goldAX=true;
			} else if(goldAX==true) {
				cout<<endl<<"对不起!您的荒芜神斧已经合成了,不能继续合成了呦!"<<endl;
			}
			break;
		case '4':
			if(wood>=100&&metal>=150&&diamond>=175&&goldAX==true&&jstoneAX==false) {
				cout<<endl<<"已合成"<<endl;
				jstoneAX=true;
			}
			break;
		case '5':
			if(wood>=101&&metal>=151&&diamond>=176&&jstone>=1) {
				cout<<endl<<"您已不怕岩浆"<<endl;
				tl=true;
			}
			break;
	}
}
void getk() {
	switch(getch()) {
		case 'w':
			if(x!=0&&jstoneAX==true) {
				jstAX();
			} else if(x!=0&&goldAX==true) {
				golAX();
			} else if(x!=0&&diamondAX==true) {
				diaAX();
			} else if(x!=0&&metalAX==true) {
				metAX();
			}
			if( x!=0 && canGO( stoneAX, metalAX, diamondAX, goldAX, undergroundMAP[x-1][y] ) ) {
				x-=1;
				switch(undergroundMAP[x][y]) {
					case 1:
						wood++;
						break;
					case 2:
						stone++;
						stoDIG();
						break;
					case 3:
						metal++;
						metDIG();
						break;
					case 4:
						diamond++;
						diaDIG();
						break;
					case 5:
						jstone++;
						misDIG();
						break;
					case 7:
						if( !tl ) life--;
						break;
				}
				undergroundMAP[x][y]=0;
			}
			break;
		case 's':
			if(x!=9&&jstoneAX==true) {
				jstAX();
			} else if(x!=9&&goldAX==true) {
				golAX();
			} else if(x!=9&&diamondAX==true) {
				diaAX();
			} else if(x!=9&&metalAX==true) {
				metAX();
			}
			if( x!=9 && canGO( stoneAX, metalAX, diamondAX, goldAX, undergroundMAP[x+1][y] ) ) {
				x+=1;
				switch(undergroundMAP[x][y]) {
					case 1:
						wood++;
						break;
					case 2:
						stone++;
						stoDIG();
						break;
					case 3:
						metal++;
						metDIG();
						break;
					case 4:
						diamond++;
						diaDIG();
						break;
					case 5:
						jstone++;
						misDIG();
						break;
					case 7:
						if( !tl ) life--;
						break;
				}
				undergroundMAP[x][y]=0;
			}
			break;
		case 'a':
			if(y!=0&&jstoneAX==true) {
				jstAX();
			} else if(y!=0&&goldAX==true) {
				golAX();
			} else if(y!=0&&diamondAX==true) {
				diaAX();
			} else if(y!=0&&metalAX==true) {
				metAX();
			}
			if( y!=0 && canGO( stoneAX, metalAX, diamondAX, goldAX, undergroundMAP[x][y-1] ) ) {
				y-=1;
				switch(undergroundMAP[x][y]) {
					case 1:
						wood++;
						break;
					case 2:
						stone++;
						stoDIG();
						break;
					case 3:
						metal++;
						metDIG();
						break;
					case 4:
						diamond++;
						diaDIG();
						break;
					case 5:
						jstone++;
						misDIG();
						break;
					case 7:
						if( !tl ) life--;
						break;
				}
				undergroundMAP[x][y]=0;
			}
			break;
		case 'd':
			if(y!=9&&jstoneAX==true) {
				jstAX();
			} else if(y!=9&&goldAX==true) {
				golAX();
			} else if(y!=9&&diamondAX==true) {
				diaAX();
			} else if(y!=9&&metalAX==true) {
				metAX();
			}
			if( y!=9 && canGO( stoneAX, metalAX, diamondAX, goldAX, undergroundMAP[x][y+1] ) ) {
				y+=1;
				switch(undergroundMAP[x][y]) {
					case 1:
						wood++;
						break;
					case 2:
						stone++;
						stoDIG();
						break;
					case 3:
						metal++;
						metDIG();
						break;
					case 4:
						diamond++;
						diaDIG();
						break;
					case 5:
						jstone++;
						misDIG();
						break;
					case 7:
						if( !tl ) life--;
						break;
				}
				undergroundMAP[x][y]=0;
			}
			break;
		case 'm':
			make();
			break;
		case 'c':
			if(jstoneAX==true) {
				for(int i=0; i<10; i++) {
					for(int j=0; j<10; j++) {
						switch(undergroundMAP[i][j]) {
							case 1:
								wood++;
								break;
							case 2:
								stone++;
								break;
							case 3:
								metal++;
								break;
							case 4:
								diamond++;
								break;
							case 5:
								diamond*=100;
								break;
							case 6:
								metal*=1000;
								break;
							case 7:
								if( !tl ) life--;
								break;
						}
						undergroundMAP[i][j]=0;
					}
				}
			}
	}
}
bool emp() {
	for(int i=1; i<9; i++) {
		for(int j=1; j<9; j++) {
			if(undergroundMAP[i][j]!=0&&undergroundMAP[i][j]!=4) {
				return false;
			}
		}
	}
	return true;
}
void pm() {
	system("cls");
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
	cout<<" _________________________________________________________________________________________ "<<endl;
	cout<<"|  __________________________________________________ _______________ __________________  |"<<endl;
	cout<<"| |                  迷  你  世  界                  |     背包      |      合成表      | |"<<endl;
	cout<<"| |__________________________________________正常模式| 1.木头:       | 2.工具合成       | |"<<endl;
	cout<<"| |生命:     | 饥饿值: 100 | 状态:正常 | 网络延时:0ms|               |   (1).挖掘工具   | |"<<endl;
	cout<<"| |__________________________________________________| 2.石头:       | 1.石斧           | |"<<endl;
	cout<<"| |                                                  |               |   直接送         | |"<<endl;
	cout<<"| |                                                  | 3.铁矿:       |                  | |"<<endl;
	cout<<"| |                                                  |               | 2.铁斧           | |"<<endl;
	cout<<"| |                                                  | 4.钻石:       |   需要一个石斧和 | |"<<endl;
	cout<<"| |                                                  |_______________|四块铁矿合成      | |"<<endl;
	cout<<"| |                                                  |     工具      |                  | |"<<endl;
	cout<<"| |                                                  |1.石斧:        | 3.钻石斧         | |"<<endl;
	cout<<"| |                                                  |               |   需要一个铁斧和 | |"<<endl;
	cout<<"| |                                                  |2.铁斧:        |两块钻石矿合成    | |"<<endl;
	cout<<"| |__________________________________________________|               |                  | |"<<endl;
	cout<<"| |目标完成情况:       |目标:合成基岩斧  |丢包率:  %0|3.钻石斧:      | 4.荒芜神斧       | |"<<endl;
	cout<<"| |____________________|_________________|___________|               |   需要三十个木头 | |"<<endl;
	cout<<"| |                                m键打开工具制造区 |4.荒芜神斧:    |加二十块铁矿 加十 | |"<<endl;
	cout<<"| |提示:挖掘钻石需要铁镐哦!铁镐需要石镐和四块铁合成 |_______________|二个钻石合成      | |"<<endl;
	cout<<"| |     钻石需要挖掘到地下-7层左右才有               |当前高度:      |                  | |"<<endl;
	cout<<"| |__________________________________________________|_______________|__________________| |"<<endl;
	cout<<"| |快捷键:                                                                              | |"<<endl;
	cout<<"| |m:制作斧子  c:基岩斧特有函数,能清空挖掘屏幕                                         | |"<<endl;
	cout<<"| |挖掘特效:                                                                            | |"<<endl;
	cout<<"| |    基岩斧挖掘特效:一层有一次能挖掘8*8矿石,挖掘后需手动挖掘其他矿石或使用快捷键c挖掘| |"<<endl;
	cout<<"| |    荒芜神斧挖掘特效:一次可以直接清屏                                                | |"<<endl;
	cout<<"| |    钻石斧挖掘特效:5*5挖掘范围                                                       | |"<<endl;
	cout<<"| |    铁斧挖掘特效:3*3挖掘范围                                                         | |"<<endl;
	cout<<"| |    石斧挖掘特效:无                                                                  | |"<<endl;
	cout<<"| |_____________________________________________________________________________________| |"<<endl;
	cout<<"| |______注意:由于某种bug,第一行矿石请尽量不要挖掘,谢谢配合,后面我们将尽快修复!______| |"<<endl;
	cout<<"|                                     |版本号|                                            |"<<endl;
	cout<<"|_____________________________________|V1.7.3|____________________________________________|"<<endl;

	if(emp()) {
		und--;
		srand(time(0));
		for(int k=4; k<=13; k++) {
			SetPos(k+1,2);
			for(int i=0; i<9; i++) {
				if(k-4==x&&i==y) {
					cout<<" *你*";
					undergroundMAP[k-4][i]=0;
					continue;
				}
				int a;
				do {
					a=rand()%7+1;
				} while(a==4&&und>-7);
				if(a==1) {
					cout<<setw(5)<<"木头";
					undergroundMAP[k-4][i]=1;
				} else if(a==2) {
					cout<<setw(5)<<"石子";
					undergroundMAP[k-4][i]=2;
				} else if(a==3) {
					cout<<setw(5)<<"铁矿";
					undergroundMAP[k-4][i]=3;
				} else if(a==4&&und<=-7) {
					cout<<setw(5)<<"钻石";
					undergroundMAP[k-4][i]=4;
				} else if(a==5&&und<=-96) {
					cout<<setw(5)<<"神石";
					undergroundMAP[k-4][i]=5;
				} else if(a==6&&und<=-101) {
					cout<<setw(5)<<"基岩";
					undergroundMAP[k-4][i]=6;
				} else if(a==7&&und<=-20) {
					cout<<setw(5)<<"岩浆";
					undergroundMAP[k-4][i]=7;
				}
			}
		}
	} else {
		for(int i=0; i<9; i++) {
			SetPos(i+5,2);
			for(int j=0; j<9; j++) {
				if(i==x&&j==y) {
					cout<<" *你*";
					undergroundMAP[i-4][j]=0;
					continue;
				}
				switch(undergroundMAP[i][j]) {
					case 0:
						cout<<setw(5)<<"  ";
						break;
					case 1:
						cout<<setw(5)<<"木头";
						break;
					case 2:
						cout<<setw(5)<<"石子";
						break;
					case 3:
						cout<<setw(5)<<"铁矿";
						break;
					case 4:
						cout<<setw(5)<<"钻石";
						break;
					case 5:
						cout<<setw(5)<<"神石";
						break;
					case 6:
						cout<<setw(5)<<"基岩";
						break;
					case 7:
						cout<<setw(5)<<"岩浆";
						break;
				}
			}
		}
	}

	SetPos(3.5,5);
	cout<<life;
	SetPos(2,32);
	cout<<wood;
	SetPos(4,32);
	cout<<stone;
	SetPos(6,32);
	cout<<metal;
	SetPos(8,32);
	cout<<diamond;
	SetPos(11,31);
	cout<<(stoneAX==false?"没有":"有");
	SetPos(13,31);
	cout<<(metalAX==false?"没有":"有");
	SetPos(15,32);
	cout<<(diamondAX==false?"没有":"有");
	SetPos(17,33);
	cout<<(goldAX==false?"没有":"有");
	SetPos(19,32);
	cout<<und;
	SetPos(15,9);
	cout<<"未完成"<<endl;
}
void OpenShow() {
	cout<<"请务必全屏"<<endl;
	HIDE();
	cin.get();
	cout<<"这里是迷你世界游戏"<<endl;
	HIDE();
	cin.get();
	cout<<"准备进入…"<<endl;
	HIDE();
	cin.get();
}

int main() {
	cout.tie();
	HIDE();
	OpenShow();
	HIDE();
	while(jstoneAX!=true) {
		system("cls");
		if(jstoneAX==true) break;
		pm();
		getk();
	}
	getch();
	system("cls");
	return 0;
}

总体606行,经过精细排序和整理TAB键,挨行排查错误,大家喜欢的话一定要点赞+关注啊!

好了,今天就到这里吧!

下期预告:

内容:迷你世界升级版3

时间:大约10月29号~11月15号更新

增加内容:空气墙,x斧……

敬请期待……

有任何问题可以私聊哦,我会尽量第一时间回应

最后,还是祝大家每天都开心!

(新文大概率10月30日出版,毕竟是生日嘛)

 类似资料: