WHCSRL 技术网

勇闯迷塔小游戏(c++)

        游戏背景:

            在古老的传说中,有一座五层妖塔,塔中住着魔王和他手下的妖精们。

            一日,妖塔中的魔术师决定举办一次祭祀活动,以增强魔王的法力。他们抓来了一个可怜的流浪商人,关在第四层的一个房间里,他被魔术师施了魔法(魔化了),准备拿来当作祭品。

            国王听说此事后,派出了一位勇士(就是你),来到了妖塔下面,你的任务是干掉魔王,为国家除害。当然,你不是空手去的,你随身携带一本怪物书(monster_book),每次杀掉怪物之后,你都会获取与怪物相关的数据。在妖塔中,有很多妖怪散落的装备或者药水可以供你使用,还有一些商店(奸商)给你提供商品。

           ...好了,你自己玩吧...

------------------------------------------------丑不拉叽的分割线---------------------------------------------------------

  1. #include<algorithm>
  2. #include<cmath>
  3. #include<stdio.h>
  4. #include<iostream>
  5. #include<string>
  6. #include<cstring>
  7. #include<windows.h>
  8. #include<conio.h>
  9. #include<cstdlib>
  10. #include<ctime>
  11. #include<fstream>
  12. using namespace std;
  13. #define BNUM 17
  14. #define TOWER 5
  15. #define COLS 40
  16. #define LINES 100
  17. #define RUNE 22
  18. struct BLOCKS
  19. {
  20. string name;
  21. int hp;
  22. int attack;
  23. int defence;
  24. bool go;
  25. bool monster;
  26. int xp;
  27. int number;
  28. };
  29. struct PLAYER
  30. {
  31. string name;
  32. int hp;
  33. int attack;
  34. int defence;
  35. int tower;
  36. int x;
  37. int y;
  38. int xp;
  39. int level;
  40. int money;
  41. };
  42. unsigned long long uplevel[]={0,10,25,40,60,80,150,300,400,650,800,950,1100,1200,1500,1800,2000,3100,5000,6500,7900,8900,9700,10000,12000,14000,15860,17738,18939,20039,21950,25910,27830,29382,31829,33849,35939,36788,38193,41829,43829,45888,47361,49382,51853,54830};
  43. BLOCKS map[BNUM][COLS][LINES];
  44. string runec[RUNE]=
  45. {
  46. "魔王在进行一种祭祀仪式(最高机密,不可泄漏),只要集齐了日月的阴阳之力(眼熟吧),就可以召唤^&*!%%%%!%%%%@(字迹不清)",
  47. "吼...",
  48. "妖怪们最喜欢在一层的这个右侧房间玩耍了,因为有卫兵和骑士把守,十分安全...",
  49. "传说中的储物间中,存放着妖精们的武器和神秘药水,不知有何作用...",
  50. "真是个奇怪的骑士,还带着假面,还是不要惹他为好...",
  51. "长满了青苔和杂草的楼梯间,上面还传来了不明的低吼声...",
  52. "魔法师在这里布下重重迷阵,并制造了许多分身,防止有人破坏了祭祀仪式... ",
  53. "只有通过了迷阵,才能找到下一个楼梯间... ",
  54. "无数的怪物在里面防守着,可见内部可能藏着什么东西... ",
  55. "魔王允许一个人类在这里开设商店,并且高价卖破烂,就是为了坑钱... ",
  56. "迷宫,又是迷宫... ",
  57. "魔法师:&*#$^!...(消失不见)... ",
  58. "魔王将魔兽与人类生下的孩子在这里培养,这些孩子长得歪瓜裂枣(很丑),但好像很喜欢打架... ",
  59. "伪装的魔王在这里等待着客人的来临... ",
  60. "别想着走捷径,傻瓜... ",
  61. "传说中的英文字母表(不会的请回幼儿园重读),不过好像并没有那么简单呢... ",
  62. "一块石碑: 旅行者的血肉,魔术师的魔法,还有被感染的人类,可以召唤 (只有聪明的人才能看见那些东西)... ",
  63. "只要干掉魔王,就能终止祭祀仪式, 就不会出现... ",
  64. "阴之月符文: $&^%%%%!!# 聚集月的阴之力... ",
  65. "阴之日符文:#%%%%^&!$! 聚集日的阴之力... ",
  66. "阳之日符文:!$!&^%%%%# 聚集日的阳之力... ",
  67. "阳之月符文:#!!%%%%^&$ 聚集月的阳之力... ",
  68. };
  69. int rtower[RUNE]={0,0,0,0,0,0,1,1,1,1,1,1,2,2,2,3,4,4,4,4,4,4};
  70. int rposx[RUNE]={2,17,7,6,31,37,1,9,31,1,2,38,3,33,39,2,1,1,16,19,19,22};
  71. int rposy[RUNE]={1,1,3,9,59,97,1,10,1,31,42,97,2,98,92,2,2,3,36,34,40,46};bool DidFile=false;
  72. bool monster_[BNUM]={0};
  73. string sympol=" #shjlmdbzaSftg@";
  74. string Name[BNUM]={"空地","墙","卫兵","骑士","假面骑士","小丑","魔术师","商店","流浪商人_魔化","治疗药水","战斧","盾牌","魔王_假","魔王_真","小鬼","符文"};
  75. int Hp[BNUM]= {0,0,100,200,800,1500,1800,0,1200,0,0,0,3000,6000,500,0};
  76. int Attack[BNUM]= {0,0, 30, 50,220,200, 570,0,400,0,0,0,600,1000,130,0};
  77. int Defence[BNUM]={0,0, 10, 20, 80,120, 220,0,150,0,0,0,350,500,35,0};
  78. bool Go[BNUM]= {1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
  79. bool monster[BNUM]={0,0,1,1,1,1,1,0,1,0,0,0,1,1,1,0};
  80. int Xp[BNUM]={2,0,10,30,60,100,150,0,100,0,0,0,5000,20000,300,10};
  81. PLAYER player;
  82. int sudu=5;
  83. unsigned long long Time,now;
  84. char MAP[TOWER][40][102]=
  85. {
  86. {
  87. "# ##################################################################################################",
  88. "# ## s s #z #a #a # #",
  89. "#@s# a # # h # # # # #",
  90. "#z ########hh#########s######s#####h##### a #",
  91. "# # @ # #",
  92. "# # ##h## ######################## a S S a #",
  93. "# # #h# #h# #zzs # z #",
  94. "# s@ # # ### # a S S a #",
  95. "# #### ##### # # # # #",
  96. "# #ah # # # # a #",
  97. "# #hh # # # # #",
  98. "# ## l lg # # # # #",
  99. "# # mgm # ### ## ##### hh #",
  100. "# # g l # # # # # hhhh #",
  101. "# # # # # # # #############################hh###############",
  102. "# # # # ########## # # #",
  103. "# # # # ######### ## # #",
  104. "#@# ## ##s# # # # # #",
  105. "#f## ## # #jh# # # # # ## # #",
  106. "#f # # # #### # # # # # # # #",
  107. "# ######ss######## # # # # # # # # # #",
  108. "# hh ## ## # ## # # # # # #",
  109. "# # ## # # # # #",
  110. "# # # # # # # # #",
  111. "# # ##### #### # ## # #",
  112. "# # # # ## # #",
  113. "# ####### # # # #",
  114. "###################################################### # #",
  115. "# # #",
  116. "# # #",
  117. "#################### ######################################h######################## ###############",
  118. "# # @ j # #",
  119. "# ####### ##### # # # #",
  120. "# # # # # # #",
  121. "# # # # # # #",
  122. "# # # # # #",
  123. "# # # # # # # #",
  124. "# # # # # # # @j#",
  125. "# ######## #### ####### # # j #",
  126. "####################################################################################################",
  127. },
  128. {
  129. "# ##################################################################################################",
  130. "#@# jSaz# # dj @ # #",
  131. "# # ###### # # # @ #",
  132. "#h # hs # #### #### ## ##### # #### ###### ####### #",
  133. "#z# ##################### # # # # # # # # # # # ## # #",
  134. "#a# z z # # # # # # ##### #### # ###### #",
  135. "# # z ###hs### l hh h # # # # # # ## # # ## # #",
  136. "# # z z # sh # l hh # ##################################################### #",
  137. "# # # # # # # # # # # # ## ## #",
  138. "##########@######################### # ### # # # # # ## # ### # # #",
  139. "# ## # #z # # # # ######################## ## # # # # # #",
  140. "## # #z######### ## # # # # ## # #### ## ## # # # # #",
  141. "# ##### # # # # l # # # ## # # # # # ## # # #",
  142. "#z j # #z# # S # # # ## # # # #### ## # # # #",
  143. "# # z # # ####### # # # ### # m# ## # # ## ##### #",
  144. "# # # #z#z # ## # # # # ###### ## ###### ## # # # # # # # # #",
  145. "# ##### # ####### #zz############## # # # # # # ## ## ## # # # #",
  146. "# z ## #z ## # # # ###### # # ##m #### # # ## # # # #",
  147. "# z# #z ##########z h# S j j# # # f ## # # # # # #",
  148. "# z# ## # # ## # # # # # # # #",
  149. "# # # ################# S # # # #### #### # # # # #",
  150. "# # z # # # # # # # # #",
  151. "#########z ############ # # # #### ### # #",
  152. "# z # # z ############## # # # # # #",
  153. "# z h h z # jj j# # #### #### # #",
  154. "#################### ## a # # # # #",
  155. "# z h zzzz h z # # # # # ##### # #",
  156. "## ####################a S a # # # # # # # #",
  157. "# zh aaaaaa hz # # # ### # # ##### # #",
  158. "#################### ## # # # # # # # #",
  159. "# hz SSSSSSSS zh # a a # # # # ##### f #",
  160. "#@#################################### ############## ######################## ####################",
  161. "#shjjjzsjshjjjjjjhsjsslfjfjjjshljsh #### # #### #### ##### zzzzzzzz #",
  162. "#sajjjzazjjzSshsajsssh######## ### ###### # # # # # zaaaaaaz #",
  163. "#hzzsjsjzsjSjsjhjzjjjjshshhhslshhsh #a# # #### ### ##### zSSSSSSz #",
  164. "#sjzsSzSzsSjjhsahhhhSh######## ### ####a# # # # # # zzzzzzzz #",
  165. "#sjjsssSzajjjsSjjjsshj#sszhzjahhsms #a# # #### #### ##### #",
  166. "#hjhzjassssssjssssshjj###########################################################################m##",
  167. "#jjhsjssjjhsssssjjsssajjjljjjjjjjjj @ #",
  168. "####################################################################################################",
  169. },
  170. {
  171. "####################################################################################################",
  172. "# # #",
  173. "##@g g g g ggggggggggg #",
  174. "#gg##g#g#g#g#g#######g##########################g###############g################################ #",
  175. "# g g g g g #",
  176. "#gg##g#g#g#g#g#########g######################g#################g################################ #",
  177. "# g g g g g #",
  178. "#gg##g#g#g#g#g###########g##################g###################g################################ #",
  179. "# g g g g g #",
  180. "#gg##g#g#g#g#g#############g##############g#####################g################################ #",
  181. "# g g g g g #",
  182. "#gg##g#g#g#g#g###############g##########g#######################g################################ #",
  183. "# g g g g g #",
  184. "#gg##g#g#g#g#g#################g######g#########################g##########gggggggggg############ #",
  185. "# g g g g g #",
  186. "#gg##g#g#g#g#g###################g##g###########################g################################ #",
  187. "# g g gg g #",
  188. "#gg##g#g#g#g#g####################gg############################g##########gggggggggg############ #",
  189. "# g g g g g #",
  190. "#gg##g#g#g#g#g##################g####g##########################g################################ #",
  191. "# g g g g g #",
  192. "#gg##g#g#g#g#g################g########g########################g################################ #",
  193. "# g g g g g #",
  194. "#jj##g#g#g#g#g##############g############g######################g################################ #",
  195. "# g g g g g #",
  196. "#jj##g#g#g#g#g############g################g####################g################################ #",
  197. "# g g g g g #",
  198. "#jj##g#g#g#g#g##########g####################g##################g################################ #",
  199. "# g g g g g #",
  200. "#gg##g#g#g#g#g########g########################g################g################################ #",
  201. "# g g g g g #",
  202. "#gg##g#g#g#g#g######g############################g##############g################################ #",
  203. "# g # z aaaaaa s a @#",
  204. "## # # zzzzzzz a a a sa zzz#",
  205. "# # # z z z a aa a zs zzz#",
  206. "## ##z zzz z aaaa z s #z#",
  207. "# # # z aaaaa #z#",
  208. "# # ###########################################################################################f#",
  209. "# # @mlfff #",
  210. "####################################################################################################",
  211. },
  212. {
  213. "####################################################################################################",
  214. "# j a # # # # #",
  215. "#j@ a a # bggg # zzz # mmmm # #",
  216. "# a a # g g # z z # l m # jjjjjj #",
  217. "# aaaaaaa g gggg g z # l m # j #",
  218. "# a a # g g # z z l l d m l jjjjj #",
  219. "# a a # g g # zzzz # l m # j #",
  220. "# # ggggg # # l m # j #",
  221. "# # # # mmmmm # jjjjjjj #",
  222. "# # # # # #",
  223. "##########################################################################################l#########",
  224. "# # # # # #",
  225. "# # # # # #",
  226. "# # # jjjjjj # # # # # ######## #",
  227. "# # # j # # # # gggggg # # #",
  228. "# # # j # # # # g g # # #",
  229. "# # # # j # ###### # # g # # #",
  230. "# # # j # # # # j g gggggg g ###### #",
  231. "# ### # j j # # # # # g g # # #",
  232. "# # # # jj # # # # # g g # # #",
  233. "# # # # # # # # # # ggggggg # # #",
  234. "# # # # # # # #",
  235. "# # # # # #",
  236. "###### #############################################################################################",
  237. "# # # # # #",
  238. "# l # # # # # jj # ##### #",
  239. "# l # # ## # # j j # # # #",
  240. "# l # # # # # # j j # ##### #",
  241. "# l # # # # # j j # #",
  242. "# l # # # # # # j j # # #",
  243. "# l l # # # ## # jjj # # #",
  244. "# llllllll # # # # # # #",
  245. "# # # # # #",
  246. "######## ################# ##################### ##################### ################### #########",
  247. "# # # #m## # zzzz # lll #",
  248. "# g g # ##### # # # z z # l l #",
  249. "# g g # # # # zzz # l ll #",
  250. "# g g # # # #### # z z # llll #",
  251. "# ggg g # # # # # # # l #",
  252. "####################################################################################################",
  253. },
  254. {
  255. "####################################################################################################",
  256. "# @@ m # ##",
  257. "### mmm # # #",
  258. "# # # # # # # #",
  259. "# # # # # # #",
  260. "# # # # # # # #",
  261. "# # # # # # #",
  262. "# # # # # # # #",
  263. "# # #a a# # # #",
  264. "# # # aa aa # # # # #",
  265. "# # # aaa aaaa aaa # # # #",
  266. "# # # aaaa # # # # #",
  267. "# # # aaaa # # # #",
  268. "# # #z aaaa z# # # # #",
  269. "# # # z z # # # #",
  270. "# # # z z # # # # #",
  271. "# # # z ###@### z # # # #",
  272. "# # # zzzz # # zzzzz # # # # #",
  273. "# m m zzzz # fff # z zzzz mm # #",
  274. "# mmm zzzzz @ ftf @ z zzzz mm mm #",
  275. "# mmm zzzz z# fff #z zzzz mm mm #",
  276. "# m m a # # a mm # #",
  277. "# # # a ###@### a # # # # #",
  278. "# # # a a # # # #",
  279. "# # # a a # # # # #",
  280. "# # # a zzzz a # # # #",
  281. "# # # aSSS zzzz SSSa # # # # #",
  282. "# # # SS zzzz SS # # # #",
  283. "# # #S zzzz S# # # # #",
  284. "# # # # # # #",
  285. "# # # # # # # #",
  286. "# # # # # # #",
  287. "# # # # # # # #",
  288. "# # # # # # #",
  289. "# # # # # # # #",
  290. "# # # # # # #",
  291. "# # # # # # # #",
  292. "# # mmm # # #",
  293. "## m # ##",
  294. "####################################################################################################",
  295. },
  296. };
  297. int tower=0;
  298. void addlevels();
  299. int AttAck(int attack);
  300. void AttackMonster();
  301. void color(int x);
  302. void cls();
  303. void coutwhat(int a,int b,int c,int d,string n);
  304. void Die();
  305. void game();
  306. char getin(char x,char y);
  307. void gotoxy(int y,int x);
  308. void gs();
  309. void hidden();
  310. void init();
  311. void monsterbook();
  312. void PrintfMap(int x);
  313. int random(int n,int m);
  314. void rf();
  315. void Sout(string n);
  316. void wf();
  317. void shop();
  318. void bnm();
  319. void monsterbook()
  320. {
  321. cls();
  322. int i,j,k;
  323. for(i=0;i<BNUM;i++)
  324. if (monster[i])
  325. if (monster_[i])
  326. printf("%%%%c %%%%s attack:%%%%d hp:%%%%d defence:%%%%d ------------------------------- ",sympol[i],Name[i].c_str(),Attack[i],Hp[i],Defence[i]);
  327. else
  328. printf("??? ------------------------------- ");
  329. gs();
  330. PrintfMap(player.tower);
  331. }
  332. int AttAck(int attack)
  333. {
  334. int i=0,j=1;
  335. gotoxy(10,0);
  336. cout<<"按空格攻击 ";
  337. cout<<"Low High Low ";
  338. cout<<"------------------------------------------------------------ ";
  339. cout<<"------------------------------------------------------------";
  340. float shang[60]=
  341. {0.1,0.1,0.1,0.2,0.2,0.2,0.2,0.3,0.3,0.3,0.3,0.5,0.5,0.5,0.6,0.6,0.6,0.7,0.7,0.7,0.7,0.7,0.8,0.9,0.9,1.0,1.2,1.5,2.0,1.5,1.2,0.9,0.9,0.8,0.8,0.7,0.7,0.7,0.7,0.6,0.6,0.6,0.5,0.5,0.5,0.4,0.4,0.4,0.3,0.2,0.2,0.2,0.2,0.1,0.1,0.1,0.6,0.4,0.4,0.1};
  342. while(1)
  343. {
  344. gotoxy(13,i-j);
  345. cout<<" ";
  346. gotoxy(13,i);
  347. cout<<"|#|";
  348. char m;
  349. if (kbhit())
  350. {
  351. m=getch();
  352. if (m==' ')
  353. return attack*(shang[i])+attack*0.3;
  354. }
  355. i+=j;
  356. if (i>=60)
  357. j=-j;
  358. if (i<=0)
  359. j=-j;
  360. Sleep(1);
  361. }
  362. }
  363. void init()
  364. {
  365. int i,j,k,I;
  366. Time=time_t();
  367. printf("初始化请稍等...");
  368. for(I=0;I<TOWER;I++)
  369. for(i=0;i<40;i++)
  370. {
  371. for(j=0;j<100;j++)
  372. {
  373. k=sympol.find(MAP[I][i][j]);
  374. map[I][i][j].name=Name[k];
  375. map[I][i][j].attack=Attack[k];
  376. map[I][i][j].hp=Hp[k];
  377. map[I][i][j].defence=Defence[k];
  378. map[I][i][j].go=Go[k];
  379. map[I][i][j].monster=monster[k];
  380. map[I][i][j].number=k;
  381. map[I][i][j].xp=Xp[k];
  382. }
  383. }
  384. player.tower=0;
  385. player.hp=150;
  386. player.attack=35;
  387. player.defence=15;
  388. player.xp=1;
  389. player.level=1;
  390. player.x=1;
  391. player.y=1;
  392. system("cls");
  393. }
  394. void coutwhat(int a,int b,int c,int d,string n)//输出一些东西,从坐标(a,b)到(c,d)输出n
  395. {
  396. int i,j;
  397. for(i=a;i<=c;i++)
  398. {
  399. gotoxy(i,b);
  400. for(j=b;j<=d;j++)
  401. {
  402. cout<<n;
  403. }
  404. }
  405. }
  406. void gotoxy(int y,int x) //移动光标
  407. {
  408. COORD coord;
  409. coord.X=x;
  410. coord.Y=y;
  411. HANDLE a=GetStdHandle(STD_OUTPUT_HANDLE);
  412. SetConsoleCursorPosition(a,coord);
  413. }
  414. void color(int x)//调颜色
  415. {
  416. switch(x)
  417. {
  418. case 0:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);break;
  419. case 1:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_GREEN);break;
  420. case 2:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE |FOREGROUND_GREEN);break;
  421. case 3:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE |FOREGROUND_GREEN);break;
  422. case 4:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE);break;
  423. case 5:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE |FOREGROUND_RED);break;
  424. case 7:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);break;
  425. case 8:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED|FOREGROUND_GREEN);break;
  426. case 9:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED|FOREGROUND_BLUE);break;
  427. case 10:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED);break;
  428. default:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_BLUE);break;
  429. }
  430. }
  431. char getin(char x,char y)
  432. {
  433. char l;
  434. do
  435. l=_getch();
  436. while(l<x||l>y);
  437. return l;
  438. }
  439. int random(int n,int m)
  440. {
  441. int s;
  442. s=rand()%%%%(m-n+1);
  443. s+=n;
  444. return s;
  445. }
  446. void cls()
  447. {
  448. system("cls");
  449. }
  450. void shop()
  451. {
  452. cls();
  453. int much[10]={30,50,120,30,50,150,30,50,120};
  454. while(1)
  455. {printf("欢迎,你想买些什么?");
  456. printf("1.锈迹斑斑的铁剑 (attack+3) $30 ");
  457. printf("2.崭新的铁剑 (attack+5) $50 ");
  458. printf("3.银光闪闪的宝剑 (attack+12) $120 ");
  459. printf("4.发霉的药水 (hp+20) $30 ");
  460. printf("5.普通的药水 (hp+40) $50 ");
  461. printf("6.高级药水 (hp+500 attack+10) $150 ");
  462. printf("7.破烂盾牌 (defence+1) $30 ");
  463. printf("8.木头盾牌 (defence+2) $50 ");
  464. printf("9.坚固的铁盾(defence+4) $120 ");
  465. printf("0.离开 $0 ");
  466. char n=_getch();
  467. if (n=='0')
  468. break;
  469. printf("确定买%%%%c吗?Y/N",n);
  470. char m=_getch();
  471. if (m=='N'||m=='n')
  472. continue;
  473. if (player.money<much[n-'0'])
  474. printf("钱不够!");
  475. else
  476. {
  477. printf("购买成功!");
  478. player.money-=much[n-'0'];
  479. switch(n)
  480. {
  481. case '1':player.attack+=3;break;
  482. case '2':player.attack+=5;break;
  483. case '3':player.attack+=12;break;
  484. case '4':player.hp+=20;break;
  485. case '5':player.hp+=40;break;
  486. case '6':player.hp+=500,player.attack+=10;break;
  487. case '7':player.defence++;break;
  488. case '8':player.defence+=2;break;
  489. case '9':player.defence+=4;break;
  490. }
  491. }
  492. system("cls");
  493. }
  494. PrintfMap(player.tower);
  495. }
  496. void Sout(string n)
  497. {
  498. for(int i=0;i<n.size();i++)
  499. {
  500. cout<<n[i];
  501. Sleep(sudu);
  502. if (kbhit())
  503. if (getch()==' ')
  504. {
  505. cout<<n.substr(i+1,n.size()-i);
  506. return;
  507. }
  508. }
  509. }
  510. void hidden()
  511. {
  512. HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
  513. CONSOLE_CURSOR_INFO CursorInfo;GetConsoleCursorInfo(handle, &CursorInfo);
  514. CursorInfo.bVisible = false;
  515. SetConsoleCursorInfo(handle, &CursorInfo);
  516. }
  517. void gs()
  518. {
  519. hidden();
  520. gotoxy(45,80);
  521. cout<<"按下任意键继续_";
  522. _getch();
  523. system("cls");
  524. }
  525. void PrintfMap(int x)
  526. {
  527. cls();
  528. gotoxy(0,0);
  529. int i,j;
  530. for(i=0;i<40;i++)
  531. {
  532. for(j=0;j<100;j++)
  533. {
  534. printf("%%%%c",MAP[x][i][j]);
  535. }
  536. printf(" ");
  537. }
  538. for(i=0;i<BNUM;i++)
  539. if (monster[i]==false)
  540. {
  541. gotoxy(i+10,105);
  542. printf("%%%%c %%%%s ",sympol[i],Name[i].c_str());
  543. }
  544. }
  545. void Die()
  546. {
  547. cls();
  548. sudu=150;
  549. Sout("你 死 了");
  550. sudu=10;
  551. exit(0);
  552. gs();
  553. rf();
  554. }
  555. void AttackMonster(int x,int y)
  556. {
  557. cls();
  558. BLOCKS j;
  559. char l;
  560. int n,m;
  561. j=map[player.tower][player.x][player.y];
  562. n=player.attack;
  563. player.attack*=0.9;//考虑玩家不一定全部能正中
  564. if (j.attack-player.defence>0)
  565. {
  566. m=player.hp/(j.attack-player.defence);
  567. if (player.attack-j.defence<=0)
  568. {
  569. printf("你现在可能还打不过他呢,是否继续挑战?Y.yes N.no");
  570. l=_getch();
  571. player.attack=n;
  572. if (l=='n'||l=='N')
  573. {
  574. PrintfMap(player.tower);
  575. player.x=x,player.y=y;
  576. return;
  577. }
  578. }
  579. m*=(player.attack-j.defence);
  580. if (m<=j.hp)
  581. {
  582. printf("你现在可能还打不过他呢,是否继续挑战?Y.yes N.no");
  583. l=_getch();
  584. player.attack=n;
  585. if (l=='n'||l=='N')
  586. {
  587. PrintfMap(player.tower);
  588. player.x=x,player.y=y;
  589. return;
  590. }
  591. }
  592. }
  593. player.attack=n;
  594. while(j.hp>0&&player.hp>0)
  595. {
  596. cls();
  597. printf("敌人:%%%%s ",j.name.c_str());
  598. printf("敌人的血量:%%%%d ",j.hp);
  599. printf("敌人的攻击:%%%%d ",j.attack);
  600. printf("敌人的防御:%%%%d ",j.defence);
  601. printf("你的血量:%%%%d ",player.hp);
  602. printf("你的攻击:%%%%d ",player.attack);
  603. printf("你的防御:%%%%d ",player.defence);
  604. printf("1.attack 2.run away ");
  605. l=_getch();
  606. if (l=='2')
  607. if (rand()%%%%4==1&&j.name!="魔术师"&&j.name!="魔王_真")
  608. {
  609. map[player.tower][player.x][player.y].hp=j.hp;
  610. return;
  611. }
  612. else
  613. printf("逃跑失败!");
  614. n=AttAck(player.attack);
  615. n-=j.defence;
  616. j.hp-=n;
  617. if (n<=0)
  618. n=1;
  619. printf("你发起了攻击,%%%%s受到了%%%%d点伤害! ",j.name.c_str(),n);
  620. n=j.attack*random(9,12)/10.0;
  621. n-=player.defence;
  622. if (n<=0)
  623. n=1;
  624. player.hp-=n;
  625. printf("%%%%s发起了攻击,你受到了%%%%d点伤害! ",j.name.c_str(),n);
  626. gs();
  627. }
  628. if (player.hp<=0)
  629. Die();
  630. if (map[player.tower][player.x][player.y].name=="魔王_真")
  631. {
  632. system("cls");
  633. Sout("你成功打败了魔王,游戏结束,你赢了!");
  634. exit(0);
  635. }
  636. if (map[player.tower][player.x][player.y].name=="流浪商人_魔化")
  637. map[player.tower][player.x][player.y].name="流浪商人";
  638. map[player.tower][player.x][player.y].hp=0;
  639. map[player.tower][player.x][player.y].attack=0;
  640. map[player.tower][player.x][player.y].defence=0;
  641. map[player.tower][player.x][player.y].go=1;
  642. map[player.tower][player.x][player.y].monster=0;
  643. monster_[map[player.tower][player.x][player.y].number]=1;
  644. player.money+=Xp[map[player.tower][player.x][player.y].number];
  645. MAP[player.tower][player.x][player.y]=' ';
  646. PrintfMap(player.tower);
  647. return;
  648. }
  649. void addlevels()
  650. {
  651. while(player.xp>uplevel[player.level])
  652. player.level++,player.hp+=80,player.attack+=6,player.defence+=3;
  653. }
  654. void game()
  655. {
  656. char l;
  657. int i,j,k,n,m;
  658. while(player.tower<TOWER)
  659. {
  660. PrintfMap(player.tower);
  661. Time=clock();
  662. do
  663. {
  664. l=',';
  665. hidden();
  666. int sx,sy;
  667. sx=player.x,sy=player.y;
  668. gotoxy(42,0);
  669. printf("LEVEL:%%%%d XP:%%%%d/%%%%lld ",player.level,player.xp,uplevel[player.level]);
  670. gotoxy(43,0);
  671. printf("HP:%%%%d ATTACK:%%%%d DEFENCE:%%%%d ",player.hp,player.attack,player.defence);
  672. gotoxy(44,0);
  673. printf("MONEY:%%%%d ",player.money);
  674. gotoxy(player.x,player.y);
  675. cout<<"O";
  676. if (kbhit())
  677. l=getch();
  678. now=clock();
  679. gotoxy(0,105);
  680. k=now-Time;
  681. printf("%%%%d:%%%%d:%%%%d.%%%%d",k/3600000,k%%%%3600000/60000,k%%%%60000/1000,k%%%%1000);
  682. switch(l)
  683. {
  684. case 'w':if (player.x>0&&map[player.tower][player.x-1][player.y].go) player.x--;break;
  685. case 's':if (player.x<COLS&&map[player.tower][player.x+1][player.y].go) player.x++;break;
  686. case 'a':if (player.y>0&&map[player.tower][player.x][player.y-1].go) player.y--;break;
  687. case 'd':if (player.y<LINES&&map[player.tower][player.x][player.y+1].go) player.y++;break;
  688. case 'm':monsterbook();break;
  689. case '/':cin>>n;if (n<5)player.tower=n;else player.hp+=n,player.attack+=n,player.defence+=n,player.money+=n*100;
  690. }
  691. if (sx!=player.x||sy!=player.y)
  692. {
  693. gotoxy(sx,sy);
  694. cout<<" ";
  695. gotoxy(player.x,player.y);
  696. cout<<"O";
  697. }
  698. if (map[player.tower][player.x][player.y].monster)
  699. if (MessageBox(NULL,TEXT("是否挑战此怪物?"),TEXT("?"),MB_YESNO)==IDYES)
  700. AttackMonster(sx,sy);
  701. else
  702. {
  703. gotoxy(player.x,player.y);
  704. printf("%%%%c",MAP[player.tower][player.x][player.y]);
  705. player.x=sx,player.y=sy;
  706. }
  707. gotoxy(45,0);
  708. printf("位置:%%%%d,%%%%d,%%%%d",player.x,player.tower+1,player.y);
  709. if (map[player.tower][player.x][player.y].hp<=0)
  710. player.xp+=map[player.tower][player.x][player.y].xp;
  711. addlevels();
  712. map[player.tower][player.x][player.y].xp=0;
  713. if (map[player.tower][player.x][player.y].number==9)
  714. player.hp+=50,MAP[player.tower][player.x][player.y]=' ',map[player.tower][player.x][player.y].number=0;
  715. if (map[player.tower][player.x][player.y].number==10)
  716. player.attack+=10,MAP[player.tower][player.x][player.y]=' ',map[player.tower][player.x][player.y].number=0;
  717. if (MAP[player.tower][player.x][player.y]=='S')
  718. player.defence+=4,MAP[player.tower][player.x][player.y]=' ',map[player.tower][player.x][player.y].number=0;
  719. if (MAP[player.tower][player.x][player.y]=='d'||map[player.tower][player.x][player.y].name=="流浪商人")
  720. {
  721. shop();
  722. gotoxy(player.x,player.y);
  723. printf("%%%%c",MAP[player.tower][player.x][player.y]);
  724. player.x=sx,player.y=sy;
  725. }
  726. if (MAP[player.tower][player.x][player.y]=='@')
  727. {
  728. gotoxy(46,0);
  729. for(i=0;i<RUNE;i++)
  730. if (player.tower==rtower[i]&&player.x==rposx[i]&&player.y==rposy[i])
  731. break;
  732. printf("石碑内容:%%%%s",runec[i].c_str());
  733. }
  734. else
  735. {
  736. gotoxy(46,0);
  737. printf(" ");
  738. }
  739. }
  740. while(!((player.x==COLS-2&&player.y==LINES-2)||(player.x==0&&player.y==1&&player.tower>0)));
  741. if (player.x==COLS-2&&player.y==LINES-2)
  742. player.tower++,player.x=1,player.y=1;
  743. else if (player.tower>0)
  744. player.tower--,player.x=38,player.y=98;
  745. //wf();
  746. }
  747. }
  748. int main()
  749. {
  750. char l;
  751. int i,j,k;
  752. hidden();
  753. init();
  754. game();
  755. return 0;
  756. }

推荐阅读