升级小游戏源代码

作者在 2008-01-27 09:52:55 发布以下内容

   
    这是一个用C++编的打怪升级游戏,当初玩《仙剑》,现在也可以玩自己的游戏了。当然了,这个肯定没有《仙剑》好玩了,不过什么事都是从简单到复杂,大家可以好好研究研究,争取做出自己的经典游戏出来~~~...
   需要的去文件库下载源代码!

源代码:

#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<<"你死啦!"<<endl;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'; 
     }
}

C++游戏 | 阅读 7486 次
文章评论,共1条
chuan2008
2008-03-09 20:47
1
好玩
游客请输入验证码
浏览49380次
最新评论