#include"Hero.h"
#include"Game.h"
void Hero::UpPoint(GameMap * map)
{
// 遍历查找玩家位置
for (int i = 0; i < 13; i++)
{
bool b = false;
for (int j = 0; j < 13; j++)
{
if (2 == map->m_map[m_iCurIndex][i][j])
{
m_i = i;
m_j = j;
b = true;
break;
//return;
}
}
if (b)
break;
}
}
//初始化英雄数据
void Hero::initPlayer(int index)
{
m_atk = 500;
m_def = 100;
m_exp = 0;
m_gold = 0;
m_hp = 1000;
m_lv = 1;
m_tj = 1;
m_fx = 1;
m_gz = 1;
m_key.blueKey = 0;
m_key.redKey = 0;
m_key.yellowKey = 0;
m_iCurIndex=index;
strcpy(m_name, "勇士");
}
// 获取对应下标元素
int Hero::getObjectOfIndex(GameMap * map, int i, int j)
{
return map->m_map[m_iCurIndex][i][j];
}
// 修改地图信息
void Hero::updateMap(GameMap* map,int offsetX, int offsetY)
{
map->m_map[m_iCurIndex][m_i][m_j] = 0;
map->m_map[m_iCurIndex][m_i + offsetX][m_j + offsetY] = 2;
// 玩家位置更新
m_i += offsetX;
m_j += offsetY;
}
//拾取道具
void Hero::Pikprops(Props *m,int type)
{
m_hp += m->hp;
m_atk += m->atk;
m_def += m->def;
m_key.blueKey += m->key.blueKey;
m_key.redKey += m->key.redKey;
m_key.yellowKey += m->key.yellowKey;
m_fx += m->fx;
m_gz += m->gz;
m_tj += m->tj;
if (type < 55)
m->Showprops(m);
}
//打开门
bool Hero::Opendrop(int type)
{
switch (type)
{
case 40:
if (m_key.redKey > 0)
{
--m_key.redKey;
return true;
}
else return false;
break;
case 42:
if (m_key.yellowKey > 0)
{
--m_key.yellowKey;
return true;
}
else return false;
break;
case 41:
if (m_key.blueKey > 0)
{
--m_key.blueKey;
return true;
}
else return false;
break;
}
return false;
}
//钥匙商店
void Hero::ysshop()
{
system("CLS");
color.setColor(4);
cout << "小伙子要点啥!:" << endl;
cout << "■■■■■■■■■■■■■■■■" << endl;
cout << "1.消耗十金币购买一把黄色钥匙 " << endl;
cout << "2.消耗二十金币购买一把蓝色钥匙" << endl;
cout << "3.消耗五十金币购买一把红色钥匙" << endl;
cout << "6.输入6退出商店 " << endl;
cout << "■■■■■■■■■■■■■■■■" << endl;
cout << "请输入你序号购买你想要的道具:" << endl;
bool ok = true;
while (ok)
{
int iput = getch();
switch (iput)
{
case '1':
if (m_gold >= 10)
{
cout << "购买成功" << endl;
m_key.yellowKey += 1;
m_gold -= 10;
}
else cout << "穷鬼,加油挣钱吧!" << endl;
break;
case '2':
if (m_gold >= 20)
{
cout << "购买成功" << endl;
m_key.blueKey += 1;
//hero.fy += 7;
//hero.hp += 800;
m_gold -= 20;
}
else cout << "穷鬼,加油挣钱吧!" << endl;
break;
case '3':
if (m_gold >= 50)
{
cout << "购买成功" << endl;
m_key.redKey += 1;
//hero.fy += 7;
//hero.hp += 800;
m_gold -= 50;
}
else cout << "穷鬼,加油挣钱吧!" << endl;
break;
case '6':
ok = false;
break;
}
}
}
//勇士升级商店
void Hero::expshop()
{
system("CLS");
color.setColor(4);
cout << "■■■■■■■■■■■■■■■■" << endl;
cout << "1.消耗五十点经验升一级" << endl;
cout << "2.消耗十金币获得3点攻击" << endl;
cout << "3.消耗十金币获得3点防御" << endl;
cout << "4.消耗十经验获得3点攻击" << endl;
cout << "5.消耗十经验获得3点防御" << endl;
cout << "6.输入6退出商店 " << endl;
cout << "■■■■■■■■■■■■■■■■" << endl;
cout << "请输入你序号购买你想要的道具:" << endl;
bool ok = true;
while (ok)
{
int iput = getch();
switch (iput)
{
case '1':
if (m_exp >= 50)
{
cout << "升级成功等级+1攻击+7,防御+7,血量+800:" << endl;
m_lv += 1;
m_atk += 7;
m_def += 7;
m_hp += 800;
m_exp -= 50;
}
else cout << "升级失败,经验不够!" << endl;
break;
case '2':
if (m_gold >= 10)
{
cout << "购买成功攻击+3" << endl;
m_atk += 4;
//hero.fy += 7;
//hero.hp += 800;
m_gold -= 10;
}
else cout << "穷鬼,加油挣钱吧!" << endl;
break;
case '3':
if (m_gold >= 10)
{
cout << "购买成功防御+3" << endl;
m_def += 3;
//hero.fy += 7;
//hero.hp += 800;
m_gold -= 10;
}
else cout << "穷鬼,加油挣钱吧!" << endl;
break;
case '4':
if (m_exp >= 10)
{
cout << "购买成功攻击+3" << endl;
m_atk += 3;
//hero.fy += 7;
//hero.hp += 800;
m_exp -= 10;
}
else cout << "经验不够,抓紧时间打怪吧!" << endl;
break;
case '5':
if (m_exp >= 10)
{
cout << "购买成功防御+3" << endl;
m_def += 3;
//hero.fy += 7;
//hero.hp += 800;
m_exp -= 10;
}
else cout << "经验不够,抓紧时间打怪吧!" << endl;
break;
case '6':
ok = false;
break;
}
}
}
//NPC处理
void Hero::Npc(int type)
{
switch(type)
{
case 43:
system("CLS");
cout << "勇士,欢迎来到魔塔世界!" << endl;
Sleep(1000);
cout << "你的任务是:解救公主,击败邪恶的泰斯尔领主!" << endl;
Sleep(2000);
m_key.blueKey += 1;
m_key.redKey += 1;
m_key.yellowKey += 1;
break;
case 44:
expshop();
break;
case 45:
ysshop();
break;
}
}
//怪物攻击
void Hero::monsterakt(Monster *m)
{
if (m->m_atk <= m_def)
m_hp -= 0;
else
m_hp -= (m->m_atk - m_def);
}
//英雄攻击
void Hero::heroakt(Monster *m)
{
if (m_atk <= m->m_def)
m->m_hp -= 0;
else
m->m_hp -= (m_atk - m->m_def);
}
//显示攻击页面
void Hero::showakt(Monster *m)
{
system("CLS");
color.setColor(1);
cout << "■■■■■■■■■■■■■■■■" << endl;
cout << "♂" << "生命值:" << left << setw(4) << m->m_hp << " ■" << " " << "■" <<m_hp << " :生命值" << " ♀" << endl;
cout << " " << "攻击力:" << left << setw(4) << m->m_atk << " ■" << " " << "■" << m_atk << " :攻击力" << " " << endl;
cout << " " << "防御力:" << left << setw(4) << m->m_def << " ■" << " " << "■" << m_def << " :防御力" << " " << endl;
cout << "怪物" << " " << left << setw(4) << " ■" << " " << "■" << " " << "勇士" << endl;
cout << "■■■■■■■■■■■■■■■■" << endl;
Sleep(500);
}
//判断能否杀死怪物
bool Hero::cankill(Monster *m)
{
if ((m_atk>m->m_def &&m->m_atk <m_def) || (m_atk>m->m_def &&m_hp / (m->m_atk - m_def) > m->m_hp / (m_atk - m->m_def)))//能打死
{
while (m->m_hp > 0)
{
showakt(m);
heroakt(m);
if (m->m_hp <= 0)
{
m->m_hp = 0;
}
showakt(m);
monsterakt(m);
}
m_gold += m->m_gold;
m_exp += m->m_exp;
return true;
}
else
{
return false;
}
}
//跳跃关卡
void Hero::Jumpbar(GameMap *map)
{
system("CLS");
int bar = 0;
cout << "请输入你想要到达的层数:" << endl;
cin >> bar;
if (bar > 5)
{
system("CLS");
color.setColor(1);
cout << "后面的层数,作者弟弟正在努力更新中,敬请期待!" << endl;
Sleep(2000);
}
else
{
m_iCurIndex = bar;
map->m_iCurIndex = bar;
UpPoint(map);
}
}
//怪物图鉴
void Hero::ShowMonsterinfo(GameMap *map)
{
int ok = true;
while (ok)
{
system("CLS");
cout << "■■■■■■■■■■■■■■■■■■■■■■■■■■" << endl;
// 遍历查找当前层怪物
Monster m;
for (int i = 0; i < 13; i++)
{
//bool b = false;
for (int j = 0; j < 13; j++)
{
if (11 <= map->m_map[m_iCurIndex][i][j] && map->m_map[m_iCurIndex][i][j] <= 21)
{
Monster* pMonsret;
pMonsret=m.createMonster(map->m_map[m_iCurIndex][i][j]);
cout << pMonsret->m_name << "■" << "生命值:" << left << setw(4) << pMonsret->m_hp << " ■";
cout << " " << "攻击力:" << left << setw(4) << pMonsret->m_atk << " ■";
cout << " " << "防御力:" << left << setw(4) << pMonsret->m_def << " ■" << endl;
delete pMonsret;
pMonsret = nullptr;
}
}
}
cout << "■■■■■■■■■■■■■■■■■■■■■■■■■■" << endl;
cout << "温馨提示再按L/l可关闭图鉴!!" << endl;
int iput = getch();
switch (iput)
{
case 'l
没有合适的资源?快使用搜索试试~ 我知道了~
重新用类写了下魔塔,内含源代码和可执行文件,以及丰富的注释
共39个文件
h:7个
obj:7个
cpp:7个
需积分: 15 16 下载量 67 浏览量
2019-08-20
19:17:10
上传
评论 2
收藏 11.64MB ZIP 举报
温馨提示
重新用类写了下魔塔,内含源代码和可执行文件,以及丰富的注释,关卡稍微有点少,可以自行增加,可扩展性好
资源推荐
资源详情
资源评论
收起资源包目录
MTGJ.zip (39个子文件)
MTGJ
Debug
MTGJ.pdb 1.26MB
MTGJ.exe 116KB
MTGJ.ilk 1.5MB
MTGJ.sdf 32MB
MTGJ.sln 958B
MTGJ
Color.cpp 708B
Hero.cpp 11KB
GameMap.cpp 8KB
Debug
MTGJ.tlog
cl.command.1.tlog 4KB
CL.read.1.tlog 150KB
link.read.1.tlog 3KB
link.write.1.tlog 878B
CL.write.1.tlog 7KB
link.command.1.tlog 2KB
MTGJ.lastbuildstate 157B
vc120.pdb 484KB
Color.obj 28KB
MTGJ.log 2KB
main.obj 154KB
Props.obj 185KB
vc120.idb 1011KB
GameMap.obj 191KB
Monster.obj 132KB
Hero.obj 218KB
Game.obj 188KB
Hero.h 2KB
Props.h 554B
Props.cpp 4KB
main.cpp 141B
Game.cpp 5KB
Game.h 541B
Monster.cpp 2KB
MTGJ.vcxproj 4KB
MTGJ.vcxproj.filters 2KB
Color.h 198B
GameMap.h 399B
StartUi.h 2KB
Monster.h 350B
MTGJ.v12.suo 37KB
共 39 条
- 1
资源评论
caryone
- 粉丝: 2
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功