| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1554 人关注过本帖
标题:[原创]一个经典RPG游戏
只看楼主 加入收藏
xiangjiantui
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2005-11-13
收藏
 问题点数:0 回复次数:8 
[原创]一个经典RPG游戏

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
int str[4],def[4],hp[8];
int boss=1,l=1,mj=0,ycboss=0;
int money=0;
int yaopin[4];
int yaopinqian[4];
int wuqi[4],wuqiqian[4],wuqiz[4];
int fangju[4],fangjuqian[4],fangjuz[4];
int temp[3];
int main(int argc, char *argv[])
{
wuqiz[1]=wuqiz[2]=wuqiz[3]=wuqiz[4]=0;
fangjuz[1]=fangjuz[2]=fangjuz[3]=fangjuz[4]=0;
str[1]=def[1]=10;
hp[1]=hp[2]=40;
str[2]=def[2]=8;
hp[3]=hp[4]=30;
str[3]=def[3]=40;
hp[5]=hp[6]=200;
str[4]=def[4]=10000;
hp[7]=hp[8]=1000000;
temp[2]=temp[3]=0;
string d;
void prt(),prt2(),yudi(),boss2(),boss3();
void miji(),shiyong(),daoju(),zhuangtai();
yaopinqian[1]=40;
yaopinqian[2]=200;
yaopinqian[3]=500;
yaopinqian[4]=2000;
wuqiqian[1]=30;
wuqiqian[2]=200;
wuqiqian[3]=500;
wuqiqian[4]=1000;
fangjuqian[1]=20;
fangjuqian[2]=100;
fangjuqian[3]=500;
fangjuqian[4]=1000;
mj=0;
for (;boss!=0 || mj==1;)
{
if (mj==0) cout<<"打小怪=1 打boss=2 道具店=3 状态=c 退出=q"<<'\n';
if (mj==1) cout<<"打小怪=1 打boss=2 道具店=3 隐藏boss=4 状态=c 退出=q"<<'\n';
cin>>d;
if (d=="c") zhuangtai();
if (d=="m") miji();
if (d=="q") break;
if (d=="1") yudi();
if (d=="2") boss2();
if (d=="3") daoju();
if (d=="4" && mj==1) boss3();
if (hp[1]<=0) { cout<<"你死啦!";break;}
}
system("PAUSE");
return EXIT_SUCCESS;
}
void zhuangtai()
{
cout<<"你的状态为:"<<'\n';
cout<<"hp="<<hp[1]<<"/"<<hp[2]<<'\n';
cout<<"str="<<str[1]<<" "<<"def="<<def[1]<<'\n';
cout<<"武器:";
if (wuqiz[1]==1) cout<<"小刀";
if (wuqiz[2]==1) cout<<"阔刀";
if (wuqiz[3]==1) cout<<"血饮";
if (wuqiz[4]==1) cout<<"机关炮";
if (wuqiz[1]==0 && wuqiz[2]==0 && wuqiz[3]==0 && wuqiz[4]==0) cout<<"无";
cout<<" "<<"防具:";
if (fangjuz[1]==1) cout<<"布衣";
if (fangjuz[2]==1) cout<<"皮衣";
if (fangjuz[3]==1) cout<<"锁甲";
if (fangjuz[4]==1) cout<<"板甲";
if (fangjuz[1]==0 && fangjuz[2]==0 && fangjuz[3]==0 && fangjuz[4]==0) cout<<"无";
cout<<'\n';
cout<<"你有"<<money<<"金"<<'\n'<<'\n';
}
void prt()
{
int tempmoney;
tempmoney=hp[4];
str[1]=str[1]+3;
def[1]=def[1]+3;
hp[1]=hp[2]=hp[2]+10;
cout<<"胜利!升级 str="<<str[1]<<" def="<<def[1]<<" hp="<<hp[2]<<'\n';
cout<<"得到"<<tempmoney<<"金"<<'\n'<<'\n';
money=money+tempmoney;
str[2]=str[2]+3;
def[2]=def[2]+4;
hp[3]=hp[4]=hp[2]*4/5;
}
void yudi()
{
void shiyong();
string c;
int b;
hp[3]=hp[4];
cout<<"小怪出现 hp="<<hp[3]<<'\n';
do
{
cout<<"攻击=a 逃跑=b 使用道具=c"<<'\n';
cin>>c;
if (c=="a")
{
b=str[1]*2-def[2]*3/2+str[1]*4/def[2];
if (b<=0) b=1;
cout<<"攻击! 怪物减少"<<b<<"滴血"<<'\n';
hp[3]=hp[3]-b;
if (hp[3]<=0) hp[3]=0;
cout<<"怪物还有"<<hp[3]<<"滴血"<<'\n';
if (hp[3]>0)
{
b=str[2]*2-def[1]*3/2+str[2]*4/def[1];
if (b<=0) b=1;
cout<<"怪物攻击! 减少"<<b<<"滴血"<<'\n';
hp[1]=hp[1]-b;
cout<<"人物还有"<<hp[1]<<"滴血"<<'\n'<<'\n';
}
}
if (c=="c")
{
shiyong();
b=str[2]*2-def[1]*3/2+str[2]*4/def[1];
if (b<=0) b=1;
cout<<"怪物攻击! 减少"<<b<<"滴血"<<'\n';
hp[1]=hp[1]-b;
cout<<"人物还有"<<hp[1]<<"滴血"<<'\n'<<'\n';
}
if (c=="b")
{ cout<<"逃跑成功 hp+3"<<'\n';
hp[1]=hp[1]+3;
if (hp[1]>hp[2]) hp[1]=hp[2];
break;
}
if (hp[1]<=0) break;
} while (hp[3]>0);
if (hp[3]<=0) prt();
}
void boss2()
{
void prt2();
void shiyong();
string c;
int b;
hp[5]=hp[6];
cout<<"boss出现 hp="<<hp[5]<<'\n';
do
{
cout<<"攻击=a 逃跑=b 使用道具=c"<<'\n';
cin>>c;
if (c=="a")
{
b=str[1]*2-def[3]*3/2+str[1]*4/def[3];
if (b<=0) b=1;
cout<<"攻击! boss减少"<<b<<"滴血"<<'\n';
hp[5]=hp[5]-b;
if (hp[5]<=0) hp[5]=0;
cout<<"boss还有"<<hp[5]<<"滴血"<<'\n';
if (hp[5]>0)
{
b=str[3]*2-def[1]*3/2+str[3]*4/def[1];
if (b<=0) b=1;
cout<<"boss攻击! 减少"<<b<<"滴血"<<'\n';
hp[1]=hp[1]-b;
cout<<"人物还有"<<hp[1]<<"滴血"<<'\n'<<'\n';
}
}
if (c=="c")
{
shiyong();
b=str[3]*2-def[1]*3/2+str[3]*4/def[1];
if (b<=0) b=1;
cout<<"boss攻击! 减少"<<b<<"滴血"<<'\n';
hp[1]=hp[1]-b;
cout<<"人物还有"<<hp[1]<<"滴血"<<'\n'<<'\n';
}
if (c=="b")
{ cout<<"逃跑成功 hp+3"<<'\n';
hp[1]=hp[1]+3;
if (hp[1]>hp[2]) hp[1]=hp[2];
break;
}
if (hp[1]<=0) break;
} while (hp[5]>0);
if (hp[5]<=0) prt2();
}
void prt2()
{
int tempmoney;
cout<<"太帅了!打赢总boss,游戏结束"<<'\n';
boss=0;
if (mj==1)
{ tempmoney=hp[6];
str[1]=str[1]+10;
def[1]=def[1]+10;
hp[1]=hp[1]+10;
cout<<"胜利!升级 str="<<str[1]<<" def="<<def[1]<<" hp="<<hp[2]<<'\n';
cout<<"得到"<<tempmoney<<"金"<<'\n'<<'\n';
str[3]=str[3]+10;
def[3]=def[3]+10;
hp[6]=hp[5]=hp[6]+10;
money=money+200;
}
}
void miji()
{
cout<<"秘籍模式开启!";
mj=1;
}
void boss3()
{
void prt3();
void shiyong();
string c;
int b;
hp[7]=hp[8]=1000000;
cout<<"Zn出现 hp="<<hp[7]<<'\n';
do
{
cout<<"攻击=a 逃跑=b 使用道具=c"<<'\n';
cin>>c;
if (c=="a")
{
b=str[1]*2-def[4]*3/2+str[1]*4/def[4];
if (b<=0) b=1;
cout<<"攻击! Zn减少"<<b<<"滴血"<<'\n';
hp[7]=hp[7]-b;
if (hp[7]<=0) hp[7]=0;
cout<<"Zn还有"<<hp[7]<<"滴血"<<'\n';
if (hp[7]>0)
{
b=str[4]*2-def[1]*3/2+str[4]*4/def[1];
if (b<=0) b=1;
cout<<"Zn攻击! 减少"<<b<<"滴血"<<'\n';
hp[1]=hp[1]-b;
cout<<"人物还有"<<hp[1]<<"滴血"<<'\n'<<'\n';
}
}
if (c=="c")
{
shiyong();
b=str[4]*2-def[1]*3/2+str[4]*4/def[1];
if (b<=0) b=1;
cout<<"Zn攻击! 减少"<<b<<"滴血"<<'\n';
hp[1]=hp[1]-b;
cout<<"人物还有"<<hp[1]<<"滴血"<<'\n'<<'\n';
}
if (c=="b")
{ cout<<"逃跑成功 hp+3"<<'\n';
hp[1]=hp[1]+3;
if (hp[1]>hp[2]) hp[1]=hp[2];
break;
}
if (hp[1]<=0) break;
} while (hp[7]>0);
if (hp[7]<=0) prt3();
}
void daoju()
{
void yaopind();
void wuqid();
void fangjud();
string b;
cout<<"药品=1"<<'\n'<<"武器=2"<<'\n'<<"防具=3"<<'\n';
cin>>b;
if (b=="1") yaopind();
if (b=="2") wuqid();
if (b=="3") fangjud();
if (b!="1" && b!="2" && b!="3") cout<<"错误!"<<'\n'<<'\n';
}
void yaopind()
{
string b;
int c,e=0,f;
cout<<"小补药=1 40$ hp+30"<<'\n';
cout<<"大补药=2 200$ hp+100"<<'\n';
cout<<"全恢复药=3 500$ hp+100%"<<'\n';
cout<<"神奇水=4 2000$ ???"<<'\n';
cout<<"退出=q"<<'\n';
cin>>b;
if (b=="q") e=1;
if (b!="1" && b!="2" && b!="3" && b!="4" && b!="q") e=2;
if (e==2) cout<<"输入错误!"<<'\n'<<'\n';
else {
if (e!=1)
{
cout<<"要多少个"<<'\n';
cin>>c;
if (c<=0)
{
for(;;)
{
cout<<"重新输入"<<'\n';
cin>>c;
if (c>0) break;
}
}
if (b=="1") f=1;
if (b=="2") f=2;
if (b=="3") f=3;
if (b=="4") f=4;
if (money<yaopinqian[f]*c) cout<<"失败"<<'\n'<<'\n';
else { money=money-yaopinqian[f]*c;
yaopin[f]=yaopin[f]+c;
cout<<"购买成功"<<'\n'<<'\n'; }
}
else cout<<"退出!"<<'\n'<<'\n';
}
}
void wuqid()
{
wuqi[1]=10;
wuqi[2]=20;
wuqi[3]=50;
wuqi[4]=80;
int e=0,f;
string b;
cout<<"小刀=1 30$ str+10"<<'\n';
cout<<"阔刀=2 200$ str+20"<<'\n';
cout<<"血饮=3 500$ str+50"<<'\n';
cout<<"机关炮=4 1000$ str+80"<<'\n';
cout<<"退出=q"<<'\n';
cin>>b;
if (b=="q") e=1;
if (b!="1" && b!="2" && b!="3" && b!="4" && b!="q") e=2;
if (e==2) cout<<"输入错误!"<<'\n'<<'\n';
else {
if (e!=1)
{
if (b=="1") f=1;
if (b=="2") f=2;
if (b=="3") f=3;
if (b=="4") f=4;
if (money<wuqiqian[f]) cout<<"失败"<<'\n'<<'\n';
else { money=money-wuqiqian[f];
wuqiz[1]=wuqiz[2]=wuqiz[3]=wuqiz[4]=0;
wuqiz[f]=1;
str[1]=str[1]+wuqi[f]-temp[2];
temp[2]=wuqi[f];
cout<<"购买成功"<<'\n'<<'\n'; }
}
else cout<<"退出!"<<'\n'<<'\n';
}
}
void fangjud()
{
int e=0,f;
string b;
fangju[1]=5;
fangju[2]=15;
fangju[3]=30;
fangju[4]=50;
cout<<"布衣=1 20$ def+5"<<'\n';
cout<<"皮衣=2 100$ def+15"<<'\n';
cout<<"锁甲=3 500$ def+30"<<'\n';
cout<<"板甲=4 1000$ def+50"<<'\n';
cout<<"退出=q"<<'\n';
cin>>b;
if (b=="q") e=1;
if (b!="1" && b!="2" && b!="3" && b!="4" && b!="q") e=2;
if (e==2) cout<<"输入错误!"<<'\n'<<'\n';
else {
if (e!=1)
{
if (b=="1") f=1;
if (b=="2") f=2;
if (b=="3") f=3;
if (b=="4") f=4;
if (money<fangjuqian[f]) cout<<"失败"<<'\n'<<'\n';
else { money=money-fangjuqian[f];
fangjuz[1]=fangjuz[2]=fangjuz[3]=fangjuz[4]=0;
fangjuz[f]=1;
def[1]=def[1]+fangju[f]-temp[3];
temp[3]=fangju[f];
cout<<"购买成功"<<'\n'<<'\n'; }
}
else cout<<"退出!"<<'\n'<<'\n';
}
}
void shiyong()
{
cout<<"1 小补药有"<<yaopin[1]<<"个"<<'\n';
cout<<"2 大补药有"<<yaopin[2]<<"个"<<'\n';
cout<<"3 全恢复药有"<<yaopin[3]<<"个"<<'\n';
cout<<"4 神奇水有"<<yaopin[4]<<"个"<<'\n';
int c;
cout<<"使用药品=";
cin>>c;
if (yaopin[c]==0) cout<<"失败!!!!"<<'\n'<<'\n';
else
{ yaopin[c]--;
switch (c)
{
case 1:cout<<"hp恢复30"<<'\n';hp[1]=hp[1]+30;
if (hp[1]>hp[2]) hp[1]=hp[2];
break;
case 2:cout<<"hp恢复100"<<'\n';hp[1]=hp[1]+100;
if (hp[1]>hp[2]) hp[1]=hp[2];
break;
case 3:cout<<"hp全恢复"<<'\n';hp[1]=hp[2];
break;
case 4:cout<<"爆豆啦!"<<'\n';str[1]=str[1]+100000;
hp[1]=99999;
break;
}
}
}
void prt3()
{
cout<<"太帅了!打赢Zn,游戏结束"<<'\n';
boss=0;
if (mj=1)
{ str[1]=str[1]+1000;
def[1]=def[1]+1000;
hp[1]=hp[1]+1000;
cout<<"胜利!升级 str="<<str[1]<<" def="<<def[1]<<" hp="<<hp[2]<<'\n';
str[4]=str[4]+10000;
def[4]=def[4]+10000;
money=money+20000;
cout<<"得到20000金"<<'\n'<<'\n';
}
}

[此贴子已经被作者于2006-5-19 22:03:52编辑过]

搜索更多相关主题的帖子: RPG 游戏 include std 
2006-05-19 21:10
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 
你的代码函数名字好丑啊

[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-05-19 21:46
c120110
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2006-2-19
收藏
得分:0 

呵呵!灌下水!顶下!写一个不容易了..


2006-05-20 00:32
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 

呵呵,不好意思,我也只是题意见,对不起啊

[此贴子已经被作者于2006-5-20 11:17:24编辑过]


[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-05-20 11:11
北塔
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-5-16
收藏
得分:0 

创意很好,不过可以在试试面向对象的思维方式.加油

2006-05-20 16:33
p1s
Rank: 4
等 级:贵宾
威 望:10
帖 子:454
专家分:3
注 册:2005-11-4
收藏
得分:0 

嗯,系统满丰富的。
可以考虑面向对象啊!我用面向对象写的。发过帖子了,楼主可以参考看看,交流一下。

2006-05-20 21:43
xiangjiantui
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2005-11-13
收藏
得分:0 
哦,谢谢我想做做巩固一下基础而已

2006-05-20 21:59
无限忧伤
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2006-4-5
收藏
得分:0 
好样的,用Dos屏竟能做出这种东西,小弟佩服!
不过若用MFC做一个类似性质的东西或许会更好.
大家一起加油啊!

2006-05-21 10:54
hsjljh
Rank: 1
等 级:新手上路
帖 子:56
专家分:0
注 册:2005-10-26
收藏
得分:0 
是在牛鼻啊
2006-05-21 11:19
快速回复:[原创]一个经典RPG游戏
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014249 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved