#include <iostream>
#include <conio.h>
#include <string>
#include <map>
#include <cmath>
#include <windows.h>
#include <time.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
int fallspeed;
int jumpspeed = -3;
int gravity = 1;
int y = 400, x = 500;
int restartposy, restartposx, face, health = 1000, lasthealth = 1000, breath = 100, hungry = 1000, dienum;
bool attack, defense, hurt, mode;
struct TNT
{
int y;
int x;
int time;
bool issave;
};
struct BLOCK
{
int color;
string ch;
string type;
};
struct MOB
{
int fallspeed;
int health;
bool hurt;
int y;
int x;
int attack;
string shap;
bool isenemy;
int color;
string name;
};
struct ARROW
{
string shap;
double y;
double x;
double fallspeed;
double plusx;
};
TNT tnt[20];
string die;
ARROW arrow[100];
MOB mobs[50] = {
{0,1000,0,0,0,100,"危",true,7,"危"},
{0,10,0,0,0,10," ",true,7," "},
{0,1000,0,0,0,100,"MM",false,7,"MM"},
{0,100000,0,90,70,-100,"AC",true,7,"Accept"},
{0,10000,0,90,70,500,"BO",true,7,"BOSS"},
{0,100000,0,90,70,-1000,"AK",true,7,"AK"},
};
MOB mob[100] = {
{0,1000,0,92,4,100,"WA",true,7,"Wrong Anwser"},
{0,1000,0,92,4,100,"TL",true,7,"Time Limit Error"},
{0,2000,0,92,4,300,"CE",true,7,"Compile Error"},
{0,1000,0,45,9,100,"WA",true,7,"Wrong Anwser"},
{0,100000,0,90,70,-100,"AC",true,7,"Accept"},
{0,100000,0,90,70,-1000,"AK",true,7,"AK"},
{0,10000,0,90,70,500,"UK",true,7,"Unknown Error"},
{0,1000,0,92,3,0,"MM",false,7,"MM"},
{0,1000,0,92,3,0,"MM",false,7,"MM"},
{0,1000,0,90,15,0,"MM",false,7,"MM"},
{0,1000,0,90,80,0,"MM",false,7,"MM"},
};
BLOCK block[32] = {
{0," ","air"},//空气
{6,"██","block"},//土块
{8,"██","block"},//石头
{2,"██","block"},//草方块
{15,"██","block"},//雪块
{4,"██","block"},//岩浆块
{14,"▓▓","fallblock"},//沙块
{8,"II","fallblock"},//铁砧
{9,"██","water"},//水
{9,"▇▇","water"},//水
{9,"▆▆","water"},//水
{9,"▅▅","water"},//水
{9,"▄▄","water"},//水
{9,"▃▃","water"},//水
{9,"▂▂","water"},//水
{9,"▁▁","water"},//水
{12,"██","lava"},//岩浆
{12,"▇▇","lava"},//岩浆
{12,"▆▆","lava"},//岩浆
{12,"▅▅","lava"},//岩浆
{12,"▄▄","lava"},//岩浆
{12,"▃▃","lava"},//岩浆
{12,"▂▂","lava"},//岩浆
{12,"▁▁","lava"},//岩浆
{12,"危","background"},//危
{6,"██","background"},//木头
{10,"▓▓","background"},//树叶
{15,"▓▓","background"},//带雪树叶
{15,"▅▅","bomb"},//TNT爆炸
{12,"Ⅲ","TNT"},//TNT
{7,"Ⅲ","TNT"},//TNT2
{6,"∷","ladder"},//梯子
};
int board[5005][5005];
int setboard[5005][5005];
int bag[100];
int clear_buffer()
{
while(kbhit())
{
if(getch() != EOF);
for(int i = 1; i <= 256; i++)
{
if(GetAsyncKeyState(i));
}
}
return 0;
}
void color(int a)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
/* 1 深蓝色
2 深绿色
3 深青色
4 深红色
5 深粉色
i 黄色
7 深白色
8 灰色
9 浅蓝色
10 浅绿色
11 浅青色
12 浅红色
13 浅粉色
14 浅黄色
15 浅白色
背景
1~15 黑色
16~31 深蓝色
32~47 深绿色
48~63 深青色
64~79 深红色
'S'~95 深粉色
96~111 深黄色
112~127 深白色
128~143 灰色
144~159 浅蓝色
160~1'A' 浅绿色
176~191 浅青色
192~207 浅红色
208~223 浅粉色
224~239 浅黄色
240~255 浅白色
*/
}
int init()//听说有人要我增加地图生成的注释,所以我就写了。
{
for(int j = 0; j < 100; j++)
{
bag[j] = 0;//这个...初始化背包
}
for(int i = 0; i < 5000; i++)
{
for(int j = 0; j < 5000; j++)
{
board[i][j] = 0;//初始化地图 (我们的y是倒着来的)
}
}
double lasty = rand() % 101 + 400;//lasty代表上一个我们选择的点的高度。
for(int i = 5; i < 5000; i += 5)//i每次加5,每隔5个点连一条线
{
double y = rand() % 21 - 10 + lasty;//y代表这个点我们选择的高度,为了不出现太陡峭的山,我们只允许这个高度在刚才的点的高低10格内。
y = min(450.0, y);//这是最小高度,防止整个地图都在水里。
double high = lasty;//这个high是用来统计当前高度的,用double可以更加精确。
int dirt = rand() % 5 + 2;//dirt代表这一列上泥土高度。
for(int j = i - 5; j < i; j++)
{
high += (y - lasty) / 5;//high每次增加差距的1/5。
for(int k = 999; k >= (int)high; k--)
{
if(k == (int)high)//如果是最高点
{
setboard[k][j] = 3;//就用草地
if(high <= 350)//如果high比较高
{
setboard[k][j] = 4;//就用雪地
}
}
else if(k - dirt <= (int)high)//泥土
{
setboard[k][j] = 1;
}
else
{
setboard[k][j] = 2;//石头
}
}
}
lasty = y;//赋值
}
//再来一边,填满最后几格
int dirt = rand() % 5 + 2;
double high = lasty+10000;
for(int j = 995; j < 999; j++)
{
for(int k = 999; k >= (int)high; k--)
{
if(k == (int)high)
{
setboard[k][j] = 3;
if(high <= 350)
{
setboard[k][j] = 4;
}
}
else if(k - dirt <= (int)high)
{
setboard[k][j] = 1;
}
else
{
setboard[k][j] = 2;
}
}
}
//填满水,这里默认把海平面高度设为410。
for(int i = 0; i < 5000; i++)
{
for(int j = 600; j >= 410; j--)
{
if(setboard[j][i] == 0)
{
setboard[j][i] = 8;
}
}
}
//沙子
for(int i = 0; i < 5000; i++)
{
bool a = 0;
for(int j = 999; j >= 0; j--)
{
if(a && setboard[j][i] != 0 && setboard[j][i] != 8)
{
setboard[j][i] = 6;
continue;
}
if(setboard[j][i] == 8)
{
continue;
}
if(setboard[j][i + 3] == 8)
{
a = true;
setboard[j][i] = 6;
}
if(setboard[j][i + 2] == 8)
{
a = true;
setboard[j][i] = 6;
}
if(setboard[j][i + 1] == 8)
{
a = true;
setboard[j][i] = 6;
}
if(setboard[j][i - 1] == 8)
{
a = true;
setboard[j][i] = 6;
}
if(setboard[j][i - 2] == 8)
{
a = true;
setboard[j][i] = 6;
}
if(setboard[j][i - 3] == 8)
{
a = true;
setboard[j][i] = 6;
}
if(setboard[j - 2][i] == 8)
{
a = true;
setboard[j][i] = 6;
}
if(setboard[j - 1][i] == 8)
{
a = true;
setboard[j][i] = 6;
}
if(setboard[j - 3][i] == 8)
{
a = true;
setboard[j][i] = 6;
}
if(setboard[j - 4][i] == 8)
{
a = true;
setboard[j][i] = 6;
}
}
}
//树
for(int i = 0; i < 5000; i++)
{
for(int j = 0; j < 5000; j++)
{
if(setboard[j][i] == 0 && block[setboard[j + 1][i]].type == "block")
{
if(rand() % 10 == 1)
{
setboard[j][i] = 25;
setboard[j - 1][i] = 25;
setboard[j - 2][i] = 25;
setboard[j - 3][i] = 25;
setboard[j - 3][i + 1] = 26;
setboard[j - 3][i - 1] = 26;
setboard[j - 4][i + 2] = 26;
c++ 小游戏——我的世界
最新推荐文章于 2024-08-14 21:24:52 发布
这是一个使用C++编程实现的简单版“我的世界”小游戏,包含地图生成、角色移动、物品交互等功能。游戏地图通过随机算法生成,包括不同地形如山、水、沙子等。玩家可以通过键盘控制角色移动,可以放置和破坏方块,还能使用道具如TNT。此外,游戏还支持一些特殊指令,如瞬移、创造模式等。
摘要由CSDN通过智能技术生成