1 Star 0 Fork 1

saigon/Algorithms

forked from charlieshu/Algorithms 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
暂无数据
克隆/下载
我的世界2d.cpp 29.20 KB
一键复制 编辑 原始数据 按行查看 历史
charlie 提交于 11个月前 . move from github to gitee
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
#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[1005][1005];
int setboard[1005][1005];
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 < 1000; i++)
{
for(int j = 0; j < 1000; j++)
{
board[i][j] = 0;//初始化地图 (我们的y是倒着来的)
}
}
double lasty = rand() % 101 + 400;//lasty代表上一个我们选择的点的高度。
for(int i = 5; i < 1000; 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;
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 < 1000; i++)
{
for(int j = 600; j >= 410; j--)
{
if(setboard[j][i] == 0)
{
setboard[j][i] = 8;
}
}
}
//沙子
for(int i = 0; i < 1000; 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 < 1000; i++)
{
for(int j = 0; j < 1000; 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;
setboard[j - 4][i + 1] = 26;
setboard[j - 4][i] = 26;
setboard[j - 4][i - 1] = 26;
setboard[j - 4][i - 2] = 26;
setboard[j - 5][i + 2] = 26;
setboard[j - 5][i + 1] = 26;
setboard[j - 5][i] = 26;
setboard[j - 5][i - 1] = 26;
setboard[j - 5][i - 2] = 26;
setboard[j - 6][i + 1] = 26;
setboard[j - 6][i] = 26;
setboard[j - 6][i - 1] = 26;
if(j <= 350)
{
setboard[j - 3][i + 1] = 27;
setboard[j - 3][i - 1] = 27;
setboard[j - 4][i + 2] = 27;
setboard[j - 4][i + 1] = 27;
setboard[j - 4][i] = 27;
setboard[j - 4][i - 1] = 27;
setboard[j - 4][i - 2] = 27;
setboard[j - 5][i + 2] = 27;
setboard[j - 5][i + 1] = 27;
setboard[j - 5][i] = 27;
setboard[j - 5][i - 1] = 27;
setboard[j - 5][i - 2] = 27;
setboard[j - 6][i + 1] = 27;
setboard[j - 6][i] = 27;
setboard[j - 6][i - 1] = 27;
}
}
}
}
}
//地洞
for(int j = 999; j >= 700; j--)
{
if(rand() % 20 == 1)
{
setboard[j - 3][2] = 0;
setboard[j - 2][2] = 0; setboard[j - 2][3] = 0;
setboard[j - 1][2] = 0; setboard[j - 1][3] = 0; setboard[j - 1][4] = 0;
setboard[j][2] = 0; setboard[j][3] = 0; setboard[j][4] = 0; setboard[j][5] = 0;
setboard[j + 1][2] = 0; setboard[j + 1][3] = 0; setboard[j + 1][4] = 0;
setboard[j + 2][2] = 0; setboard[j + 2][3] = 0;
setboard[j + 3][2] = 0;
}
}
for(int i = 3; i < 997; i++)
{
for(int j = 996; j >= 500; j--)
{
if(block[setboard[j + 3][i]].type == "block" && block[setboard[j - 3][i]].type == "block" && setboard[j][i] == 0 && setboard[j + 1][i] == 0 && setboard[j + 2][i] == 0 && setboard[j - 1][i] == 0 && setboard[j - 2][i] == 0)
{
j += rand() % 5 - 2;
j = max(3, j);
j = min(996, j);
if(rand() % 500 <= 499)
{
setboard[j - 3][i] = 0;
setboard[j - 2][i - 1] = 0; setboard[j - 2][i] = 0; setboard[j - 2][i + 1] = 0;
setboard[j - 1][i - 2] = 0; setboard[j - 1][i - 1] = 0; setboard[j - 1][i] = 0; setboard[j - 1][i + 1] = 0; setboard[j - 1][i + 2] = 0;
setboard[j][i - 3] = 0; setboard[j][i - 2] = 0; setboard[j][i - 1] = 0; setboard[j][i] = 0; setboard[j][i + 1] = 0; setboard[j][i + 2] = 0; setboard[j][i + 3] = 0;
setboard[j + 1][i - 2] = 0; setboard[j + 1][i - 1] = 0; setboard[j + 1][i] = 0; setboard[j + 1][i + 1] = 0; setboard[j + 1][i + 2] = 0;
setboard[j + 2][i - 1] = 0; setboard[j + 2][i] = 0; setboard[j + 2][i + 1] = 0;
setboard[j + 3][i] = 0;
if(rand() % 20 == 1)
{
for(int k = 0; k < 100; k++)
{
if(mob[k].shap == "")
{
mob[k] = {0,1000,0,0,0,100,"SS",true,7,"僵尸"};
mob[k].x = i;
mob[k].y = j;
break;
}
}
}
}
}
else if(block[setboard[j + 3][i]].type == "block" && block[setboard[j + 2][i]].type == "block" && block[setboard[j + 1][i]].type == "block" && block[setboard[j][i]].type == "block" && block[setboard[j - 1][i]].type == "block" && block[setboard[j - 2][i]].type == "block" && block[setboard[j - 3][i]].type == "block")
{
if(rand() % 500 == 1)
{
setboard[j - 3][i] = 0;
setboard[j - 2][i - 1] = 0; setboard[j - 2][i] = 0; setboard[j - 2][i + 1] = 0;
setboard[j - 1][i - 2] = 0; setboard[j - 1][i - 1] = 0; setboard[j - 1][i] = 0; setboard[j - 1][i + 1] = 0; setboard[j - 1][i + 2] = 0;
setboard[j][i - 3] = 0; setboard[j][i - 2] = 0; setboard[j][i - 1] = 0; setboard[j][i] = 0; setboard[j][i + 1] = 0; setboard[j][i + 2] = 0; setboard[j][i + 3] = 0;
setboard[j + 1][i - 2] = 0; setboard[j + 1][i - 1] = 0; setboard[j + 1][i] = 0; setboard[j + 1][i + 1] = 0; setboard[j + 1][i + 2] = 0;
setboard[j + 2][i - 1] = 0; setboard[j + 2][i] = 0; setboard[j + 2][i + 1] = 0;
setboard[j + 3][i] = 0;
}
}
}
}
//出生点
bool a = false;
for(int i = 400; i < 1000; i++)
{
for(int j = 0; j < 1000; j++)
{
if(setboard[j][i] == 0 && block[setboard[j + 1][i]].type == "block" && (setboard[j + 1][i] == 3 || setboard[j + 1][i] == 4))
{
restartposy = j;
restartposx = i;
y = j;
x = i;
a = true;
break;
}
}
if(a)
{
break;
}
}
return 0;
}
int Arrowmove()
{
for(int i = 0; i < 100; i++)
{
if(arrow[i].shap == "")
{
continue;
}
arrow[i].x += (int)arrow[i].plusx;
arrow[i].plusx -= 0.1;
for(int j = (int)arrow[j].y + 1; j <= (int)arrow[j].y + (int)arrow[j].fallspeed; j++)
{
if(block[board[j][(int)arrow[j].x]].type == "block" || block[board[j][(int)arrow[j].x]].type == "fallblock")
{
arrow[i].fallspeed = 0;
return 0;
}
}
arrow[i].y += arrow[i].fallspeed;
arrow[i].fallspeed += 0.1;
if(arrow[i].y > 999)
{
arrow[i].shap = "";
}
if(block[board[(int)arrow[i].y + 1][(int)arrow[i].x]].type == "block" || block[board[(int)arrow[i].y + 1][(int)arrow[i].x]].type == "fallblock")
{
arrow[i].shap = "";
}
}
return 0;
}
int mobmove()
{
for(int j = 0; j < 100; j++)
{
if(mob[j].shap == "")
{
continue;
}
mob[j].hurt = false;
mob[j].color = 7;
if(mob[j].health <= 0 || mob[j].y > 999)
{
mob[j].shap = "";
mob[j].color = 7;
continue;
}
if(block[board[mob[j].y][mob[j].x]].type == "lava")
{
mob[j].health -= 200;
mob[j].hurt = true;
}
else if((board[mob[j].y + 1][mob[j].x] == 5) || ((mob[j].y == y || mob[j].y == y - 1) && (mob[j].x == x + 1 || mob[j].x == x || mob[j].x == x - 1) && KEY_DOWN(' ')))
{
mob[j].health -= 100;
mob[j].hurt = true;
}
if(mob[j].y == y && mob[j].x == x && mob[j].isenemy)
{
health -= mob[j].attack;
hurt = true;
die = "被 " + mob[j].name + " 杀死了";
}
for(int i = mob[j].y - 1; i >= mob[j].y + mob[j].fallspeed; i--)
{
if(block[board[i - 1][mob[j].x]].type == "block")
{
mob[j].fallspeed = 0 - mob[j].y + i + 1;
return 0;
}
}
for(int i = mob[j].y + 1; i <= mob[j].y + mob[j].fallspeed; i++)
{
if(block[board[i][mob[j].x]].type == "block" || block[board[i][mob[j].x]].type == "fallblock")
{
if(mob[j].fallspeed >= 5 && block[board[i - 1][mob[j].x]].type == "water")
{
mob[j].health -= 50 * (mob[j].fallspeed - 4);
mob[j].hurt = true;
}
mob[j].fallspeed = 0;
return 0;
}
}
mob[j].y += mob[j].fallspeed;
mob[j].fallspeed += gravity;
if(mob[j].isenemy)
{
if(mob[j].y > y && (block[board[mob[j].y + 1][mob[j].x]].type == "block" || block[board[mob[j].y + 1][mob[j].x]].type == "fallblock"))
{
if(mob[j].y > y + 50)
{
mob[j].fallspeed = -7;
}
mob[j].fallspeed = -3;
}
if(mob[j].x < x)
{
if(block[board[mob[j].y][mob[j].x + 1]].type != "block" || block[board[mob[j].y][mob[j].x + 1]].type != "fallblock")
{
mob[j].x++;
}
else if(block[board[mob[j].y + 1][mob[j].x]].type == "block" || block[board[mob[j].y + 1][mob[j].x]].type != "fallblock")
{
mob[j].fallspeed = -3;
}
}
else if(mob[j].x > x)
{
if(block[board[mob[j].y][mob[j].x - 1]].type != "block" || block[board[mob[j].y][mob[j].x - 1]].type != "fallblock")
{
mob[j].x--;
}
else if(block[board[mob[j].y + 1][mob[j].x]].type == "block" || block[board[mob[j].y + 1][mob[j].x]].type != "fallblock")
{
mob[j].fallspeed = -3;
}
}
}
else
{
if(rand() % 3 == 0)
{
if(block[board[mob[j].y][mob[j].x + 1]].type != "block" || block[board[mob[j].y][mob[j].x + 1]].type != "fallblock")
{
mob[j].x++;
}
else if(block[board[mob[j].y + 1][mob[j].x]].type == "block" || block[board[mob[j].y + 1][mob[j].x]].type != "fallblock")
{
mob[j].fallspeed = -3;
}
}
else if(rand() % 3 == 1)
{
if(block[board[mob[j].y][mob[j].x - 1]].type != "block" || block[board[mob[j].y][mob[j].x - 1]].type != "fallblock")
{
mob[j].x--;
}
else if(block[board[mob[j].y + 1][mob[j].x]].type == "block" || block[board[mob[j].y + 1][mob[j].x]].type != "fallblock")
{
mob[j].fallspeed = -3;
}
}
}
if(mob[j].hurt)
{
mob[j].color = 12;
}
}
return 0;
}
int print()
{
if(!mode)
{
color(8);
cout << "HP:";
color(12);
cout << health << endl;
for(int i = 0; i < health; i += 100)
{
cout << "◆";
}
color(7);
for(int i = health; i < lasthealth; i += 100)
{
cout << "◇";
}
cout << endl;
color(8);
cout << "AIR:";
color(11);
cout << breath << endl;
for(int i = 0; i < breath; i += 10)
{
cout << "●";
}
for(int i = breath; i < 91; i += 10)
{
cout << "○";
}
cout << endl;
color(8);
cout << "HUNGRY:";
color(14);
cout << hungry << endl;
for(int i = 0; i < hungry; i += 100)
{
cout << "§";
}
cout << endl;
}
color(8);
cout << "DIENUM:";
color(4);
cout << dienum << endl;
for(int i = y - 6; i <= y + 6; i++)
{
for(int j = x - 6; j <= x + 6; j++)
{
bool ismob = false;
for(int s = 0; s < 100; s++)
{
if(mob[s].shap == "")
{
continue;
}
else if(mob[s].x == j && mob[s].y == i)
{
color(mob[s].color);
cout << mob[s].shap;
ismob = true;
break;
}
}
if(ismob)
{
continue;
}
for(int s = 0; s < 100; s++)
{
if(arrow[s].shap == "")
{
continue;
}
else if((int)arrow[s].x == j && (int)arrow[s].y == i)
{
color(7);
cout << arrow[s].shap;
ismob = true;
break;
}
}
if(ismob)
{
continue;
}
else if(i == y && j == x)
{
if (KEY_DOWN('S'))
{
color(14);
if(hurt)
{
color(12);
}
cout << "()";
}
else
{
color(9);
if(hurt)
{
color(12);
}
cout << "∏";
}
}
else if(i == y - 1 && j == x)
{
if (!KEY_DOWN('S'))
{
color(14);
if(hurt)
{
color(12);
}
cout << "()";
}
else
{
color(block[board[i][j]].color);
cout << block[board[i][j]].ch;
}
}
else
{
if(i < 0 || i >= 1000 || j < 0 || j >= 1000)
{
cout << " ";
continue;
}
color(block[board[i][j]].color);
cout << block[board[i][j]].ch;
}
}
cout << endl;
}
color(7);
cout << "Y:";
color(6);
cout << 1000 - y << endl;
color(7);
cout << "X:";
color(6);
cout << x << endl;
return 0;
}
int move()
{
if(board[y][x] == 31)
{
y += fallspeed;
return 0;
}
if(block[board[y][x]].type == "water")
{
if(fallspeed > 1)
{
fallspeed = 1;
}
}
else
{
for(int i = y - 1; i >= y + fallspeed; i--)
{
if(block[board[i - 1][x]].type == "block" || block[board[i - 1][x]].type == "fallblock")
{
fallspeed = 0 - y + i + 1;
return 0;
}
}
}
for(int i = y + 1; i <= y + fallspeed; i++)
{
if(block[board[i][x]].type == "block" || block[board[i][x]].type == "fallblock")
{
if(fallspeed >= 5 && block[board[i - 1][x]].type != "water")
{
health -= 50 * (fallspeed - 4);
if(fallspeed >= 7)
{
die = "落地过猛!";
}
else
{
die = "从高处摔了下来!";
}
hurt = true;
}
fallspeed = 0;
return 0;
}
}
y += fallspeed;
fallspeed += gravity;
return 0;
}
int bomb()
{
for(int i = 0; i < 20; i++)
{
if(tnt[i].time == 0)
{
int atk = 0;
if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 4)
{
atk = 50;
fallspeed -= 1;
x += x - tnt[i].x;
}
if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 3)
{
atk = 100;
fallspeed -= 2;
x += x - tnt[i].x;
}
if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 2)
{
atk = 300;
fallspeed -= 4;
x += 2 * (x - tnt[i].x);
}
if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 1)
{
atk = 500;
fallspeed -= 7;
x += 5 * (x - tnt[i].x);
}
if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 0)
{
atk = 800;
fallspeed -= 10;
}
tnt[i].time--;
if(!tnt[i].issave)
{
health -= atk;
}
die = "被TNT炸死了";
if(atk > 0 && !tnt[i].issave)
{
hurt = true;
}
if(!tnt[i].issave)
{
for(int yy = tnt[i].y - 3; yy <= tnt[i].y + 3; yy++)
{
for(int xx = tnt[i].x - 3; xx <= tnt[i].x + 3; xx++)
{
if((int)(sqrt(abs(yy - tnt[i].y) * abs(yy - tnt[i].y) + abs(xx - tnt[i].x) * abs(xx - tnt[i].x)) + 0.9999) == 3)
{
setboard[yy][xx] = 28;
}
if((int)(sqrt(abs(yy - tnt[i].y) * abs(yy - tnt[i].y) + abs(xx - tnt[i].x) * abs(xx - tnt[i].x)) + 0.9999) < 3)
{
setboard[yy][xx] = 0;
}
}
}
}
}
else if(tnt[i].time == -1)
{
setboard[tnt[i].y][tnt[i].x] = 0;
if(!tnt[i].issave)
{
for(int yy = tnt[i].y - 3; yy <= tnt[i].y + 3; yy++)
{
for(int xx = tnt[i].x - 3; xx <= tnt[i].x + 3; xx++)
{
if((int)(sqrt(abs(yy - tnt[i].y) * abs(yy - tnt[i].y) + abs(xx - tnt[i].x) * abs(xx - tnt[i].x)) + 0.9999) <= 3)
{
setboard[yy][xx] = 0;
}
}
}
}
tnt[i].time--;
}
else if(tnt[i].time > 0)
{
tnt[i].time--;
if(tnt[i].time % 2 == 0)
{
setboard[tnt[i].y][tnt[i].x] = 29;
}
else
{
setboard[tnt[i].y][tnt[i].x] = 30;
}
}
}
return 0;
}
int check()
{
for(int i = 0; i < 1000; i++)
{
for(int j = 0; j < 1000; j++)
{
if(block[board[i][j]].type == "water" && board[i][j] != 15)
{
if(board[i + 1][j] == 0)
{
setboard[i + 1][j] = board[i][j];
setboard[i + 1][j] = 8;
}
else if(block[board[i + 1][j]].type == "lava")
{
setboard[i + 1][j] = 2;
}
else if(block[board[i + 1][j]].type == "block" || block[board[i + 1][j]].type == "fallblock")
{
if(board[i][j + 1] == 0)
{
setboard[i][j + 1] = board[i][j] + 1;
}
else if(block[board[i][j + 1]].type == "lava")
{
setboard[i][j + 1] = 2;
}
if(board[i][j - 1] == 0)
{
setboard[i][j - 1] = board[i][j] + 1;
}
else if(block[board[i][j - 1]].type == "lava")
{
setboard[i][j - 1] = 2;
}
}
}
if(block[board[i][j]].type == "lava" && board[i][j] != 23)
{
if(board[i + 1][j] == 0)
{
setboard[i + 1][j] = board[i][j];
setboard[i + 1][j] = 16;
}
else if(block[board[i + 1][j]].type == "water")
{
setboard[i + 1][j] = 2;
}
else if(block[board[i + 1][j]].type == "block" || block[board[i + 1][j]].type == "fallblock")
{
if(board[i][j + 1] == 0)
{
setboard[i][j + 1] = board[i][j] + 1;
}
else if(block[board[i][j + 1]].type == "water")
{
setboard[i][j + 1] = 2;
}
if(board[i][j - 1] == 0)
{
setboard[i][j - 1] = board[i][j] + 1;
}
else if(block[board[i][j - 1]].type == "water")
{
setboard[i][j - 1] = 2;
}
}
}
if(block[board[i][j]].type == "fallblock")
{
if(board[i + 2][j] == 0 && board[i + 1][j] == 0 && i + 2 < 100)
{
setboard[i][j] = 0;
setboard[i + 2][j] = board[i][j];
if(board[i][j] == 7 && j == x && i + 2 == y)
{
health -= 600;
hurt = true;
die = "被压扁了";
}
}
else if(board[i + 1][j] == 0 && i + 1 < 100)
{
setboard[i][j] = 0;
setboard[i + 1][j] = board[i][j];
if(board[i][j] == 7 && j == x && i + 1 == y)
{
health -= 600;
hurt = true;
die = "被压扁了";
}
else if(board[i][j] == 7 && j == x && i + 2 == y)
{
health -= 600;
hurt = true;
die = "被压扁了";
}
}
}
}
}
for(int i = 0; i < 1000; i++)
{
for(int j = 0; j < 1000; j++)
{
board[i][j] = setboard[i][j];
}
}
}
int main()
{
srand((int)time(0));
for(int i = 0; i < 20; i++)
{
tnt[i].time = -2;
}
init();
while(1)
{
system("cls");
if(!mode)
{
move();
}
if(KEY_DOWN('F'))
{
setboard[y + 1][x] = 2;
}
check();
bomb();
Arrowmove();
mobmove();
if(mode)
{
hurt = false;
}
print();
Sleep(30);
hungry--;
hungry = max(hungry, 0);
if(hungry == 0)
{
die = "被饿死了";
hurt = true;
health -= 10;
}
if(mode)
{
health = 1000;
}
if(health <= 0)
{
Sleep(500);
system("cls");
color(12);
cout << " GAME OVER " << endl;
color(7);
cout << " STEVE " << die << endl;
dienum++;
Sleep(2000);
x = restartposx;
y = restartposy;
health = 1000;
hungry = 1000;
breath = 100;
fallspeed = 0;
}
health += (hungry + 201) / 300;
if(health > 1000)
{
health = 1000;
}
if(attack)
{
attack = 0;
}
if(defense)
{
defense = 0;
}
if(hurt)
{
hurt = false;
lasthealth = health;
}
if(block[board[y][x]].type == "water")
{
fallspeed = 1;
if(KEY_DOWN('W'))
{
fallspeed = -1;
}
}
if(block[board[y - 1][x]].type == "water")
{
die = "被水淹死了!";
breath--;
}
else
{
breath++;
if(breath > 100)
{
breath = 100;
}
}
if(board[y][x] == 31)
{
fallspeed = 0;
if(KEY_DOWN('W'))
{
fallspeed = -1;
}
if(KEY_DOWN('S'))
{
fallspeed = 1;
}
}
if(block[board[y][x]].type == "lava")
{
fallspeed = 1;
if(KEY_DOWN('W'))
{
fallspeed = -1;
}
die = "试图在岩浆里游泳!";
hurt = true;
health -= 100;
}
if (KEY_DOWN('W') && !KEY_DOWN('S'))
{
if(mode)
{
y--;
}
else
{
if(block[board[y][x]].type != "water" && board[y][x] != 31)
{
if(block[board[y + 1][x]].type == "block" || block[board[y + 1][x]].type == "fallblock")
{
fallspeed = jumpspeed;
}
}
}
}
if (KEY_DOWN('A'))
{
if((block[board[y][x - 1]].type != "block" && block[board[y][x - 1]].type != "fallblock") || mode)
{
if(KEY_DOWN('S') || (block[board[y - 1][x - 1]].type != "block" && block[board[y - 1][x - 1]].type != "fallblock") || mode)
{
x -= 1;
}
}
face = -1;
}
if (KEY_DOWN('D'))
{
if((block[board[y][x + 1]].type != "block" && block[board[y][x + 1]].type != "fallblock") || mode)
{
if(KEY_DOWN('S') || (block[board[y - 1][x + 1]].type != "block" && block[board[y - 1][x + 1]].type != "fallblock") || mode)
{
x += 1;
}
}
face = 1;
}
if(KEY_DOWN('S'))
{
if(mode)
{
y++;
}
else
{
fallspeed += 1;
}
}
if(KEY_DOWN(' '))
{
attack = true;
}
if(KEY_DOWN('E'))
{
system("cls");
color(7);
cout << "┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐" << endl;
for(int i = 0; i < 9; i++)
{
color(7);
cout << "│";
for(int j = 0; j < 10; j++)
{
color(block[bag[i * 10 + j]].color);
cout << block[bag[i * 10 + j]].ch;
color(7);
cout << "│";
}
cout << endl;
color(7);
cout << "├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤" << endl;
}
color(7);
cout << "│";
for(int j = 0; j < 10; j++)
{
color(block[bag[90 + j]].color);
cout << block[bag[90 + j]].ch;
color(7);
cout << "│";
}
color(7);
cout << endl;
cout << "└──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘" << endl;
Sleep(3000);
}
if(KEY_DOWN('C'))
{
hungry += 100;
hungry = min(hungry, 1000);
}
if(KEY_DOWN('Q'))
{
for(int i = 0; i < 20; i++)
{
if(tnt[i].time == -2)
{
tnt[i] = {y, x, 10, 0};
break;
}
}
}
if(KEY_DOWN('i'))
{
for(int i = 0; i < 20; i++)
{
if(tnt[i].time == -2)
{
tnt[i] = {y, x, 10, 1};
break;
}
}
}
if(KEY_DOWN('8'))
{
for(int i = 0; i < 20; i++)
{
if(tnt[i].time == -2)
{
tnt[i] = {y, x, 10, 2};
break;
}
}
}
if(KEY_DOWN('9'))
{
for(int i = 0; i < 20; i++)
{
if(tnt[i].time == -2)
{
tnt[i] = {y, x, 10, 3};
break;
}
}
}
if(KEY_DOWN('0'))
{
for(int i = 0; i < 20; i++)
{
if(tnt[i].time == -2)
{
tnt[i] = {y, x, 10, 4};
break;
}
}
}
if(KEY_DOWN('I'))
{
for(int i = 0; i < 20; i++)
{
if(tnt[i].time == -2)
{
tnt[i] = {y, x, 10, 5};
break;
}
}
}
if(KEY_DOWN('Z'))
{
setboard[y + 1][x] = 0;
}
if(KEY_DOWN('X'))
{
setboard[y][x] = 24;
}
if(KEY_DOWN('3'))
{
setboard[y + 1][x] = 6;
}
if(KEY_DOWN('4'))
{
setboard[y + 1][x] = 7;
}
if(KEY_DOWN('1'))
{
setboard[y + 1][x] = 8;
}
if(KEY_DOWN('2'))
{
setboard[y + 1][x] = 16;
}
if(KEY_DOWN('5'))
{
if(face == 1)
{
for(int i = 0; i < 100; i++)
{
if(arrow[i].shap == "")
{
arrow[i] = {"→",y,x,-0.7,2};
break;
}
}
}
else
{
for(int i = 0; i < 100; i++)
{
if(arrow[i].shap == "")
{
arrow[i] = {"←",y,x,-0.7,-2};
break;
}
}
}
}
if(KEY_DOWN('T'))
{
clear_buffer();
system("cls");
cout << "请输入指令:" << endl;
string a;
cin >> a;
if(a == "kill")
{
die = "失败了。";
hurt = true;
health = 0;
}
if(a == "full_health")
{
health = 1000;
}
if(a == "creativemode")
{
mode = !mode;
}
if(a == "move")
{
cin >> y >> x;
y = 1000 - y;
}
if(a == "summom")
{
int a;
cin >> a;
for(int i = 0; i < 100; i++)
{
if(mob[i].shap == "")
{
mob[i] = mobs[a];
mob[i].x = x;
mob[i].y = y;
break;
}
}
}
}
if(KEY_DOWN('O'))
{
for(int i = 0; i < 1000; i++)
{
for(int j = 0; j < 1000; j++)
{
setboard[i][j] = 0;
}
}
}
if(KEY_DOWN('P'))
{
for(int i = 0; i < 1000; i++)
{
for(int j = 0; j < 1000; j++)
{
setboard[i][j] = 2;
}
}
}
if(y > 1000)
{
die = "掉出了这个世界!";
hurt = true;
health -= 200;
}
if(breath <= 0)
{
breath = 0;
hurt = true;
health -= 10;
}
if(!KEY_DOWN('S') && block[board[y - 1][x]].type == "block")
{
die = "在墙里窒息死亡!";
hurt = true;
health -= 50;
}
if(board[y + 1][x] == 5)
{
hurt = true;
die = "发现了地板是熔岩做的。";
health -= 30;
}
clear_buffer();
}
return 0;
}
//https://blog.csdn.net/wangxun20081008/article/details/116569849
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/saigonshu/algorithm.git
git@gitee.com:saigonshu/algorithm.git
saigonshu
algorithm
Algorithms
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385