//main.cpp
using namespace std;
#include<iostream>
#include<iomanip>
#include"player.h"
#include"swordsman.h"
#include"archer.h"
#include"mage.h"
int main()
{
int instemp;
char temp[10];
bool success=0;//操作是否成功
cout<<"请输入玩家名字(最多4个汉字):";
cin>>temp;
player *human=NULL;//方便实现多态
player *enemy=NULL;
do{
int instemp;
cout<<"请输入玩家职业:1.战士【血量高】 2.弓箭手【速度快】 3.法师【魔法足】";
cin>>instemp;
switch(instemp)//选择职业
{
case 1://选择了骑士
human = new Swordsman(1,temp,1);
success=1;//操作成功
break;
case 2:
human = new Archer(1,temp,1);
success=1;
break;
case 3:
human = new Mage(1,temp,1);
success=1;
break;
default:
break;
}
}while(success!=1);//循环选择直到操作成功
int j=0;//第几局
for(int i=1;j<10;i=i+1)
{
j++;
system("cls");
cout<<"STAGE"<<j<<endl;
srand(time(NULL));
switch (rand()%3)
{
case 0:
cout<<"敌方介绍:一个"<<i<<"级的剑士。"<<endl;
system("pause");
enemy = new Swordsman(i,"剑士",0);//创建一个i级的剑士作为敌人
break;
case 1:
cout<<"敌方介绍:一个"<<i<<"级的弓手。"<<endl;
system("pause");
enemy = new Archer(i,"弓手",0);//创建一个i级的剑士作为敌人
break;
case 2:
cout<<"敌方介绍:一个"<<i<<"级的法师。"<<endl;
system("pause");
enemy = new Mage(i,"法师",0);//创建一个i级的剑士作为敌人
break;
default:
break;
}
human->ReFill();//人类玩家没过一版声明魔法值恢复
while(!human->Death() && !enemy->Death())//两个人都没死则继续战斗
{
success=0;
while(success!=1)//直到操作成功
{
system("cls");
showinfo(*human,*enemy);//显示两个玩家信息
cout<<endl;
if(human->stunstatus!=-1)
{
cout<<"你处于晕眩状态"<<endl;
break;
}
cout<<"请下达指令:"<<endl;
cout<<"1 攻击 2 特殊攻击 3 使用回复剂 4 使用魔法(解毒)水 5 分配点数 6 防御 7 蓄力 0 退出"<<endl;
cin>>instemp;
system("pause");
switch(instemp)
{
case 0:
cout<<"是否要退出游戏?Y/N"<<endl;
char temp;
cin>>temp;
if(temp=='Y' || temp=='y')
{
exit(0);
}
else
break;
case 1:
success=human->attack(*enemy);
human->isLevelUp();
enemy->isDead();
break;
case 2:
success=human->specialatt(*enemy);
human->isLevelUp();
enemy->isDead();
break;
case 3:
success=human->useHeal();
break;
case 4:
success=human->useMW();
break;
case 5:
success=human->dPoints();
break;
case 6:
system("cls");
success=human->defendbuf();
showinfo(*human,*enemy);
break;
case 7:
system("cls");
success=human->attackbuf();
showinfo(*human,*enemy);
break;
default:
break;
}
}
enemy->recover();
if(!enemy->Death())//如果电脑玩家没有死亡
{
if(enemy->stunstatus!=-1)
{
cout<<"ai被晕眩"<<endl;
system("pause");
}
else
{
enemy->AI(*human);//与人类对战
}
human->recover();
}
else
{
human->transfer(*enemy);//把物品给人类玩家
delete enemy;
}
if(human->Death())//如果人类玩家死亡
{
system("cls");
cout<<endl<<endl<<endl<<endl<<setw(50)<<"胜败乃兵家常事,好男儿请重新再来。"<<endl;
//
system("pause");
exit(0);
}
}
}
system("cls");
cout<<endl<<endl<<endl<<endl<<setw(60)<<"所有的敌人都已经被您消灭了!\n\
世界又恢复了往日的和平。"<<endl<<endl<<endl<<setw(35)<<"终"<<endl<<endl<<endl<<endl<<endl;
//
system("pause");
}
没有合适的资源?快使用搜索试试~ 我知道了~
易学c++最后的rpg程序

共7个文件
h:5个
exe:1个
cpp:1个


温馨提示
就是书上最后的完善程序了,自己又添加修改了一些功能,当然bug很多,因为是新手见谅见谅!
资源推荐
资源详情
资源评论





















收起资源包目录








共 7 条
- 1
资源评论

- chuai16092012-04-05还行,这个还不错,注意,如果想给别人编译好的exe程序,一定要release,要不然别人没装你VC的版本用不了

zyz19890131
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
