当前位置:   article > 正文

我的世界c++源代码_c++ mc

c++ mc

我的世界电脑版是由Mojang Studios开发开发的一款迷你沙盒类建造游戏我的世界电脑版游戏采用了模拟像素风,带给了玩家最独特新颖的游戏体验。在这款游戏中,玩家可以尽情地去做自己任何想做的事,包括探索、建造、制作、破坏以及攻击等。我的世界电脑版包含了诸多的游戏模式供大家挑选,还具有鲜明的场景道具可以免费使用,以及特色的画面转换玩法,素材信息内容也清晰鲜明。

c++代码:

  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4. #include <map>
  5. #include <cmath>
  6. #include <windows.h>
  7. #include <time.h>
  8. #define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
  9. using namespace std;
  10. int fallspeed;
  11. int jumpspeed = -3;
  12. int gravity = 1;
  13. int y = 400, x = 500;
  14. int restartposy, restartposx, face, health = 1000, lasthealth = 1000, breath = 100, hungry = 1000, dienum;
  15. bool attack, defense, hurt, mode;
  16. struct TNT
  17. {
  18. int y;
  19. int x;
  20. int time;
  21. bool issave;
  22. };
  23. struct BLOCK
  24. {
  25. int color;
  26. string ch;
  27. string type;
  28. };
  29. struct MOB
  30. {
  31. int fallspeed;
  32. int health;
  33. bool hurt;
  34. int y;
  35. int x;
  36. int attack;
  37. string shap;
  38. bool isenemy;
  39. int color;
  40. string name;
  41. };
  42. struct ARROW
  43. {
  44. string shap;
  45. double y;
  46. double x;
  47. double fallspeed;
  48. double plusx;
  49. };
  50. TNT tnt[20];
  51. string die;
  52. ARROW arrow[100];
  53. MOB mobs[50] = {
  54. {0,1000,0,0,0,100,"危",true,7,"危"},
  55. {0,10,0,0,0,10," ",true,7," "},
  56. {0,1000,0,0,0,100,"MM",false,7,"MM"},
  57. {0,100000,0,90,70,-100,"AC",true,7,"Accept"},
  58. {0,10000,0,90,70,500,"BO",true,7,"BOSS"},
  59. {0,100000,0,90,70,-1000,"AK",true,7,"AK"},
  60. };
  61. MOB mob[100] = {
  62. {0,1000,0,92,4,100,"WA",true,7,"Wrong Anwser"},
  63. {0,1000,0,92,4,100,"TL",true,7,"Time Limit Error"},
  64. {0,2000,0,92,4,300,"CE",true,7,"Compile Error"},
  65. {0,1000,0,45,9,100,"WA",true,7,"Wrong Anwser"},
  66. {0,100000,0,90,70,-100,"AC",true,7,"Accept"},
  67. {0,100000,0,90,70,-1000,"AK",true,7,"AK"},
  68. {0,10000,0,90,70,500,"UK",true,7,"Unknown Error"},
  69. {0,1000,0,92,3,0,"MM",false,7,"MM"},
  70. {0,1000,0,92,3,0,"MM",false,7,"MM"},
  71. {0,1000,0,90,15,0,"MM",false,7,"MM"},
  72. {0,1000,0,90,80,0,"MM",false,7,"MM"},
  73. };
  74. BLOCK block[32] = {
  75. {0," ","air"},//空气
  76. {6,"██","block"},//土块
  77. {8,"██","block"},//石头
  78. {2,"██","block"},//草方块
  79. {15,"██","block"},//雪块
  80. {4,"██","block"},//岩浆块
  81. {14,"▓▓","fallblock"},//沙块
  82. {8,"II","fallblock"},//铁砧
  83. {9,"██","water"},//水
  84. {9,"▇▇","water"},//水
  85. {9,"▆▆","water"},//水
  86. {9,"▅▅","water"},//水
  87. {9,"▄▄","water"},//水
  88. {9,"▃▃","water"},//水
  89. {9,"▂▂","water"},//水
  90. {9,"▁▁","water"},//水
  91. {12,"██","lava"},//岩浆
  92. {12,"▇▇","lava"},//岩浆
  93. {12,"▆▆","lava"},//岩浆
  94. {12,"▅▅","lava"},//岩浆
  95. {12,"▄▄","lava"},//岩浆
  96. {12,"▃▃","lava"},//岩浆
  97. {12,"▂▂","lava"},//岩浆
  98. {12,"▁▁","lava"},//岩浆
  99. {12,"危","background"},//危
  100. {6,"██","background"},//木头
  101. {10,"▓▓","background"},//树叶
  102. {15,"▓▓","background"},//带雪树叶
  103. {15,"▅▅","bomb"},//TNT爆炸
  104. {12,"Ⅲ","TNT"},//TNT
  105. {7,"Ⅲ","TNT"},//TNT2
  106. {6,"∷","ladder"},//梯子
  107. };
  108. int board[1005][1005];
  109. int setboard[1005][1005];
  110. int bag[100];
  111. int clear_buffer()
  112. {
  113. while(kbhit())
  114. {
  115. if(getch() != EOF);
  116. for(int i = 1; i <= 256; i++)
  117. {
  118. if(GetAsyncKeyState(i));
  119. }
  120. }
  121. return 0;
  122. }
  123. void color(int a)
  124. {
  125. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
  126. /* 1 深蓝色
  127. 2 深绿色
  128. 3 深青色
  129. 4 深红色
  130. 5 深粉色
  131. i 黄色
  132. 7 深白色
  133. 8 灰色
  134. 9 浅蓝色
  135. 10 浅绿色
  136. 11 浅青色
  137. 12 浅红色
  138. 13 浅粉色
  139. 14 浅黄色
  140. 15 浅白色
  141. 背景
  142. 1~15 黑色
  143. 16~31 深蓝色
  144. 32~47 深绿色
  145. 48~63 深青色
  146. 64~79 深红色
  147. 'S'~95 深粉色
  148. 96~111 深黄色
  149. 112~127 深白色
  150. 128~143 灰色
  151. 144~159 浅蓝色
  152. 160~1'A' 浅绿色
  153. 176~191 浅青色
  154. 192~207 浅红色
  155. 208~223 浅粉色
  156. 224~239 浅黄色
  157. 240~255 浅白色
  158. */
  159. }
  160. int init()//听说有人要我增加地图生成的注释,所以我就写了。
  161. {
  162. for(int j = 0; j < 100; j++)
  163. {
  164. bag[j] = 0;//这个...初始化背包
  165. }
  166. for(int i = 0; i < 1000; i++)
  167. {
  168. for(int j = 0; j < 1000; j++)
  169. {
  170. board[i][j] = 0;//初始化地图 (我们的y是倒着来的)
  171. }
  172. }
  173. double lasty = rand() % 101 + 400;//lasty代表上一个我们选择的点的高度。
  174. for(int i = 5; i < 1000; i += 5)//i每次加5,每隔5个点连一条线
  175. {
  176. double y = rand() % 21 - 10 + lasty;//y代表这个点我们选择的高度,为了不出现太陡峭的山,我们只允许这个高度在刚才的点的高低10格内。
  177. y = min(450.0, y);//这是最小高度,防止整个地图都在水里。
  178. double high = lasty;//这个high是用来统计当前高度的,用double可以更加精确。
  179. int dirt = rand() % 5 + 2;//dirt代表这一列上泥土高度。
  180. for(int j = i - 5; j < i; j++)
  181. {
  182. high += (y - lasty) / 5;//high每次增加差距的1/5。
  183. for(int k = 999; k >= (int)high; k--)
  184. {
  185. if(k == (int)high)//如果是最高点
  186. {
  187. setboard[k][j] = 3;//就用草地
  188. if(high <= 350)//如果high比较高
  189. {
  190. setboard[k][j] = 4;//就用雪地
  191. }
  192. }
  193. else if(k - dirt <= (int)high)//泥土
  194. {
  195. setboard[k][j] = 1;
  196. }
  197. else
  198. {
  199. setboard[k][j] = 2;//石头
  200. }
  201. }
  202. }
  203. lasty = y;//赋值
  204. }
  205. //再来一边,填满最后几格
  206. int dirt = rand() % 5 + 2;
  207. double high = lasty;
  208. for(int j = 995; j < 999; j++)
  209. {
  210. for(int k = 999; k >= (int)high; k--)
  211. {
  212. if(k == (int)high)
  213. {
  214. setboard[k][j] = 3;
  215. if(high <= 350)
  216. {
  217. setboard[k][j] = 4;
  218. }
  219. }
  220. else if(k - dirt <= (int)high)
  221. {
  222. setboard[k][j] = 1;
  223. }
  224. else
  225. {
  226. setboard[k][j] = 2;
  227. }
  228. }
  229. }
  230. //填满水,这里默认把海平面高度设为410。
  231. for(int i = 0; i < 1000; i++)
  232. {
  233. for(int j = 600; j >= 410; j--)
  234. {
  235. if(setboard[j][i] == 0)
  236. {
  237. setboard[j][i] = 8;
  238. }
  239. }
  240. }
  241. //沙子
  242. for(int i = 0; i < 1000; i++)
  243. {
  244. bool a = 0;
  245. for(int j = 999; j >= 0; j--)
  246. {
  247. if(a && setboard[j][i] != 0 && setboard[j][i] != 8)
  248. {
  249. setboard[j][i] = 6;
  250. continue;
  251. }
  252. if(setboard[j][i] == 8)
  253. {
  254. continue;
  255. }
  256. if(setboard[j][i + 3] == 8)
  257. {
  258. a = true;
  259. setboard[j][i] = 6;
  260. }
  261. if(setboard[j][i + 2] == 8)
  262. {
  263. a = true;
  264. setboard[j][i] = 6;
  265. }
  266. if(setboard[j][i + 1] == 8)
  267. {
  268. a = true;
  269. setboard[j][i] = 6;
  270. }
  271. if(setboard[j][i - 1] == 8)
  272. {
  273. a = true;
  274. setboard[j][i] = 6;
  275. }
  276. if(setboard[j][i - 2] == 8)
  277. {
  278. a = true;
  279. setboard[j][i] = 6;
  280. }
  281. if(setboard[j][i - 3] == 8)
  282. {
  283. a = true;
  284. setboard[j][i] = 6;
  285. }
  286. if(setboard[j - 2][i] == 8)
  287. {
  288. a = true;
  289. setboard[j][i] = 6;
  290. }
  291. if(setboard[j - 1][i] == 8)
  292. {
  293. a = true;
  294. setboard[j][i] = 6;
  295. }
  296. if(setboard[j - 3][i] == 8)
  297. {
  298. a = true;
  299. setboard[j][i] = 6;
  300. }
  301. if(setboard[j - 4][i] == 8)
  302. {
  303. a = true;
  304. setboard[j][i] = 6;
  305. }
  306. }
  307. }
  308. //树
  309. for(int i = 0; i < 1000; i++)
  310. {
  311. for(int j = 0; j < 1000; j++)
  312. {
  313. if(setboard[j][i] == 0 && block[setboard[j + 1][i]].type == "block")
  314. {
  315. if(rand() % 10 == 1)
  316. {
  317. setboard[j][i] = 25;
  318. setboard[j - 1][i] = 25;
  319. setboard[j - 2][i] = 25;
  320. setboard[j - 3][i] = 25;
  321. setboard[j - 3][i + 1] = 26;
  322. setboard[j - 3][i - 1] = 26;
  323. setboard[j - 4][i + 2] = 26;
  324. setboard[j - 4][i + 1] = 26;
  325. setboard[j - 4][i] = 26;
  326. setboard[j - 4][i - 1] = 26;
  327. setboard[j - 4][i - 2] = 26;
  328. setboard[j - 5][i + 2] = 26;
  329. setboard[j - 5][i + 1] = 26;
  330. setboard[j - 5][i] = 26;
  331. setboard[j - 5][i - 1] = 26;
  332. setboard[j - 5][i - 2] = 26;
  333. setboard[j - 6][i + 1] = 26;
  334. setboard[j - 6][i] = 26;
  335. setboard[j - 6][i - 1] = 26;
  336. if(j <= 350)
  337. {
  338. setboard[j - 3][i + 1] = 27;
  339. setboard[j - 3][i - 1] = 27;
  340. setboard[j - 4][i + 2] = 27;
  341. setboard[j - 4][i + 1] = 27;
  342. setboard[j - 4][i] = 27;
  343. setboard[j - 4][i - 1] = 27;
  344. setboard[j - 4][i - 2] = 27;
  345. setboard[j - 5][i + 2] = 27;
  346. setboard[j - 5][i + 1] = 27;
  347. setboard[j - 5][i] = 27;
  348. setboard[j - 5][i - 1] = 27;
  349. setboard[j - 5][i - 2] = 27;
  350. setboard[j - 6][i + 1] = 27;
  351. setboard[j - 6][i] = 27;
  352. setboard[j - 6][i - 1] = 27;
  353. }
  354. }
  355. }
  356. }
  357. }
  358. //地洞
  359. for(int j = 999; j >= 700; j--)
  360. {
  361. if(rand() % 20 == 1)
  362. {
  363. setboard[j - 3][2] = 0;
  364. setboard[j - 2][2] = 0; setboard[j - 2][3] = 0;
  365. setboard[j - 1][2] = 0; setboard[j - 1][3] = 0; setboard[j - 1][4] = 0;
  366. setboard[j][2] = 0; setboard[j][3] = 0; setboard[j][4] = 0; setboard[j][5] = 0;
  367. setboard[j + 1][2] = 0; setboard[j + 1][3] = 0; setboard[j + 1][4] = 0;
  368. setboard[j + 2][2] = 0; setboard[j + 2][3] = 0;
  369. setboard[j + 3][2] = 0;
  370. }
  371. }
  372. for(int i = 3; i < 997; i++)
  373. {
  374. for(int j = 996; j >= 500; j--)
  375. {
  376. 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)
  377. {
  378. j += rand() % 5 - 2;
  379. j = max(3, j);
  380. j = min(996, j);
  381. if(rand() % 500 <= 499)
  382. {
  383. setboard[j - 3][i] = 0;
  384. setboard[j - 2][i - 1] = 0; setboard[j - 2][i] = 0; setboard[j - 2][i + 1] = 0;
  385. 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;
  386. 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;
  387. 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;
  388. setboard[j + 2][i - 1] = 0; setboard[j + 2][i] = 0; setboard[j + 2][i + 1] = 0;
  389. setboard[j + 3][i] = 0;
  390. if(rand() % 20 == 1)
  391. {
  392. for(int k = 0; k < 100; k++)
  393. {
  394. if(mob[k].shap == "")
  395. {
  396. mob[k] = {0,1000,0,0,0,100,"SS",true,7,"僵尸"};
  397. mob[k].x = i;
  398. mob[k].y = j;
  399. break;
  400. }
  401. }
  402. }
  403. }
  404. }
  405. 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")
  406. {
  407. if(rand() % 500 == 1)
  408. {
  409. setboard[j - 3][i] = 0;
  410. setboard[j - 2][i - 1] = 0; setboard[j - 2][i] = 0; setboard[j - 2][i + 1] = 0;
  411. 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;
  412. 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;
  413. 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;
  414. setboard[j + 2][i - 1] = 0; setboard[j + 2][i] = 0; setboard[j + 2][i + 1] = 0;
  415. setboard[j + 3][i] = 0;
  416. }
  417. }
  418. }
  419. }
  420. //出生点
  421. bool a = false;
  422. for(int i = 400; i < 1000; i++)
  423. {
  424. for(int j = 0; j < 1000; j++)
  425. {
  426. if(setboard[j][i] == 0 && block[setboard[j + 1][i]].type == "block" && (setboard[j + 1][i] == 3 || setboard[j + 1][i] == 4))
  427. {
  428. restartposy = j;
  429. restartposx = i;
  430. y = j;
  431. x = i;
  432. a = true;
  433. break;
  434. }
  435. }
  436. if(a)
  437. {
  438. break;
  439. }
  440. }
  441. return 0;
  442. }
  443. int Arrowmove()
  444. {
  445. for(int i = 0; i < 100; i++)
  446. {
  447. if(arrow[i].shap == "")
  448. {
  449. continue;
  450. }
  451. arrow[i].x += (int)arrow[i].plusx;
  452. arrow[i].plusx -= 0.1;
  453. for(int j = (int)arrow[j].y + 1; j <= (int)arrow[j].y + (int)arrow[j].fallspeed; j++)
  454. {
  455. if(block[board[j][(int)arrow[j].x]].type == "block" || block[board[j][(int)arrow[j].x]].type == "fallblock")
  456. {
  457. arrow[i].fallspeed = 0;
  458. return 0;
  459. }
  460. }
  461. arrow[i].y += arrow[i].fallspeed;
  462. arrow[i].fallspeed += 0.1;
  463. if(arrow[i].y > 999)
  464. {
  465. arrow[i].shap = "";
  466. }
  467. 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")
  468. {
  469. arrow[i].shap = "";
  470. }
  471. }
  472. return 0;
  473. }
  474. int mobmove()
  475. {
  476. for(int j = 0; j < 100; j++)
  477. {
  478. if(mob[j].shap == "")
  479. {
  480. continue;
  481. }
  482. mob[j].hurt = false;
  483. mob[j].color = 7;
  484. if(mob[j].health <= 0 || mob[j].y > 999)
  485. {
  486. mob[j].shap = "";
  487. mob[j].color = 7;
  488. continue;
  489. }
  490. if(block[board[mob[j].y][mob[j].x]].type == "lava")
  491. {
  492. mob[j].health -= 200;
  493. mob[j].hurt = true;
  494. }
  495. 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(' ')))
  496. {
  497. mob[j].health -= 100;
  498. mob[j].hurt = true;
  499. }
  500. if(mob[j].y == y && mob[j].x == x && mob[j].isenemy)
  501. {
  502. health -= mob[j].attack;
  503. hurt = true;
  504. die = "被 " + mob[j].name + " 杀死了";
  505. }
  506. for(int i = mob[j].y - 1; i >= mob[j].y + mob[j].fallspeed; i--)
  507. {
  508. if(block[board[i - 1][mob[j].x]].type == "block")
  509. {
  510. mob[j].fallspeed = 0 - mob[j].y + i + 1;
  511. return 0;
  512. }
  513. }
  514. for(int i = mob[j].y + 1; i <= mob[j].y + mob[j].fallspeed; i++)
  515. {
  516. if(block[board[i][mob[j].x]].type == "block" || block[board[i][mob[j].x]].type == "fallblock")
  517. {
  518. if(mob[j].fallspeed >= 5 && block[board[i - 1][mob[j].x]].type == "water")
  519. {
  520. mob[j].health -= 50 * (mob[j].fallspeed - 4);
  521. mob[j].hurt = true;
  522. }
  523. mob[j].fallspeed = 0;
  524. return 0;
  525. }
  526. }
  527. mob[j].y += mob[j].fallspeed;
  528. mob[j].fallspeed += gravity;
  529. if(mob[j].isenemy)
  530. {
  531. 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"))
  532. {
  533. if(mob[j].y > y + 50)
  534. {
  535. mob[j].fallspeed = -7;
  536. }
  537. mob[j].fallspeed = -3;
  538. }
  539. if(mob[j].x < x)
  540. {
  541. if(block[board[mob[j].y][mob[j].x + 1]].type != "block" || block[board[mob[j].y][mob[j].x + 1]].type != "fallblock")
  542. {
  543. mob[j].x++;
  544. }
  545. else if(block[board[mob[j].y + 1][mob[j].x]].type == "block" || block[board[mob[j].y + 1][mob[j].x]].type != "fallblock")
  546. {
  547. mob[j].fallspeed = -3;
  548. }
  549. }
  550. else if(mob[j].x > x)
  551. {
  552. if(block[board[mob[j].y][mob[j].x - 1]].type != "block" || block[board[mob[j].y][mob[j].x - 1]].type != "fallblock")
  553. {
  554. mob[j].x--;
  555. }
  556. else if(block[board[mob[j].y + 1][mob[j].x]].type == "block" || block[board[mob[j].y + 1][mob[j].x]].type != "fallblock")
  557. {
  558. mob[j].fallspeed = -3;
  559. }
  560. }
  561. }
  562. else
  563. {
  564. if(rand() % 3 == 0)
  565. {
  566. if(block[board[mob[j].y][mob[j].x + 1]].type != "block" || block[board[mob[j].y][mob[j].x + 1]].type != "fallblock")
  567. {
  568. mob[j].x++;
  569. }
  570. else if(block[board[mob[j].y + 1][mob[j].x]].type == "block" || block[board[mob[j].y + 1][mob[j].x]].type != "fallblock")
  571. {
  572. mob[j].fallspeed = -3;
  573. }
  574. }
  575. else if(rand() % 3 == 1)
  576. {
  577. if(block[board[mob[j].y][mob[j].x - 1]].type != "block" || block[board[mob[j].y][mob[j].x - 1]].type != "fallblock")
  578. {
  579. mob[j].x--;
  580. }
  581. else if(block[board[mob[j].y + 1][mob[j].x]].type == "block" || block[board[mob[j].y + 1][mob[j].x]].type != "fallblock")
  582. {
  583. mob[j].fallspeed = -3;
  584. }
  585. }
  586. }
  587. if(mob[j].hurt)
  588. {
  589. mob[j].color = 12;
  590. }
  591. }
  592. return 0;
  593. }
  594. int print()
  595. {
  596. if(!mode)
  597. {
  598. color(8);
  599. cout << "HP:";
  600. color(12);
  601. cout << health << endl;
  602. for(int i = 0; i < health; i += 100)
  603. {
  604. cout << "◆";
  605. }
  606. color(7);
  607. for(int i = health; i < lasthealth; i += 100)
  608. {
  609. cout << "◇";
  610. }
  611. cout << endl;
  612. color(8);
  613. cout << "AIR:";
  614. color(11);
  615. cout << breath << endl;
  616. for(int i = 0; i < breath; i += 10)
  617. {
  618. cout << "●";
  619. }
  620. for(int i = breath; i < 91; i += 10)
  621. {
  622. cout << "○";
  623. }
  624. cout << endl;
  625. color(8);
  626. cout << "HUNGRY:";
  627. color(14);
  628. cout << hungry << endl;
  629. for(int i = 0; i < hungry; i += 100)
  630. {
  631. cout << "§";
  632. }
  633. cout << endl;
  634. }
  635. color(8);
  636. cout << "DIENUM:";
  637. color(4);
  638. cout << dienum << endl;
  639. for(int i = y - 6; i <= y + 6; i++)
  640. {
  641. for(int j = x - 6; j <= x + 6; j++)
  642. {
  643. bool ismob = false;
  644. for(int s = 0; s < 100; s++)
  645. {
  646. if(mob[s].shap == "")
  647. {
  648. continue;
  649. }
  650. else if(mob[s].x == j && mob[s].y == i)
  651. {
  652. color(mob[s].color);
  653. cout << mob[s].shap;
  654. ismob = true;
  655. break;
  656. }
  657. }
  658. if(ismob)
  659. {
  660. continue;
  661. }
  662. for(int s = 0; s < 100; s++)
  663. {
  664. if(arrow[s].shap == "")
  665. {
  666. continue;
  667. }
  668. else if((int)arrow[s].x == j && (int)arrow[s].y == i)
  669. {
  670. color(7);
  671. cout << arrow[s].shap;
  672. ismob = true;
  673. break;
  674. }
  675. }
  676. if(ismob)
  677. {
  678. continue;
  679. }
  680. else if(i == y && j == x)
  681. {
  682. if (KEY_DOWN('S'))
  683. {
  684. color(14);
  685. if(hurt)
  686. {
  687. color(12);
  688. }
  689. cout << "()";
  690. }
  691. else
  692. {
  693. color(9);
  694. if(hurt)
  695. {
  696. color(12);
  697. }
  698. cout << "∏";
  699. }
  700. }
  701. else if(i == y - 1 && j == x)
  702. {
  703. if (!KEY_DOWN('S'))
  704. {
  705. color(14);
  706. if(hurt)
  707. {
  708. color(12);
  709. }
  710. cout << "()";
  711. }
  712. else
  713. {
  714. color(block[board[i][j]].color);
  715. cout << block[board[i][j]].ch;
  716. }
  717. }
  718. else
  719. {
  720. if(i < 0 || i >= 1000 || j < 0 || j >= 1000)
  721. {
  722. cout << " ";
  723. continue;
  724. }
  725. color(block[board[i][j]].color);
  726. cout << block[board[i][j]].ch;
  727. }
  728. }
  729. cout << endl;
  730. }
  731. color(7);
  732. cout << "Y:";
  733. color(6);
  734. cout << 1000 - y << endl;
  735. color(7);
  736. cout << "X:";
  737. color(6);
  738. cout << x << endl;
  739. return 0;
  740. }
  741. int move()
  742. {
  743. if(board[y][x] == 31)
  744. {
  745. y += fallspeed;
  746. return 0;
  747. }
  748. if(block[board[y][x]].type == "water")
  749. {
  750. if(fallspeed > 1)
  751. {
  752. fallspeed = 1;
  753. }
  754. }
  755. else
  756. {
  757. for(int i = y - 1; i >= y + fallspeed; i--)
  758. {
  759. if(block[board[i - 1][x]].type == "block" || block[board[i - 1][x]].type == "fallblock")
  760. {
  761. fallspeed = 0 - y + i + 1;
  762. return 0;
  763. }
  764. }
  765. }
  766. for(int i = y + 1; i <= y + fallspeed; i++)
  767. {
  768. if(block[board[i][x]].type == "block" || block[board[i][x]].type == "fallblock")
  769. {
  770. if(fallspeed >= 5 && block[board[i - 1][x]].type != "water")
  771. {
  772. health -= 50 * (fallspeed - 4);
  773. if(fallspeed >= 7)
  774. {
  775. die = "落地过猛!";
  776. }
  777. else
  778. {
  779. die = "从高处摔了下来!";
  780. }
  781. hurt = true;
  782. }
  783. fallspeed = 0;
  784. return 0;
  785. }
  786. }
  787. y += fallspeed;
  788. fallspeed += gravity;
  789. return 0;
  790. }
  791. int bomb()
  792. {
  793. for(int i = 0; i < 20; i++)
  794. {
  795. if(tnt[i].time == 0)
  796. {
  797. int atk = 0;
  798. if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 4)
  799. {
  800. atk = 50;
  801. fallspeed -= 1;
  802. x += x - tnt[i].x;
  803. }
  804. if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 3)
  805. {
  806. atk = 100;
  807. fallspeed -= 2;
  808. x += x - tnt[i].x;
  809. }
  810. if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 2)
  811. {
  812. atk = 300;
  813. fallspeed -= 4;
  814. x += 2 * (x - tnt[i].x);
  815. }
  816. if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 1)
  817. {
  818. atk = 500;
  819. fallspeed -= 7;
  820. x += 5 * (x - tnt[i].x);
  821. }
  822. if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 0)
  823. {
  824. atk = 800;
  825. fallspeed -= 10;
  826. }
  827. tnt[i].time--;
  828. if(!tnt[i].issave)
  829. {
  830. health -= atk;
  831. }
  832. die = "被TNT炸死了";
  833. if(atk > 0 && !tnt[i].issave)
  834. {
  835. hurt = true;
  836. }
  837. if(!tnt[i].issave)
  838. {
  839. for(int yy = tnt[i].y - 3; yy <= tnt[i].y + 3; yy++)
  840. {
  841. for(int xx = tnt[i].x - 3; xx <= tnt[i].x + 3; xx++)
  842. {
  843. 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)
  844. {
  845. setboard[yy][xx] = 28;
  846. }
  847. 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)
  848. {
  849. setboard[yy][xx] = 0;
  850. }
  851. }
  852. }
  853. }
  854. }
  855. else if(tnt[i].time == -1)
  856. {
  857. setboard[tnt[i].y][tnt[i].x] = 0;
  858. if(!tnt[i].issave)
  859. {
  860. for(int yy = tnt[i].y - 3; yy <= tnt[i].y + 3; yy++)
  861. {
  862. for(int xx = tnt[i].x - 3; xx <= tnt[i].x + 3; xx++)
  863. {
  864. 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)
  865. {
  866. setboard[yy][xx] = 0;
  867. }
  868. }
  869. }
  870. }
  871. tnt[i].time--;
  872. }
  873. else if(tnt[i].time > 0)
  874. {
  875. tnt[i].time--;
  876. if(tnt[i].time % 2 == 0)
  877. {
  878. setboard[tnt[i].y][tnt[i].x] = 29;
  879. }
  880. else
  881. {
  882. setboard[tnt[i].y][tnt[i].x] = 30;
  883. }
  884. }
  885. }
  886. return 0;
  887. }
  888. int check()
  889. {
  890. for(int i = 0; i < 1000; i++)
  891. {
  892. for(int j = 0; j < 1000; j++)
  893. {
  894. if(block[board[i][j]].type == "water" && board[i][j] != 15)
  895. {
  896. if(board[i + 1][j] == 0)
  897. {
  898. setboard[i + 1][j] = board[i][j];
  899. setboard[i + 1][j] = 8;
  900. }
  901. else if(block[board[i + 1][j]].type == "lava")
  902. {
  903. setboard[i + 1][j] = 2;
  904. }
  905. else if(block[board[i + 1][j]].type == "block" || block[board[i + 1][j]].type == "fallblock")
  906. {
  907. if(board[i][j + 1] == 0)
  908. {
  909. setboard[i][j + 1] = board[i][j] + 1;
  910. }
  911. else if(block[board[i][j + 1]].type == "lava")
  912. {
  913. setboard[i][j + 1] = 2;
  914. }
  915. if(board[i][j - 1] == 0)
  916. {
  917. setboard[i][j - 1] = board[i][j] + 1;
  918. }
  919. else if(block[board[i][j - 1]].type == "lava")
  920. {
  921. setboard[i][j - 1] = 2;
  922. }
  923. }
  924. }
  925. if(block[board[i][j]].type == "lava" && board[i][j] != 23)
  926. {
  927. if(board[i + 1][j] == 0)
  928. {
  929. setboard[i + 1][j] = board[i][j];
  930. setboard[i + 1][j] = 16;
  931. }
  932. else if(block[board[i + 1][j]].type == "water")
  933. {
  934. setboard[i + 1][j] = 2;
  935. }
  936. else if(block[board[i + 1][j]].type == "block" || block[board[i + 1][j]].type == "fallblock")
  937. {
  938. if(board[i][j + 1] == 0)
  939. {
  940. setboard[i][j + 1] = board[i][j] + 1;
  941. }
  942. else if(block[board[i][j + 1]].type == "water")
  943. {
  944. setboard[i][j + 1] = 2;
  945. }
  946. if(board[i][j - 1] == 0)
  947. {
  948. setboard[i][j - 1] = board[i][j] + 1;
  949. }
  950. else if(block[board[i][j - 1]].type == "water")
  951. {
  952. setboard[i][j - 1] = 2;
  953. }
  954. }
  955. }
  956. if(block[board[i][j]].type == "fallblock")
  957. {
  958. if(board[i + 2][j] == 0 && board[i + 1][j] == 0 && i + 2 < 100)
  959. {
  960. setboard[i][j] = 0;
  961. setboard[i + 2][j] = board[i][j];
  962. if(board[i][j] == 7 && j == x && i + 2 == y)
  963. {
  964. health -= 600;
  965. hurt = true;
  966. die = "被压扁了";
  967. }
  968. }
  969. else if(board[i + 1][j] == 0 && i + 1 < 100)
  970. {
  971. setboard[i][j] = 0;
  972. setboard[i + 1][j] = board[i][j];
  973. if(board[i][j] == 7 && j == x && i + 1 == y)
  974. {
  975. health -= 600;
  976. hurt = true;
  977. die = "被压扁了";
  978. }
  979. else if(board[i][j] == 7 && j == x && i + 2 == y)
  980. {
  981. health -= 600;
  982. hurt = true;
  983. die = "被压扁了";
  984. }
  985. }
  986. }
  987. }
  988. }
  989. for(int i = 0; i < 1000; i++)
  990. {
  991. for(int j = 0; j < 1000; j++)
  992. {
  993. board[i][j] = setboard[i][j];
  994. }
  995. }
  996. }
  997. int main()
  998. {
  999. srand((int)time(0));
  1000. for(int i = 0; i < 20; i++)
  1001. {
  1002. tnt[i].time = -2;
  1003. }
  1004. init();
  1005. while(1)
  1006. {
  1007. system("cls");
  1008. if(!mode)
  1009. {
  1010. move();
  1011. }
  1012. if(KEY_DOWN('F'))
  1013. {
  1014. setboard[y + 1][x] = 2;
  1015. }
  1016. check();
  1017. bomb();
  1018. Arrowmove();
  1019. mobmove();
  1020. if(mode)
  1021. {
  1022. hurt = false;
  1023. }
  1024. print();
  1025. Sleep(30);
  1026. hungry--;
  1027. hungry = max(hungry, 0);
  1028. if(hungry == 0)
  1029. {
  1030. die = "被饿死了";
  1031. hurt = true;
  1032. health -= 10;
  1033. }
  1034. if(mode)
  1035. {
  1036. health = 1000;
  1037. }
  1038. if(health <= 0)
  1039. {
  1040. Sleep(500);
  1041. system("cls");
  1042. color(12);
  1043. cout << " GAME OVER " << endl;
  1044. color(7);
  1045. cout << " STEVE " << die << endl;
  1046. dienum++;
  1047. Sleep(2000);
  1048. x = restartposx;
  1049. y = restartposy;
  1050. health = 1000;
  1051. hungry = 1000;
  1052. breath = 100;
  1053. fallspeed = 0;
  1054. }
  1055. health += (hungry + 201) / 300;
  1056. if(health > 1000)
  1057. {
  1058. health = 1000;
  1059. }
  1060. if(attack)
  1061. {
  1062. attack = 0;
  1063. }
  1064. if(defense)
  1065. {
  1066. defense = 0;
  1067. }
  1068. if(hurt)
  1069. {
  1070. hurt = false;
  1071. lasthealth = health;
  1072. }
  1073. if(block[board[y][x]].type == "water")
  1074. {
  1075. fallspeed = 1;
  1076. if(KEY_DOWN('W'))
  1077. {
  1078. fallspeed = -1;
  1079. }
  1080. }
  1081. if(block[board[y - 1][x]].type == "water")
  1082. {
  1083. die = "被水淹死了!";
  1084. breath--;
  1085. }
  1086. else
  1087. {
  1088. breath++;
  1089. if(breath > 100)
  1090. {
  1091. breath = 100;
  1092. }
  1093. }
  1094. if(board[y][x] == 31)
  1095. {
  1096. fallspeed = 0;
  1097. if(KEY_DOWN('W'))
  1098. {
  1099. fallspeed = -1;
  1100. }
  1101. if(KEY_DOWN('S'))
  1102. {
  1103. fallspeed = 1;
  1104. }
  1105. }
  1106. if(block[board[y][x]].type == "lava")
  1107. {
  1108. fallspeed = 1;
  1109. if(KEY_DOWN('W'))
  1110. {
  1111. fallspeed = -1;
  1112. }
  1113. die = "试图在岩浆里游泳!";
  1114. hurt = true;
  1115. health -= 100;
  1116. }
  1117. if (KEY_DOWN('W') && !KEY_DOWN('S'))
  1118. {
  1119. if(mode)
  1120. {
  1121. y--;
  1122. }
  1123. else
  1124. {
  1125. if(block[board[y][x]].type != "water" && board[y][x] != 31)
  1126. {
  1127. if(block[board[y + 1][x]].type == "block" || block[board[y + 1][x]].type == "fallblock")
  1128. {
  1129. fallspeed = jumpspeed;
  1130. }
  1131. }
  1132. }
  1133. }
  1134. if (KEY_DOWN('A'))
  1135. {
  1136. if((block[board[y][x - 1]].type != "block" && block[board[y][x - 1]].type != "fallblock") || mode)
  1137. {
  1138. if(KEY_DOWN('S') || (block[board[y - 1][x - 1]].type != "block" && block[board[y - 1][x - 1]].type != "fallblock") || mode)
  1139. {
  1140. x -= 1;
  1141. }
  1142. }
  1143. face = -1;
  1144. }
  1145. if (KEY_DOWN('D'))
  1146. {
  1147. if((block[board[y][x + 1]].type != "block" && block[board[y][x + 1]].type != "fallblock") || mode)
  1148. {
  1149. if(KEY_DOWN('S') || (block[board[y - 1][x + 1]].type != "block" && block[board[y - 1][x + 1]].type != "fallblock") || mode)
  1150. {
  1151. x += 1;
  1152. }
  1153. }
  1154. face = 1;
  1155. }
  1156. if(KEY_DOWN('S'))
  1157. {
  1158. if(mode)
  1159. {
  1160. y++;
  1161. }
  1162. else
  1163. {
  1164. fallspeed += 1;
  1165. }
  1166. }
  1167. if(KEY_DOWN(' '))
  1168. {
  1169. attack = true;
  1170. }
  1171. if(KEY_DOWN('E'))
  1172. {
  1173. system("cls");
  1174. color(7);
  1175. cout << "┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐" << endl;
  1176. for(int i = 0; i < 9; i++)
  1177. {
  1178. color(7);
  1179. cout << "│";
  1180. for(int j = 0; j < 10; j++)
  1181. {
  1182. color(block[bag[i * 10 + j]].color);
  1183. cout << block[bag[i * 10 + j]].ch;
  1184. color(7);
  1185. cout << "│";
  1186. }
  1187. cout << endl;
  1188. color(7);
  1189. cout << "├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤" << endl;
  1190. }
  1191. color(7);
  1192. cout << "│";
  1193. for(int j = 0; j < 10; j++)
  1194. {
  1195. color(block[bag[90 + j]].color);
  1196. cout << block[bag[90 + j]].ch;
  1197. color(7);
  1198. cout << "│";
  1199. }
  1200. color(7);
  1201. cout << endl;
  1202. cout << "└──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘" << endl;
  1203. Sleep(3000);
  1204. }
  1205. if(KEY_DOWN('C'))
  1206. {
  1207. hungry += 100;
  1208. hungry = min(hungry, 1000);
  1209. }
  1210. if(KEY_DOWN('Q'))
  1211. {
  1212. for(int i = 0; i < 20; i++)
  1213. {
  1214. if(tnt[i].time == -2)
  1215. {
  1216. tnt[i] = {y, x, 10, 0};
  1217. break;
  1218. }
  1219. }
  1220. }
  1221. if(KEY_DOWN('i'))
  1222. {
  1223. for(int i = 0; i < 20; i++)
  1224. {
  1225. if(tnt[i].time == -2)
  1226. {
  1227. tnt[i] = {y, x, 10, 1};
  1228. break;
  1229. }
  1230. }
  1231. }
  1232. if(KEY_DOWN('8'))
  1233. {
  1234. for(int i = 0; i < 20; i++)
  1235. {
  1236. if(tnt[i].time == -2)
  1237. {
  1238. tnt[i] = {y, x, 10, 2};
  1239. break;
  1240. }
  1241. }
  1242. }
  1243. if(KEY_DOWN('9'))
  1244. {
  1245. for(int i = 0; i < 20; i++)
  1246. {
  1247. if(tnt[i].time == -2)
  1248. {
  1249. tnt[i] = {y, x, 10, 3};
  1250. break;
  1251. }
  1252. }
  1253. }
  1254. if(KEY_DOWN('0'))
  1255. {
  1256. for(int i = 0; i < 20; i++)
  1257. {
  1258. if(tnt[i].time == -2)
  1259. {
  1260. tnt[i] = {y, x, 10, 4};
  1261. break;
  1262. }
  1263. }
  1264. }
  1265. if(KEY_DOWN('I'))
  1266. {
  1267. for(int i = 0; i < 20; i++)
  1268. {
  1269. if(tnt[i].time == -2)
  1270. {
  1271. tnt[i] = {y, x, 10, 5};
  1272. break;
  1273. }
  1274. }
  1275. }
  1276. if(KEY_DOWN('Z'))
  1277. {
  1278. setboard[y + 1][x] = 0;
  1279. }
  1280. if(KEY_DOWN('X'))
  1281. {
  1282. setboard[y][x] = 24;
  1283. }
  1284. if(KEY_DOWN('3'))
  1285. {
  1286. setboard[y + 1][x] = 6;
  1287. }
  1288. if(KEY_DOWN('4'))
  1289. {
  1290. setboard[y + 1][x] = 7;
  1291. }
  1292. if(KEY_DOWN('1'))
  1293. {
  1294. setboard[y + 1][x] = 8;
  1295. }
  1296. if(KEY_DOWN('2'))
  1297. {
  1298. setboard[y + 1][x] = 16;
  1299. }
  1300. if(KEY_DOWN('5'))
  1301. {
  1302. if(face == 1)
  1303. {
  1304. for(int i = 0; i < 100; i++)
  1305. {
  1306. if(arrow[i].shap == "")
  1307. {
  1308. arrow[i] = {"→",y,x,-0.7,2};
  1309. break;
  1310. }
  1311. }
  1312. }
  1313. else
  1314. {
  1315. for(int i = 0; i < 100; i++)
  1316. {
  1317. if(arrow[i].shap == "")
  1318. {
  1319. arrow[i] = {"←",y,x,-0.7,-2};
  1320. break;
  1321. }
  1322. }
  1323. }
  1324. }
  1325. if(KEY_DOWN('T'))
  1326. {
  1327. clear_buffer();
  1328. system("cls");
  1329. cout << "请输入指令:" << endl;
  1330. string a;
  1331. cin >> a;
  1332. if(a == "kill")
  1333. {
  1334. die = "失败了。";
  1335. hurt = true;
  1336. health = 0;
  1337. }
  1338. if(a == "full_health")
  1339. {
  1340. health = 1000;
  1341. }
  1342. if(a == "creativemode")
  1343. {
  1344. mode = !mode;
  1345. }
  1346. if(a == "move")
  1347. {
  1348. cin >> y >> x;
  1349. y = 1000 - y;
  1350. }
  1351. if(a == "summom")
  1352. {
  1353. int a;
  1354. cin >> a;
  1355. for(int i = 0; i < 100; i++)
  1356. {
  1357. if(mob[i].shap == "")
  1358. {
  1359. mob[i] = mobs[a];
  1360. mob[i].x = x;
  1361. mob[i].y = y;
  1362. break;
  1363. }
  1364. }
  1365. }
  1366. }
  1367. if(KEY_DOWN('O'))
  1368. {
  1369. for(int i = 0; i < 1000; i++)
  1370. {
  1371. for(int j = 0; j < 1000; j++)
  1372. {
  1373. setboard[i][j] = 0;
  1374. }
  1375. }
  1376. }
  1377. if(KEY_DOWN('P'))
  1378. {
  1379. for(int i = 0; i < 1000; i++)
  1380. {
  1381. for(int j = 0; j < 1000; j++)
  1382. {
  1383. setboard[i][j] = 2;
  1384. }
  1385. }
  1386. }
  1387. if(y > 1000)
  1388. {
  1389. die = "掉出了这个世界!";
  1390. hurt = true;
  1391. health -= 200;
  1392. }
  1393. if(breath <= 0)
  1394. {
  1395. breath = 0;
  1396. hurt = true;
  1397. health -= 10;
  1398. }
  1399. if(!KEY_DOWN('S') && block[board[y - 1][x]].type == "block")
  1400. {
  1401. die = "在墙里窒息死亡!";
  1402. hurt = true;
  1403. health -= 50;
  1404. }
  1405. if(board[y + 1][x] == 5)
  1406. {
  1407. hurt = true;
  1408. die = "发现了地板是熔岩做的。";
  1409. health -= 30;
  1410. }
  1411. clear_buffer();
  1412. }
  1413. return 0;
  1414. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/797075
推荐阅读
相关标签
  

闽ICP备14008679号