勇闯迷塔小游戏(c++)
Posted MCYH0206
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了勇闯迷塔小游戏(c++)相关的知识,希望对你有一定的参考价值。
游戏背景:
在古老的传说中,有一座五层妖塔,塔中住着魔王和他手下的妖精们。
一日,妖塔中的魔术师决定举办一次祭祀活动,以增强魔王的法力。他们抓来了一个可怜的流浪商人,关在第四层的一个房间里,他被魔术师施了魔法(魔化了),准备拿来当作祭品。
国王听说此事后,派出了一位勇士(就是你),来到了妖塔下面,你的任务是干掉魔王,为国家除害。当然,你不是空手去的,你随身携带一本怪物书(monster_book),每次杀掉怪物之后,你都会获取与怪物相关的数据。在妖塔中,有很多妖怪散落的装备或者药水可以供你使用,还有一些商店(奸商)给你提供商品。
...好了,你自己玩吧...
------------------------------------------------丑不拉叽的分割线---------------------------------------------------------
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<iostream>
#include<string>
#include<cstring>
#include<windows.h>
#include<conio.h>
#include<cstdlib>
#include<ctime>
#include<fstream>
using namespace std;
#define BNUM 17
#define TOWER 5
#define COLS 40
#define LINES 100
#define RUNE 22
struct BLOCKS
{
string name;
int hp;
int attack;
int defence;
bool go;
bool monster;
int xp;
int number;
};
struct PLAYER
{
string name;
int hp;
int attack;
int defence;
int tower;
int x;
int y;
int xp;
int level;
int money;
};
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};
BLOCKS map[BNUM][COLS][LINES];
string runec[RUNE]=
{
"魔王在进行一种祭祀仪式(最高机密,不可泄漏),只要集齐了日月的阴阳之力(眼熟吧),就可以召唤^&*!%!%@(字迹不清)",
"吼...",
"妖怪们最喜欢在一层的这个右侧房间玩耍了,因为有卫兵和骑士把守,十分安全...",
"传说中的储物间中,存放着妖精们的武器和神秘药水,不知有何作用...",
"真是个奇怪的骑士,还带着假面,还是不要惹他为好...",
"长满了青苔和杂草的楼梯间,上面还传来了不明的低吼声...",
"魔法师在这里布下重重迷阵,并制造了许多分身,防止有人破坏了祭祀仪式...\\n",
"只有通过了迷阵,才能找到下一个楼梯间...\\n",
"无数的怪物在里面防守着,可见内部可能藏着什么东西...\\n",
"魔王允许一个人类在这里开设商店,并且高价卖破烂,就是为了坑钱...\\n",
"迷宫,又是迷宫...\\n",
"魔法师:&*#$^!...(消失不见)...\\n",
"魔王将魔兽与人类生下的孩子在这里培养,这些孩子长得歪瓜裂枣(很丑),但好像很喜欢打架...\\n",
"伪装的魔王在这里等待着客人的来临...\\n",
"别想着走捷径,傻瓜...\\n",
"传说中的英文字母表(不会的请回幼儿园重读),不过好像并没有那么简单呢...\\n",
"一块石碑: 旅行者的血肉,魔术师的魔法,还有被感染的人类,可以召唤 (只有聪明的人才能看见那些东西)...\\n",
"只要干掉魔王,就能终止祭祀仪式, 就不会出现...\\n",
"阴之月符文: $&^%!!# 聚集月的阴之力...\\n",
"阴之日符文:#%^&!$! 聚集日的阴之力...\\n",
"阳之日符文:!$!&^%# 聚集日的阳之力...\\n",
"阳之月符文:#!!%^&$ 聚集月的阳之力...\\n",
};
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};
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};
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;
bool monster_[BNUM]={0};
string sympol=" #shjlmdbzaSftg@";
string Name[BNUM]={"空地","墙","卫兵","骑士","假面骑士","小丑","魔术师","商店","流浪商人_魔化","治疗药水","战斧","盾牌","魔王_假","魔王_真","小鬼","符文"};
int Hp[BNUM]= {0,0,100,200,800,1500,1800,0,1200,0,0,0,3000,6000,500,0};
int Attack[BNUM]= {0,0, 30, 50,220,200, 570,0,400,0,0,0,600,1000,130,0};
int Defence[BNUM]={0,0, 10, 20, 80,120, 220,0,150,0,0,0,350,500,35,0};
bool Go[BNUM]= {1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
bool monster[BNUM]={0,0,1,1,1,1,1,0,1,0,0,0,1,1,1,0};
int Xp[BNUM]={2,0,10,30,60,100,150,0,100,0,0,0,5000,20000,300,10};
PLAYER player;
int sudu=5;
unsigned long long Time,now;
char MAP[TOWER][40][102]=
{
{
"# ##################################################################################################",
"# ## s s #z #a #a # #",
"#@s# a # # h # # # # #",
"#z ########hh#########s######s#####h##### a #",
"# # @ # #",
"# # ##h## ######################## a S S a #",
"# # #h# #h# #zzs # z #",
"# s@ # # ### # a S S a #",
"# #### ##### # # # # #",
"# #ah # # # # a #",
"# #hh # # # # #",
"# ## l lg # # # # #",
"# # mgm # ### ## ##### hh #",
"# # g l # # # # # hhhh #",
"# # # # # # # #############################hh###############",
"# # # # ########## # # #",
"# # # # ######### ## # #",
"#@# ## ##s# # # # # #",
"#f## ## # #jh# # # # # ## # #",
"#f # # # #### # # # # # # # #",
"# ######ss######## # # # # # # # # # #",
"# hh ## ## # ## # # # # # #",
"# # ## # # # # #",
"# # # # # # # # #",
"# # ##### #### # ## # #",
"# # # # ## # #",
"# ####### # # # #",
"###################################################### # #",
"# # #",
"# # #",
"#################### ######################################h######################## ###############",
"# # @ j # #",
"# ####### ##### # # # #",
"# # # # # # #",
"# # # # # # #",
"# # # # # #",
"# # # # # # # #",
"# # # # # # # @j#",
"# ######## #### ####### # # j #",
"####################################################################################################",
},
{
"# ##################################################################################################",
"#@# jSaz# # dj @ # #",
"# # ###### # # # @ #",
"#h # hs # #### #### ## ##### # #### ###### ####### #",
"#z# ##################### # # # # # # # # # # # ## # #",
"#a# z z # # # # # # ##### #### # ###### #",
"# # z ###hs### l hh h # # # # # # ## # # ## # #",
"# # z z # sh # l hh # ##################################################### #",
"# # # # # # # # # # # # ## ## #",
"##########@######################### # ### # # # # # ## # ### # # #",
"# ## # #z # # # # ######################## ## # # # # # #",
"## # #z######### ## # # # # ## # #### ## ## # # # # #",
"# ##### # # # # l # # # ## # # # # # ## # # #",
"#z j # #z# # S # # # ## # # # #### ## # # # #",
"# # z # # ####### # # # ### # m# ## # # ## ##### #",
"# # # #z#z # ## # # # # ###### ## ###### ## # # # # # # # # #",
"# ##### # ####### #zz############## # # # # # # ## ## ## # # # #",
"# z ## #z ## # # # ###### # # ##m #### # # ## # # # #",
"# z# #z ##########z h# S j j# # # f ## # # # # # #",
"# z# ## # # ## # # # # # # # #",
"# # # ################# S # # # #### #### # # # # #",
"# # z # # # # # # # # #",
"#########z ############ # # # #### ### # #",
"# z # # z ############## # # # # # #",
"# z h h z # jj j# # #### #### # #",
"#################### ## a # # # # #",
"# z h zzzz h z # # # # # ##### # #",
"## ####################a S a # # # # # # # #",
"# zh aaaaaa hz # # # ### # # ##### # #",
"#################### ## # # # # # # # #",
"# hz SSSSSSSS zh # a a # # # # ##### f #",
"#@#################################### ############## ######################## ####################",
"#shjjjzsjshjjjjjjhsjsslfjfjjjshljsh #### # #### #### ##### zzzzzzzz #",
"#sajjjzazjjzSshsajsssh######## ### ###### # # # # # zaaaaaaz #",
"#hzzsjsjzsjSjsjhjzjjjjshshhhslshhsh #a# # #### ### ##### zSSSSSSz #",
"#sjzsSzSzsSjjhsahhhhSh######## ### ####a# # # # # # zzzzzzzz #",
"#sjjsssSzajjjsSjjjsshj#sszhzjahhsms #a# # #### #### ##### #",
"#hjhzjassssssjssssshjj###########################################################################m##",
"#jjhsjssjjhsssssjjsssajjjljjjjjjjjj @ #",
"####################################################################################################",
},
{
"####################################################################################################",
"# # #",
"##@g g g g ggggggggggg #",
"#gg##g#g#g#g#g#######g##########################g###############g################################ #",
"# g g g g g #",
"#gg##g#g#g#g#g#########g######################g#################g################################ #",
"# g g g g g #",
"#gg##g#g#g#g#g###########g##################g###################g################################ #",
"# g g g g g #",
"#gg##g#g#g#g#g#############g##############g#####################g################################ #",
"# g g g g g #",
"#gg##g#g#g#g#g###############g##########g#######################g################################ #",
"# g g g g g #",
"#gg##g#g#g#g#g#################g######g#########################g##########gggggggggg############ #",
"# g g g g g #",
"#gg##g#g#g#g#g###################g##g###########################g################################ #",
"# g g gg g #",
"#gg##g#g#g#g#g####################gg############################g##########gggggggggg############ #",
"# g g g g g #",
"#gg##g#g#g#g#g##################g####g##########################g################################ #",
"# g g g g g #",
"#gg##g#g#g#g#g################g########g########################g################################ #",
"# g g g g g #",
"#jj##g#g#g#g#g##############g############g######################g################################ #",
"# g g g g g #",
"#jj##g#g#g#g#g############g################g####################g################################ #",
"# g g g g g #",
"#jj##g#g#g#g#g##########g####################g##################g################################ #",
"# g g g g g #",
"#gg##g#g#g#g#g########g########################g################g################################ #",
"# g g g g g #",
"#gg##g#g#g#g#g######g############################g##############g################################ #",
"# g # z aaaaaa s a @#",
"## # # zzzzzzz a a a sa zzz#",
"# # # z z z a aa a zs zzz#",
"## ##z zzz z aaaa z s #z#",
"# # # z aaaaa #z#",
"# # ###########################################################################################f#",
"# # @mlfff #",
"####################################################################################################",
},
{
"####################################################################################################",
"# j a # # # # #",
"#j@ a a # bggg # zzz # mmmm # #",
"# a a # g g # z z # l m # jjjjjj #",
"# aaaaaaa g gggg g z # l m # j #",
"# a a # g g # z z l l d m l jjjjj #",
"# a a # g g # zzzz # l m # j #",
"# # ggggg # # l m # j #",
"# # # # mmmmm # jjjjjjj #",
"# # # # # #",
"##########################################################################################l#########",
"# # # # # #",
"# # # # # #",
"# # # jjjjjj # # # # # ######## #",
"# # # j # # # # gggggg # # #",
"# # # j # # # # g g # # #",
"# # # # j # ###### # # g # # #",
"# # # j # # # # j g gggggg g ###### #",
"# ### # j j # # # # # g g # # #",
"# # # # jj # # # # # g g # # #",
"# # # # # # # # # # ggggggg # # #",
"# # # # # # # #",
"# # # # # #",
"###### #############################################################################################",
"# # # # # #",
"# l # # # # # jj # ##### #",
"# l # # ## # # j j # # # #",
"# l # # # # # # j j # ##### #",
"# l # # # # # j j # #",
"# l # # # # # # j j # # #",
"# l l # # # ## # jjj # # #",
"# llllllll # # # # # # #",
"# # # # # #",
"######## ################# ##################### ##################### ################### #########",
"# # # #m## # zzzz # lll #",
"# g g # ##### # # # z z # l l #",
"# g g # # # # zzz # l ll #",
"# g g # # # #### # z z # llll #",
"# ggg g # # # # # # # l #",
"####################################################################################################",
},
{
"####################################################################################################",
"# @@ m # ##",
"### mmm # # #",
"# # # # # # # #",
"# # # # # # #",
"# # # # # # # #",
"# # # # # # #",
"# # # # # # # #",
"# # #a a# # # #",
"# # # aa aa # # # # #",
"# # # aaa aaaa aaa # # # #",
"# # # aaaa # # # # #",
"# # # aaaa # # # #",
"# # #z aaaa z# # # # #",
"# # # z z # # # #",
"# # # z z # # # # #",
"# # # z ###@### z # # # #",
"# # # zzzz # # zzzzz # # # # #",
"# m m zzzz # fff # z zzzz mm # #",
"# mmm zzzzz @ ftf @ z zzzz mm mm #",
"# mmm zzzz z# fff #z zzzz mm mm #",
"# m m a # # a mm # #",
"# # # a ###@### a # # # # #",
"# # # a a # # # #",
"# # # a a # # # # #",
"# # # a zzzz a # # # #",
"# # # aSSS zzzz SSSa # # # # #",
"# # # SS zzzz SS # # # #",
"# # #S zzzz S# # # # #",
"# # # # # # #",
"# # # # # # # #",
"# # # # # # #",
"# # # # # # # #",
"# # # # # # #",
"# # # # # # # #",
"# # # # # # #",
"# # # # # # # #",
"# # mmm # # #",
"## m # ##",
"####################################################################################################",
},
};
int tower=0;
void addlevels();
int AttAck(int attack);
void AttackMonster();
void color(int x);
void cls();
void coutwhat(int a,int b,int c,int d,string n);
void Die();
void game();
char getin(char x,char y);
void gotoxy(int y,int x);
void gs();
void hidden();
void init();
void monsterbook();
void PrintfMap(int x);
int random(int n,int m);
void rf();
void Sout(string n);
void wf();
void shop();
void bnm();
void monsterbook()
{
cls();
int i,j,k;
for(i=0;i<BNUM;i++)
if (monster[i])
if (monster_[i])
printf("%c\\n%s\\nattack:%d\\nhp:%d\\ndefence:%d\\n-------------------------------\\n",sympol[i],Name[i].c_str(),Attack[i],Hp[i],Defence[i]);
else
printf("???\\n-------------------------------\\n");
gs();
PrintfMap(player.tower);
}
int AttAck(int attack)
{
int i=0,j=1;
gotoxy(10,0);
cout<<"按空格攻击\\n";
cout<<"Low High Low\\n";
cout<<"------------------------------------------------------------\\n\\n";
cout<<"------------------------------------------------------------";
float shang[60]=
{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};
while(1)
{
gotoxy(13,i-j);
cout<<" ";
gotoxy(13,i);
cout<<"|#|";
char m;
if (kbhit())
{
m=getch();
if (m==' ')
return attack*(shang[i])+attack*0.3;
}
i+=j;
if (i>=60)
j=-j;
if (i<=0)
j=-j;
Sleep(1);
}
}
void init()
{
int i,j,k,I;
Time=time_t();
printf("初始化请稍等...");
for(I=0;I<TOWER;I++)
for(i=0;i<40;i++)
{
for(j=0;j<100;j++)
{
k=sympol.find(MAP[I][i][j]);
map[I][i][j].name=Name[k];
map[I][i][j].attack=Attack[k];
map[I][i][j].hp=Hp[k];
map[I][i][j].defence=Defence[k];
map[I][i][j].go=Go[k];
map[I][i][j].monster=monster[k];
map[I][i][j].number=k;
map[I][i][j].xp=Xp[k];
}
}
player.tower=0;
player.hp=150;
player.attack=35;
player.defence=15;
player.xp=1;
player.level=1;
player.x=1;
player.y=1;
system("cls");
}
void coutwhat(int a,int b,int c,int d,string n)//输出一些东西,从坐标(a,b)到(c,d)输出n
{
int i,j;
for(i=a;i<=c;i++)
{
gotoxy(i,b);
for(j=b;j<=d;j++)
{
cout<<n;
}
}
}
void gotoxy(int y,int x) //移动光标
{
COORD coord;
coord.X=x;
coord.Y=y;
HANDLE a=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(a,coord);
}
void color(int x)//调颜色
{
switch(x)
{
case 0:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);break;
case 1:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_GREEN);break;
case 2:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE |FOREGROUND_GREEN);break;
case 3:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE |FOREGROUND_GREEN);break;
case 4:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE);break;
case 5:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE |FOREGROUND_RED);break;
case 7:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);break;
case 8:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED|FOREGROUND_GREEN);break;
case 9:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED|FOREGROUND_BLUE);break;
case 10:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED);break;
default:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_BLUE);break;
}
}
char getin(char x,char y)
{
char l;
do
l=_getch();
while(l<x||l>y);
return l;
}
int random(int n,int m)
{
int s;
s=rand()%(m-n+1);
s+=n;
return s;
}
void cls()
{
system("cls");
}
void shop()
{
cls();
int much[10]={30,50,120,30,50,150,30,50,120};
while(1)
{printf("欢迎,你想买些什么?");
printf("1.锈迹斑斑的铁剑 (attack+3) $30\\n");
printf("2.崭新的铁剑 (attack+5) $50\\n");
printf("3.银光闪闪的宝剑 (attack+12) $120\\n");
printf("4.发霉的药水 (hp+20) $30\\n");
printf("5.普通的药水 (hp+40) $50\\n");
printf("6.高级药水 (hp+500 attack+10) $150\\n");
printf("7.破烂盾牌 (defence+1) $30\\n");
printf("8.木头盾牌 (defence+2) $50\\n");
printf("9.坚固的铁盾(defence+4) $120\\n");
printf("0.离开 $0\\n");
char n=_getch();
if (n=='0')
break;
printf("确定买%c吗?Y/N",n);
char m=_getch();
if (m=='N'||m=='n')
continue;
if (player.money<much[n-'0'])
printf("钱不够!");
else
{
printf("购买成功!");
player.money-=much[n-'0'];
switch(n)
{
case '1':player.attack+=3;break;
case '2':player.attack+=5;break;
case '3':player.attack+=12;break;
case '4':player.hp+=20;break;
case '5':player.hp+=40;break;
case '6':player.hp+=500,player.attack+=10;break;
case '7':player.defence++;break;
case '8':player.defence+=2;break;
case '9':player.defence+=4;break;
}
}
system("cls");
}
PrintfMap(player.tower);
}
void Sout(string n)
{
for(int i=0;i<n.size();i++)
{
cout<<n[i];
Sleep(sudu);
if (kbhit())
if (getch()==' ')
{
cout<<n.substr(i+1,n.size()-i);
return;
}
}
}
void hidden()
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;GetConsoleCursorInfo(handle, &CursorInfo);
CursorInfo.bVisible = false;
SetConsoleCursorInfo(handle, &CursorInfo);
}
void gs()
{
hidden();
gotoxy(45,80);
cout<<"按下任意键继续_";
_getch();
system("cls");
}
void PrintfMap(int x)
{
cls();
gotoxy(0,0);
int i,j;
for(i=0;i<40;i++)
{
for(j=0;j<100;j++)
{
printf("%c",MAP[x][i][j]);
}
printf("\\n");
}
for(i=0;i<BNUM;i++)
if (monster[i]==false)
{
gotoxy(i+10,105);
printf("%c %s\\n",sympol[i],Name[i].c_str());
}
}
void Die()
{
cls();
sudu=150;
Sout("你\\t死\\t了");
sudu=10;
exit(0);
gs();
rf();
}
void AttackMonster(int x,int y)
{
cls();
BLOCKS j;
char l;
int n,m;
j=map[player.tower][player.x][player.y];
n=player.attack;
player.attack*=0.9;//考虑玩家不一定全部能正中
if (j.attack-player.defence>0)
{
m=player.hp/(j.attack-player.defence);
if (player.attack-j.defence<=0)
{
printf("你现在可能还打不过他呢,是否继续挑战?Y.yes N.no");
l=_getch();
player.attack=n;
if (l=='n'||l=='N')
{
PrintfMap(player.tower);
player.x=x,player.y=y;
return;
}
}
m*=(player.attack-j.defence);
if (m<=j.hp)
{
printf("你现在可能还打不过他呢,是否继续挑战?Y.yes N.no");
l=_getch();
player.attack=n;
if (l=='n'||l=='N')
{
PrintfMap(player.tower);
player.x=x,player.y=y;
return;
}
}
}
player.attack=n;
while(j.hp>0&&player.hp>0)
{
cls();
printf("敌人:%s\\n",j.name.c_str());
printf("敌人的血量:%d\\n",j.hp);
printf("敌人的攻击:%d\\n",j.attack);
printf("敌人的防御:%d\\n",j.defence);
printf("你的血量:%d\\n",player.hp);
printf("你的攻击:%d\\n",player.attack);
printf("你的防御:%d\\n",player.defence);
printf("1.attack 2.run away\\n");
l=_getch();
if (l=='2')
if (rand()%4==1&&j.name!="魔术师"&&j.name!="魔王_真")
{
map[player.tower][player.x][player.y].hp=j.hp;
return;
}
else
printf("逃跑失败!");
n=AttAck(player.attack);
n-=j.defence;
j.hp-=n;
if (n<=0)
n=1;
printf("你发起了攻击,%s受到了%d点伤害!\\n",j.name.c_str(),n);
n=j.attack*random(9,12)/10.0;
n-=player.defence;
if (n<=0)
n=1;
player.hp-=n;
printf("%s发起了攻击,你受到了%d点伤害!\\n",j.name.c_str(),n);
gs();
}
if (player.hp<=0)
Die();
if (map[player.tower][player.x][player.y].name=="魔王_真")
{
system("cls");
Sout("你成功打败了魔王,游戏结束,你赢了!");
exit(0);
}
if (map[player.tower][player.x][player.y].name=="流浪商人_魔化")
map[player.tower][player.x][player.y].name="流浪商人";
map[player.tower][player.x][player.y].hp=0;
map[player.tower][player.x][player.y].attack=0;
map[player.tower][player.x][player.y].defence=0;
map[player.tower][player.x][player.y].go=1;
map[player.tower][player.x][player.y].monster=0;
monster_[map[player.tower][player.x][player.y].number]=1;
player.money+=Xp[map[player.tower][player.x][player.y].number];
MAP[player.tower][player.x][player.y]=' ';
PrintfMap(player.tower);
return;
}
void addlevels()
{
while(player.xp>uplevel[player.level])
player.level++,player.hp+=80,player.attack+=6,player.defence+=3;
}
void game()
{
char l;
int i,j,k,n,m;
while(player.tower<TOWER)
{
PrintfMap(player.tower);
Time=clock();
do
{
l=',';
hidden();
int sx,sy;
sx=player.x,sy=player.y;
gotoxy(42,0);
printf("LEVEL:%d XP:%d/%lld\\n",player.level,player.xp,uplevel[player.level]);
gotoxy(43,0);
printf("HP:%d ATTACK:%d DEFENCE:%d\\n",player.hp,player.attack,player.defence);
gotoxy(44,0);
printf("MONEY:%d\\n",player.money);
gotoxy(player.x,player.y);
cout<<"O";
if (kbhit())
l=getch();
now=clock();
gotoxy(0,105);
k=now-Time;
printf("%d:%d:%d.%d",k/3600000,k%3600000/60000,k%60000/1000,k%1000);
switch(l)
{
case 'w':if (player.x>0&&map[player.tower][player.x-1][player.y].go) player.x--;break;
case 's':if (player.x<COLS&&map[player.tower][player.x+1][player.y].go) player.x++;break;
case 'a':if (player.y>0&&map[player.tower][player.x][player.y-1].go) player.y--;break;
case 'd':if (player.y<LINES&&map[player.tower][player.x][player.y+1].go) player.y++;break;
case 'm':monsterbook();break;
case '/':cin>>n;if (n<5)player.tower=n;else player.hp+=n,player.attack+=n,player.defence+=n,player.money+=n*100;
}
if (sx!=player.x||sy!=player.y)
{
gotoxy(sx,sy);
cout<<" ";
gotoxy(player.x,player.y);
cout<<"O";
}
if (map[player.tower][player.x][player.y].monster)
if (MessageBox(NULL,TEXT("是否挑战此怪物?"),TEXT("?"),MB_YESNO)==IDYES)
AttackMonster(sx,sy);
else
{
gotoxy(player.x,player.y);
printf("%c",MAP[player.tower][player.x][player.y]);
player.x=sx,player.y=sy;
}
gotoxy(45,0);
printf("位置:%d,%d,%d",player.x,player.tower+1,player.y);
if (map[player.tower][player.x][player.y].hp<=0)
player.xp+=map[player.tower][player.x][player.y].xp;
addlevels();
map[player.tower][player.x][player.y].xp=0;
if (map[player.tower][player.x][player.y].number==9)
player.hp+=50,MAP[player.tower][player.x][player.y]=' ',map[player.tower][player.x][player.y].number=0;
if (map[player.tower][player.x][player.y].number==10)
player.attack+=10,MAP[player.tower][player.x][player.y]=' ',map[player.tower][player.x][player.y].number=0;
if (MAP[player.tower][player.x][player.y]=='S')
player.defence+=4,MAP[player.tower][player.x][player.y]=' ',map[player.tower][player.x][player.y].number=0;
if (MAP[player.tower][player.x][player.y]=='d'||map[player.tower][player.x][player.y].name=="流浪商人")
{
shop();
gotoxy(player.x,player.y);
printf("%c",MAP[player.tower][player.x][player.y]);
player.x=sx,player.y=sy;
}
if (MAP[player.tower][player.x][player.y]=='@')
{
gotoxy(46,0);
for(i=0;i<RUNE;i++)
if (player.tower==rtower[i]&&player.x==rposx[i]&&player.y==rposy[i])
break;
printf("石碑内容:%s",runec[i].c_str());
}
else
{
gotoxy(46,0);
printf(" ");
}
}
while(!((player.x==COLS-2&&player.y==LINES-2)||(player.x==0&&player.y==1&&player.tower>0)));
if (player.x==COLS-2&&player.y==LINES-2)
player.tower++,player.x=1,player.y=1;
else if (player.tower>0)
player.tower--,player.x=38,player.y=98;
//wf();
}
}
int main()
{
char l;
int i,j,k;
hidden();
init();
game();
return 0;
}
以上是关于勇闯迷塔小游戏(c++)的主要内容,如果未能解决你的问题,请参考以下文章