DOS小游戏(二.源文件.cpp)

接着一继续:由于有字数限制。因此要分开ios

==================c++

源文件windows

==================dom

 

  
  
  
  
  1. //main.cpp  
  2. #include <iostream>   
  3.  
  4. #include <windows.h>   
  5. #include<string>  
  6. #include"wait.h"  
  7. #include"character.h"  
  8. #include "Enemy.h"  
  9. #include"Blacksmith.h"  
  10. #include"Select.h"  
  11. using namespace std;  
  12.  
  13. int main()               
  14. {          
  15.     void speek(char c1[][160]);  
  16.     system("TITLE 混沌");//NND。搜索了很久才知道怎样设置。  
  17.     char c1[7][160]={"学c++至今也23天了,嗯,才学到第10章运算符重载,作这个游戏的目的有几个,主要呢是复习以前学所的内容,",  
  18.                      "由于书上关于类的题目比较少嗯,还有就是今天是我生日,想作一个特别的礼物送给本身,",  
  19.                      "让本身明年的今天再看回这个游戏必定会特别有趣.还要感谢贴吧的飞翔 雨夜,以及全部帮助过个人人,很是感谢.",  
  20.                      "至于说为啥分这么多文件写。。实际上是由于我看了第8章的公用接口与私有实现的分离0,因此练习下。这小东西",  
  21.                      "- -花了我17个小时才竣工。。,昨天写到2点用了4个小时,今天点9一直写到晚上11点半了,真累啊.",  
  22.                      "最后说下。。。虽然我知道。。这程序有不少不足。个人技术也不好。但为了赶在今天内完成。质量可能不太好",  
  23.                      "2011/3/14 混沌字。"};  
  24.     speek(c1);  
  25.    
  26.     Select s1;  
  27.     s1.display();  
  28.       
  29.  
  30. }  
  31.  
  32. void speek(char c1[][160])  
  33. {  
  34.     int i,j,h=0;  
  35.     int s=50;  
  36.     for(i=0;i<7;i++)  
  37.     {     
  38.         system("CLS");  
  39.         cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;  
  40.         cout<<"\t";  
  41.         for(j=0;c1[i][j]!='\0';j++)  
  42.         {     
  43.               
  44.             cout<<c1[i][j];  
  45.             h++;  
  46.             Sleep(s);  
  47.               
  48.         }  
  49.         Sleep(2000);  
  50.           
  51.     }  
  52.       
  53.       
  54.       
  55.           
  56.       

=================================ide

资源文件动画

====================================spa

 

  
  
  
  
  1. //Blacksmith.cpp  
  2. #ifndef ONE4  
  3. #include <iostream>   
  4. #include <windows.h>    
  5. #include"wait.h"  
  6. #include"Blacksmith.h"  
  7. #include"Character.h"  
  8. #include"Fighting.h"  
  9. #include <time.h>  
  10. using namespace std;  
  11.  
  12. void Blacksmith::display()  
  13. {  
  14.     int a;  
  15.     do 
  16.     {system("CLS");  
  17.     cout<<endl<<endl<<endl<<endl<<endl<<endl;  
  18.     cout<<"\t\t\t〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl;  
  19.     cout<<"\t\t\t☆         黑死你铁匠店         ★"<<endl;  
  20.     cout<<"\t\t\t〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓"<<endl;  
  21.     cout<<"\t\t\t1.强化武器(须要5点混沌币)"<<endl;  
  22.     cout<<"\t\t\t2.特殊属性附魔(须要5点混沌币)"<<endl;  
  23.     cout<<"\t\t\t3.返回主界面"<<endl<<endl;  
  24.     cout<<"\t\t\t你目前的武器是:";  
  25.     cout<<Character::b_prefix_name<<Character::b_weapons_name<<"("<<(Character::b_weapons+Character::b_prefix)<<")";  
  26.     cout<<endl;  
  27.       
  28.     cin>>a;  
  29.     cin.ignore(1024,'\n');  
  30.     if(a==1)//===========================武器强化==========================  
  31.     {  
  32.         if(Character::money<5)  
  33.         {  
  34.             do 
  35.             {  
  36.                 cout<<"你的混沌币不够,请及时充值。";  
  37.                 cin>>a;  
  38.                 cin.ignore(1024,'\n');  
  39.             }while(a!=3);  
  40.         }  
  41.         else if(Character::money>=5)  
  42.         {  
  43.            Character::money-=5;  
  44.            if(Character::b_weapons_name=="木剑")  
  45.            {    
  46.                int b;  
  47.               b=Fighting::random(1);  
  48.               switch(b)  
  49.               {  
  50.               case 0:  
  51.                   {  
  52.                       Character::b_weapons_name=Character::weapons_name[1];//武器名更改  
  53.                       Character::b_weapons=Character::weapons[1];//属性更改  
  54.                        Character::attack  =(Character::b_attack+Character::b_weapons+Character::b_prefix);//最终***=基本+武器+前缀  
  55.                       cout<<"强化成功!"<<endl;  
  56.                       Sleep(1000);  
  57.                       system("CLS");  
  58.                       Wait::display(10);  
  59.                       break;  
  60.                   }  
  61.               default:cout<<"强化失败。"<<endl;    
  62.                       Sleep(1000);  
  63.                       system("CLS");  
  64.                       Wait::display(10);break;  
  65.               }  
  66.            }  
  67.           else if(Character::b_weapons_name=="木剑+1")  
  68.            {  //================================================  
  69.                int b;  
  70.               b=Fighting::random(2);  
  71.               switch(b)  
  72.               {  
  73.               case 0:  
  74.                   {  
  75.                       Character::b_weapons_name=Character::weapons_name[2];//武器名更改  
  76.                       Character::b_weapons=Character::weapons[2];//属性更改  
  77.                        Character::attack  =(Character::b_attack+Character::b_weapons+Character::b_prefix);//最终***=基本+武器+前缀  
  78.                       cout<<"强化成功!"<<endl;  
  79.                       Sleep(1000);  
  80.                       system("CLS");  
  81.                       Wait::display(10);  
  82.                       break;  
  83.                   }  
  84.               default:cout<<"强化失败。"<<endl;    
  85.                       Sleep(1000);  
  86.                       system("CLS");  
  87.                       Wait::display(10);break;  
  88.               }  
  89.            }//=============================================  
  90.           else if(Character::b_weapons_name=="木剑+2")  
  91.            {  //================================================  
  92.                int b;  
  93.               b=Fighting::random(5);  
  94.               switch(b)  
  95.               {  
  96.               case 0:  
  97.                   {  
  98.                       Character::b_weapons_name=Character::weapons_name[3];//武器名更改  
  99.                       Character::b_weapons=Character::weapons[3];//属性更改  
  100.                        Character::attack  =(Character::b_attack+Character::b_weapons+Character::b_prefix);//最终***=基本+武器+前缀  
  101.                       cout<<"强化成功!"<<endl;  
  102.                       Sleep(1000);  
  103.                       system("CLS");  
  104.                       Wait::display(10);  
  105.                       break;  
  106.                   }  
  107.               default:cout<<"强化失败。"<<endl;    
  108.                       Sleep(1000);  
  109.                       system("CLS");  
  110.                       Wait::display(10);break;  
  111.               }  
  112.            }//=============================================  
  113.            else if(Character::b_weapons_name=="木剑+3")  
  114.            {  //================================================  
  115.                int b;  
  116.               b=Fighting::random(10);  
  117.               switch(b)  
  118.               {  
  119.               case 0:  
  120.                   {  
  121.                       Character::b_weapons_name=Character::weapons_name[4];//武器名更改  
  122.                       Character::b_weapons=Character::weapons[4];//属性更改  
  123.                        Character::attack  =(Character::b_attack+Character::b_weapons+Character::b_prefix);//最终***=基本+武器+前缀  
  124.                       cout<<"强化成功!"<<endl;  
  125.                       Sleep(1000);  
  126.                       system("CLS");  
  127.                       Wait::display(10);  
  128.                       break;  
  129.                   }  
  130.               default:cout<<"强化失败。"<<endl;    
  131.                       Sleep(1000);  
  132.                       system("CLS");  
  133.                       Wait::display(10);break;  
  134.               }  
  135.  
  136.            }//=============================================  
  137.           else if(Character::b_weapons_name=="木剑+4")  
  138.           {  
  139.               cout<<"没法强化,已是最高等级";  
  140.               Character::money+=5;  
  141.            }  
  142.  
  143.         }  
  144.     }//===========================武器强化==========================  
  145.  
  146.  
  147.     else if(a==2)//===========================特殊附魔==========================  
  148.     {  
  149.         if(Character::money<5)  
  150.         {  
  151.             do 
  152.             {  
  153.                 cout<<"你的混沌币不够,请及时充值。";  
  154.                 cin>>a;  
  155.                 cin.ignore(1024,'\n');  
  156.             }while(a!=3);  
  157.         }  
  158.         else if(Character::money>=5)  
  159.         {  
  160.            Character::money-=5;  
  161.               
  162.                int b;  
  163.               b=Fighting::random(9);  
  164.               switch(b)  
  165.               {  
  166.               case 0:  
  167.                   {  
  168.                       Character::b_prefix_name=Character::prefix_name[1];//武器名更改  
  169.                       Character::b_prefix=Character::prefix[1];//属性更改  
  170.                       Character::attack  =(Character::b_attack+Character::b_weapons+Character::b_prefix);//最终***=基本+武器+前缀  
  171.                       cout<<"附魔成功!"<<endl;  
  172.                       Sleep(1000);  
  173.                       system("CLS");  
  174.                       Wait::display(10);  
  175.                       break;  
  176.                   }  
  177.               case 1:  
  178.               case 2:  
  179.               case 3:  
  180.                   {  
  181.                       Character::b_prefix_name=Character::prefix_name[2];//武器名更改  
  182.                       Character::b_prefix=Character::prefix[2];//属性更改  
  183.                        Character::attack  =(Character::b_attack+Character::b_weapons+Character::b_prefix);//最终***=基本+武器+前缀  
  184.                       cout<<"附魔成功!"<<endl;  
  185.                       Sleep(1000);  
  186.                       system("CLS");  
  187.                       Wait::display(10);  
  188.                       break;  
  189.  
  190.                   }  
  191.               case 4:  
  192.               case 5:  
  193.                     
  194.                   {  
  195.                     
  196.                       Character::b_prefix_name=Character::prefix_name[3];//武器名更改  
  197.                       Character::b_prefix=Character::prefix[3];//属性更改  
  198.                        Character::attack  =(Character::b_attack+Character::b_weapons+Character::b_prefix);//最终***=基本+武器+前缀  
  199.                       cout<<"附魔成功!"<<endl;  
  200.                       Sleep(1000);  
  201.                       system("CLS");  
  202.                       Wait::display(10);  
  203.                       break;  
  204.  
  205.                   }  
  206.               case 6:  
  207.                   {  
  208.                     
  209.                       Character::b_prefix_name=Character::prefix_name[4];//武器名更改  
  210.                       Character::b_prefix=Character::prefix[4];//属性更改  
  211.                        Character::attack =(Character::b_attack+Character::b_weapons+Character::b_prefix);//最终***=基本+武器+前缀  
  212.                       cout<<"附魔成功!"<<endl;  
  213.                       Sleep(1000);  
  214.                       system("CLS");  
  215.                       Wait::display(10);  
  216.                       break;  
  217.  
  218.                   }  
  219.  
  220.               default:  
  221.                   {     
  222.                       Character::b_prefix_name=Character::prefix_name[0];//武器名更改  
  223.                       Character::b_prefix=Character::prefix[0];//属性更改  
  224.                        Character::attack  =(Character::b_attack+Character::b_weapons+Character::b_prefix);//最终***=基本+武器+前缀  
  225.                       cout<<"附魔失败。"<<endl;    
  226.                       Sleep(1000);  
  227.                       system("CLS");  
  228.                       Wait::display(10);break;  
  229.                    }  
  230.            }  
  231.             
  232.         }  
  233.     }//===========================特殊附魔==========================  
  234.       
  235.     }while(a!=3);  
  236.     system("CLS");  
  237. }  
  238. #define ONE4   
  239.  
  240. #endif ; 

 

  
  
  
  
  1. //Character.cpp  
  2. #include <iostream>   
  3. #include <windows.h>    
  4. #include<string>  
  5. #include"Character.h"  
  6. #include"Wait.h"  
  7.  
  8. using namespace std;  
  9.  
  10. /*=========常类=============*/ 
  11.  
  12. int Character::money    =10;  
  13. string Character::name  ="混沌";  
  14. int Character::exp_max  =100;  
  15. int Character::exp_min  =0;  
  16. int Character::lv       =1;  
  17.  
  18. //============库类==============  
  19.  
  20. string Character::weapons_name[5] ={"木剑","木剑+1","木剑+2","木剑+3","木剑+4"};//武器名字  
  21. int    Character::weapons[5]      ={10,15,25,60,120};   //        武器属性  
  22. string Character::clothes_name    ="布衣";//衣服名字  
  23. int    Character::clothes         =10;//        衣服属性  
  24. string Character::prefix_name[4]  ={"","幸运的","巨熊的","破坏的"};//      属性前缀名字  
  25. int    Character::prefix[4]       ={0,5,30,60};//         属性前缀     
  26.  
  27. /*=======身上装备类==============*/ 
  28.  
  29. string Character::b_weapons_name =weapons_name[0];  //身上武器名字  
  30. int    Character::b_weapons      =weapons[0];       //身上武器属性  
  31. string Character::b_prefix_name  =prefix_name[0];   //武器前缀名字  
  32. int    Character::b_prefix       =prefix[0];        //武器前缀属性  
  33. string Character::b_clothes_name =clothes_name;     //身上衣服名字  
  34. int    Character::b_clothes      =clothes;          //身上衣服属性  
  35.  
  36. /*=========属性类=============*/ 
  37.  
  38. int Character::life_max   =20;  
  39. int Character::life_min   =20;  
  40. int Character::magic_max  =10;  
  41. int Character::magic_min  =10;  
  42. double Character::b_attack   =5;//基本***  
  43. double Character::attack     =(b_attack+b_weapons+b_prefix);//最终***=基本+武器+前缀  
  44. double Character::b_defense  =10;//基本防护  
  45. double Character::defense    =(b_defense+b_clothes);  
  46.  
  47.  
  48. void Character::display(string p)  
  49. {  
  50.       
  51.     if(p=="money")cout<<"混沌币:"<<money<<"点";  
  52.     else if(p=="name")cout<<"『"<<name<<"』";  
  53.     else if(p=="exp")  
  54.     {      
  55.         while(exp_min>=exp_max)  
  56.         {  
  57.             int temp=0;  
  58.             temp=exp_min-exp_max;  
  59.             exp_max=exp_max*1.5*lv;//经验公式  
  60.             exp_min=temp;  
  61.             lv++;  
  62.             //====升级属性提高=====//  
  63.             life_max=life_max*1.5;//------升级后生命增长  
  64.             life_min=life_max;//    ------生命全满  
  65.             magic_max=magic_max*1.5;//同上  
  66.             magic_min=magic_max;//    ----  
  67.             b_attack=b_attack*1.5;//***增长  
  68.             b_defense=b_defense*1.5;//防护增长  
  69.         }  
  70.         cout<<"Exp:"<<exp_min<<"/"<<exp_max;  
  71.     }  
  72.     else if(p=="lv")cout<<"Lv:"<<lv;  
  73.     else if(p=="life")  
  74.     {  
  75.         cout<<"Hp:";  
  76.         cout<<life_min<<"/"<<life_max<<" ";  
  77.  
  78.         if(life_min > life_max*0.6&&life_min<=life_max*0.8)  
  79.  
  80.             cout<<'\003'<<'\003'<<'\003'<<'\003';  
  81.  
  82.         else if (life_min > life_max*0.4&&life_min<=life_max*0.6)  
  83.  
  84.             cout<<'\003'<<'\003'<<'\003';  
  85.  
  86.         else if (life_min > life_max*0.2&&life_min<=life_max*0.4)  
  87.  
  88.             cout<<'\003'<<'\003';  
  89.  
  90.         else if (life_min>0&&life_min<=life_max*0.2)  
  91.  
  92.             cout<<'\003';  
  93.  
  94.         else if (life_min==0)  
  95.  
  96.             cout<<"死亡";  
  97.         else 
  98.            cout<<'\003'<<'\003'<<'\003'<<'\003'<<'\003';  
  99.     }  
  100.  
  101.     else if (p=="magic")//因为没开发技能。。因此无论了  
  102.     {  
  103.         cout<<"Mp:"<<magic_min<<"/"<<magic_max<<" ";  
  104.             if(magic_min<=magic_max*0.8)  
  105.             cout<<'\016'<<'\016'<<'\016'<<'\016';  
  106.         else if (magic_min<=magic_max*0.6)  
  107.             cout<<'\016'<<'\016'<<'\016';  
  108.         else if (magic_min<=magic_max*0.4)  
  109.             cout<<'\016'<<'\016';  
  110.         else if (magic_min<=magic_max*0.2)  
  111.             cout<<'\016';  
  112.         else if (magic_min==0)  
  113.             cout<<" ";  
  114.         else 
  115.            cout<<'\016'<<'\016'<<'\016'<<'\016'<<'\016';  
  116.     }  
  117.     else if (p=="attack")cout<<"***力:"<<attack<<"("<<b_attack<<"+"<<(b_weapons+b_prefix)<<")";  
  118.     else if (p=="defense")cout<<"防护力:"<<defense<<"("<<b_defense<<"+"<<b_clothes<<")";  
  119.     else if (p=="w_name")cout<<"武器:"<<b_prefix_name<<b_weapons_name<<"("<<(b_weapons+b_prefix)<<")";  
  120.     else if (p=="c_name")cout<<"衣服:"<<b_clothes_name<<"("<<b_clothes<<")";  
  121.       
  122.  
  123.       
  124. }  
  125.  
  126. void Character::show()//人物头像  
  127. {  
  128.       
  129.  
  130.  
  131.     cout<<"       __------__       "  <<endl  
  132.         <<"     /~          ~\\   "<<endl  
  133.         <<"    |    //^\\//^\\  |" << endl  
  134.         <<" /~~\   ||  o| |o|:~\\   "<<endl  
  135.         <<"| |6   ||___|_|_|l: l    "<<endl  
  136.         <<" \__.  /     o    \\ /'    "<<endl  
  137.         <<"   |   (       O   )   "<<endl  
  138.         <<"    `\\  \\          /    "<<endl  
  139.         <<"      )  ~------~`\\    "<<endl;  
  140. }  
  141. void Character::view_properties()//查看属性  
  142. {  
  143.     int a=0;  
  144.     do 
  145.     {  
  146.     system("CLS");  
  147.     cout<<endl;  
  148.     cout<<endl;  
  149.     cout<<endl;  
  150.     cout<<"\t\t\t\t ①返回选择界面"<<endl;  
  151.  
  152.     string life="life",magic="magic",money="money",attack="attack",defense="defense",  
  153.         name="name",w_name="w_name",c_name="c_name";  
  154.      //其实能够直接打字符串的。。不过。。我怕忘记了。。因此。。  
  155.       
  156.     show();  
  157.     cout<<endl;  
  158.     cout<<"   ";  
  159.     display(name);  
  160.     cout<<"\t";  
  161.     display("lv");  
  162.     cout<<endl;  
  163.     display("exp");  
  164.     cout<<endl;  
  165.     display(life);  
  166.     cout<<"\t";  
  167.     display(attack);  
  168.     cout<<endl;  
  169.     display(magic);  
  170.     cout<<"\t";  
  171.     display(defense);  
  172.     cout<<endl;  
  173.     display(money);  
  174.     cout<<endl<<"=======装备栏========"<<endl;  
  175.     display(w_name);  
  176.     cout<<endl;  
  177.     display(c_name);  
  178.     cout<<endl;  
  179.     cin>>a;  
  180.       
  181.     cin.ignore(1024,'\n');  
  182.     if(a==1)  
  183.     {  
  184.         Wait::display(10);  
  185.     }  
  186.     }while(a!=1);  
  187.  
  188. }  
  189.  

 

  
  
  
  
  1. //Enemy.cpp  
  2. #include <iostream>   
  3. #include <windows.h>    
  4. #include<string>  
  5. #include"Character.h"  
  6. #include"Enemy.h"  
  7. using namespace std;  
  8.  
  9.  
  10.  
  11.     string Enemy::e_name="梦魇杂兵";  
  12.     int Enemy::e_hp=10;  
  13.     int Enemy::e_att=10;  
  14.     int Enemy::e_def=10;  
  15.     //====BOSS=====  
  16.     string Enemy::boss_name="心魔";  
  17.     int Enemy::boss_hp=100;  
  18.     int Enemy::boss_att=100;  
  19.     int Enemy::boss_def=100;  
  20.  
  21. void Enemy::display(string p)  
  22. {  
  23.     if(p=="e_name")cout<<"『"<<e_name<<"』";  
  24.     else if(p=="e_hp")cout<<"Hp:"<<e_hp;  
  25.     else if(p=="e_att")cout<<"***力:"<<e_att;  
  26.     else if(p=="boss_name")cout<<"¤"<<boss_name<<"¤";  
  27.     else if(p=="boss_hp")cout<<"Hp:"<<boss_hp;  
  28.     else if(p=="boss_att")cout<<"***力:"<<boss_att;  
  29. }  
  30. void Enemy::set(string p)  
  31. {  
  32.     if(p=="e_name")//杂兵 属性设置  
  33.      {  
  34.          e_hp=(Character::life_max)/2;//角色生命的一半  
  35.          e_att=(Character::attack)*1.5;//角色***的1.5  
  36.          e_def=5;//防护值  
  37.     }  
  38.     if(p=="boss_name")//BOSS 属性设置  
  39.     {  
  40.         boss_hp=(Character::life_max)*3;//角色生命的3倍  
  41.         boss_att=(Character::attack)*2;//角色***的2倍  
  42.         boss_def=0;//防护值  
  43.     }  

 

  
  
  
  
  1. //Fighting.cpp  
  2. #ifndef ONE5  
  3. #include<iostream>  
  4. #include<string>  
  5. #include<windows.h>  
  6. #include <time.h>  
  7.  
  8. #include"Fighting.h"  
  9. #include"Enemy.h"  
  10. #include"Character.h"  
  11. #include"wait.h"  
  12.  
  13. using namespace std;  
  14. char Fighting::role[3][50]      ={":废话少说,看招!\0",      ":吃我一拳!",                              ":………………打不打啊,我要睡着了。。。"};//人物对话  
  15. char Fighting::e_role[3][50]    ={":今每天气不错~",           ":大爷今天心情不错,不杀你,快从我眼前消失"":武功再高,也怕个人菜刀!"               };//怪物对话  
  16. char Fighting::b_role[3][50]    ={":人类,你这是自寻死路!"":很久没见过玩具来这里了~",                ":想打败我那是痴心妄想!我是无敌的!"   };//BOSS对话  
  17. string Fighting::mode="att";  
  18. void Fighting::d_speed(int a,string p)//用法d_speed(rand(3),"role/e_role/b_role")  
  19. {  
  20.     int i=0;  
  21.     int s=50;  
  22.     if(p=="role")  
  23.         while(role[a][i]!='\0')  
  24.         {  
  25.             cout<<role[a][i];  
  26.             Sleep(s);  
  27.             i++;  
  28.         }  
  29.     else if(p=="e_role")  
  30.         while(e_role[a][i]!='\0')  
  31.         {  
  32.             cout<<e_role[a][i];  
  33.             Sleep(s);  
  34.             i++;  
  35.         }  
  36.     else if (p=="b_role")  
  37.         while(b_role[a][i]!='\0')  
  38.         {  
  39.             cout<<b_role[a][i];  
  40.             Sleep(s);  
  41.             i++;  
  42.         }  
  43. }  
  44. int Fighting::random(int a)  
  45. {  
  46.  
  47.     srand((unsigned)time(NULL));  
  48.     return (rand()%a);  
  49.  
  50. }  
  51. void Fighting::hurt(string p1)//p1打人者 mod为战斗模式att or def  
  52. {  
  53.     if(p1=="e_name")//杂兵打主角  
  54.     {  
  55.         double a=0;//被打防减伤率  
  56.  
  57.         if(mode=="def")//若是角色是防护模式  
  58.         {  
  59.             double m=Character::defense*2;//防护值加倍  
  60.  
  61.             a=1-1/(1+m/10);//防护值物免伤率=1-1/(1+防守者防护总值/10)   
  62.             cout<<"\t\t\t\t\t";  
  63.             Character::display("name");  
  64.             cout<<"防护"<<endl;  
  65.         }    
  66.         else if(mode=="att")  
  67.         {  
  68.  
  69.             a=1-1/(1+Character::defense/10);//防护值物免伤率=1-1/(1+防守者防护总值/10)  
  70.         }  
  71.         //=====伤害赋值=======  
  72.         double b=0;   
  73.         b=Enemy::e_att-Enemy::e_att*a;//伤害=***-****免伤  
  74.         Character::life_min=Character::life_min-int(b);  
  75.         cout<<"\t\t\t\t\t";  
  76.         Character::display("name");  
  77.         cout<<"受到了"<<int(b)<<"点伤害"<<endl;  
  78.     }  
  79.     else if(p1=="boss_name")//boss打主角  
  80.     {  
  81.         double a=0;//被打防减伤率  
  82.  
  83.         if(mode=="def")//若是角色是防护模式  
  84.         {  
  85.             double m=Character::defense*2;//防护值加倍  
  86.  
  87.             a=1-1/(1+m/10);//防护值物免伤率=1-1/(1+防守者防护总值/10)   
  88.         }    
  89.         else if(mode=="att")  
  90.         {  
  91.  
  92.             a=1-1/(1+Character::defense/10);//防护值物免伤率=1-1/(1+防守者防护总值/10)  
  93.         }  
  94.         //=====伤害赋值=======  
  95.         double b=0;   
  96.         b=Enemy::boss_att-Enemy::boss_att*a;//伤害=***-****免伤  
  97.         Character::life_min=Character::life_min-int(b);  
  98.         cout<<"\t\t\t\t\t";  
  99.         Character::display("name");  
  100.         cout<<"受到了"<<int(b)<<"点伤害"<<endl;  
  101.     }  
  102.     else if(p1=="name_e")//主角打杂兵  
  103.     {  
  104.         double a=0;//被打防减伤率  
  105.         a=1-1/(1+Enemy::e_def/10);//防护值物免伤率=1-1/(1+防守者防护总值/10)  
  106.  
  107.         //=====伤害赋值=======  
  108.         double b=0;   
  109.         b=Character::attack-Character::attack*a;//伤害=***-****免伤  
  110.         Enemy::e_hp=Enemy::e_hp-int(b);  
  111.         cout<<"\t\t\t\t\t";  
  112.         Enemy::display("e_name");  
  113.         cout<<"受到了"<<int(b)<<"点伤害"<<endl;  
  114.     }  
  115.     else if(p1=="name_boss")//主角打BOSS  
  116.     {     
  117.         double a=0;//被打防减伤率 BOSS无防护  
  118.         //  a=1-1/(1+Enemy::e_def/10);//防护值物免伤率=1-1/(1+防守者防护总值/10)  
  119.  
  120.         //=====伤害赋值=======  
  121.         double b=0;   
  122.         b=Character::attack-Character::attack*a;//伤害=***-****免伤  
  123.         Enemy::boss_hp=Enemy::boss_hp-int(b);  
  124.         cout<<"\t\t\t\t\t";  
  125.         Enemy::display("boss_name");  
  126.         cout<<"受到了"<<int(b)<<"点伤害"<<endl;  
  127.     }  
  128.  
  129. }  
  130. void Fighting::display(string p)  
  131. {  
  132.     if(p=="e_name")  
  133.     {  
  134.         system("CLS");//清屏  
  135.         cout<<endl;  
  136.         cout<<endl;  
  137.         cout<<endl;  
  138.         Enemy::set(p);//设置敌人属性  
  139.         string e_name="e_name",e_hp="e_hp",e_att="e_att";  
  140.  
  141.         cout<<"                      ";  
  142.         Enemy::display(e_name);  
  143.  
  144.  
  145.         d_speed(random(2),"e_role");//敌方对话  
  146.         cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl;  
  147.         cout<<"       ";  
  148.         Sleep(1000);  
  149.         Character::display("name");  
  150.         d_speed(random(2),"role");//我方对话  
  151.         Sleep(1000);//等待1秒  
  152.         system("CLS");//清除对话  
  153.         Wait::display(13);//转场动画  
  154.  
  155.         //=============================  
  156.         //=========战斗开始============  
  157.         //=============================  
  158.  
  159.         //===========界面数据输出========  
  160.         do 
  161.         {  
  162.             system("CLS");  
  163.             cout<<endl<<"\t\t 1.***"<<endl<<"\t\t 2.防护"<<endl<<endl<<endl;  
  164.             cout<<"\t\t\t\t\t\t";  
  165.             Enemy::display(e_name);  
  166.             cout<<endl;  
  167.             cout<<"\t\t\t\t\t\t";  
  168.             Enemy::display(e_hp);  
  169.             cout<<"\t";  
  170.             Enemy::display(e_att);  
  171.             cout<<endl<<endl<<endl<<endl;  
  172.             Character::show();//====头像  
  173.             cout<<"\t";  
  174.             Character::display("name");  
  175.             cout<<"  ";  
  176.             Character::display("lv");  
  177.             cout<<endl<<"  ";  
  178.             Character::display("life");  
  179.             cout<<"  ";  
  180.             Character::display("attack");  
  181.             cout<<endl<<"  ";  
  182.             Character::display("magic");  
  183.             cout<<"  ";  
  184.             Character::display("defense");  
  185.             cout<<endl;  
  186.             //===========界面数据输出========  
  187.             //============选择战斗方式========//  
  188.  
  189.             int a;  
  190.             cin>>a;  
  191.             cin.ignore(1024,'\n');  
  192.             if(a==1)  
  193.             {  
  194.                 mode="att";//***模式  
  195.                 hurt("name_e");//角色打怪  
  196.                 if(Enemy::e_hp>0)//怪未死  
  197.                 {  
  198.                     Sleep(2000);  
  199.                     hurt("e_name");//打角色  
  200.                     if(Character::life_min<0)//角色死了  
  201.               {  
  202.                   Sleep(2000);  
  203.                   Wait::display(10);  
  204.                   Sleep(2000);  
  205.                   cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;  
  206.                   cout<<"\t\t\t\t角色死亡   GAME OVER"<<endl;  
  207.                   Sleep(4000);  
  208.  
  209.                   cout<<"\t\t\t\t哈被骗了吧,菜鸟,复活术~";  
  210.                     }  
  211.                 }  
  212.                 else if(Enemy::e_hp<0)//怪死了  
  213.                 {  
  214.                     Sleep(2000);  
  215.                     Wait::display(10);  
  216.                     cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;  
  217.                     int up;  
  218.  
  219.                     up=Character::lv;  
  220.                     Character::money+=20;  
  221.                     Character::exp_min+=20;  
  222.  
  223.                     cout<<"\t\t\t\t得到了20点混沌币";  
  224.                     cout<<endl;  
  225.                     cout<<"\t\t\t\t得到了20点经验值";  
  226.                     cout<<endl;  
  227.                     cout<<"\t\t\t\t";  
  228.                     Character::display("exp");  
  229.                     cout<<endl;  
  230.                     if(up<Character::lv)  
  231.                         cout<<"\t\t\t\t升级了!!!";  
  232.                     Character::attack  =(Character::b_attack+Character::b_weapons+Character::b_prefix);//最终***=基本+武器+前缀  
  233.                     cout<<endl;  
  234.                     Sleep(2000);  
  235.                     Wait::display(10);  
  236.                 }  
  237.             }  
  238.  
  239.             else if(a==2)  
  240.             {   
  241.                 mode="def";//防护模式  
  242.                 hurt("e_name");//怪打角色  
  243.                 Sleep(2000);  
  244.  
  245.                 if(Character::life_min<0)//角色死了  
  246.                 {  
  247.                     Sleep(2000);  
  248.                     Wait::display(10);  
  249.                     Sleep(2000);  
  250.                     cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;  
  251.                     cout<<"\t\t\t\t角色死亡   GAME OVER"<<endl;  
  252.                     Sleep(4000);  
  253.  
  254.                     cout<<"\t\t\t\t哈被骗了吧,菜鸟,复活术~";  
  255.  
  256.                 }     
  257.                 else Sleep(2000);  
  258.  
  259.             }  
  260.  
  261.         }while((Enemy::e_hp>0)&&(Character::life_min>0));  
  262.         if(Character::life_min<=0)  
  263.             Character::life_min=Character::life_max;  
  264.     }  
  265.     //===============================================  
  266.     //==================BOSS==========================  
  267.     //===============================================  
  268.     else if(p=="boss_name")  
  269.     {  
  270.         system("CLS");//清屏  
  271.         cout<<endl;  
  272.         cout<<endl;  
  273.         cout<<endl;  
  274.         Enemy::set(p);//设置敌人属性  
  275.  
  276.  
  277.         cout<<"                      ";  
  278.         Enemy::display("boss_name");  
  279.  
  280.  
  281.         d_speed(random(2),"b_role");//敌方对话  
  282.         cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl;  
  283.         cout<<"       ";  
  284.         Sleep(1000);  
  285.         Character::display("name");  
  286.         d_speed(random(2),"role");//我方对话  
  287.         Sleep(1000);//等待1秒  
  288.         system("CLS");//清除对话  
  289.         Wait::display(13);//转场动画  
  290.  
  291.         //=============================  
  292.         //=========战斗开始============  
  293.         //=============================  
  294.  
  295.         //===========界面数据输出========  
  296.         do 
  297.         {  
  298.             system("CLS");  
  299.             cout<<endl<<"\t\t 1.***"<<endl<<"\t\t 2.防护"<<endl<<endl;  
  300.             cout<<"\t\t\t\t\t\t";  
  301.             Enemy::display("boss_name");  
  302.             cout<<endl;  
  303.             cout<<"\t\t\t\t\t\t";  
  304.             Enemy::display("boss_hp");  
  305.             cout<<"\t";  
  306.             Enemy::display("boss_att");  
  307.             cout<<endl<<endl<<endl<<endl;  
  308.             Character::show();//====头像  
  309.             cout<<"\t";  
  310.             Character::display("name");  
  311.             cout<<"  ";  
  312.             Character::display("lv");  
  313.             cout<<endl<<"  ";  
  314.             Character::display("life");  
  315.             cout<<"  ";  
  316.             Character::display("attack");  
  317.             cout<<endl<<"  ";  
  318.             Character::display("magic");  
  319.             cout<<"  ";  
  320.             Character::display("defense");  
  321.             cout<<endl;  
  322.             //===========界面数据输出========  
  323.             //============选择战斗方式========//  
  324.  
  325.             int a;  
  326.             cin>>a;  
  327.             cin.ignore(1024,'\n');  
  328.             if(a==1)  
  329.             {  
  330.                 mode="att";//***模式  
  331.                 hurt("name_boss");//角色打怪  
  332.                 if(Enemy::boss_hp>0)//怪未死  
  333.                 {  
  334.                     Sleep(2000);  
  335.                     hurt("boss_name");//打角色  
  336.                     if(Character::life_min<0)//角色死了  
  337.                     {  
  338.                        Sleep(2000);  
  339.                        Wait::display(10);  
  340.                        Sleep(2000);  
  341.                        cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;  
  342.                        cout<<"\t\t\t\t角色死亡   GAME OVER"<<endl;  
  343.                        Sleep(4000);  
  344.                        cout<<"\t\t\t\t哈被骗了吧,菜鸟,复活术~";  
  345.                     }  
  346.                     Sleep(2000);  
  347.                 }  
  348.                 else if(Enemy::boss_hp<0)//怪死了  
  349.                 {  
  350.                     Sleep(2000);  
  351.                     Wait::display(10);  
  352.                     cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;  
  353.                     int up;  
  354.  
  355.                     up=Character::lv;  
  356.                     Character::money+=1000;  
  357.                     Character::exp_min+=2000;  
  358.                     cout<<"\t\t\t\t得到1000点混沌币。";  
  359.                     cout<<endl;  
  360.                     cout<<"\t\t\t\t得到2000点经验币。";  
  361.                     cout<<endl;  
  362.                     cout<<"\t\t\t\t";  
  363.                     Character::display("exp");  
  364.                     cout<<endl;  
  365.                     if(up<Character::lv)  
  366.                         cout<<"\t\t\t\t升级了!!!";  
  367.                     cout<<endl;  
  368.                     Sleep(2000);;  
  369.                     Wait::display(10);  
  370.                 }  
  371.             }  
  372.  
  373.             else if(a==2)  
  374.             {   
  375.                 mode="def";//防护模式  
  376.                 hurt("boss_name");//怪打角色  
  377.                 Sleep(2000);  
  378.  
  379.                 if(Character::life_min<0)//角色死了  
  380.                 {  
  381.                     Sleep(2000);  
  382.                     Wait::display(10);  
  383.                     Sleep(2000);  
  384.                     cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;  
  385.                     cout<<"\t\t\t\t角色死亡   GAME OVER"<<endl;  
  386.                     Sleep(4000);  
  387.                     cout<<"\t\t\t\t哈被骗了吧,菜鸟,复活术~";  
  388.                 }     
  389.                 else Sleep(2000);  
  390.  
  391.             }  
  392.  
  393.         }while((Enemy::boss_hp>0)&&(Character::life_min>0));  
  394.         if(Character::life_min<=0)  
  395.             Character::life_min=Character::life_max;  
  396.     }  
  397. }  
  398. #define ONE5  
  399.  
  400. #endif ; 

 

 

  
  
  
  
  1. //Select.cpp  
  2. #include<iostream>  
  3. #include"Select.h"  
  4. #include"Fighting.h"  
  5. #include"Character.h"  
  6. #include"Blacksmith.h"  
  7. using namespace std;  
  8.  
  9. void Select::display()  
  10. {  
  11.     int a;  
  12.     do 
  13.     {  
  14.         system("CLS");  
  15.     cout<<endl<<endl<<endl<<endl<<endl;  
  16.     cout<<"\t\t\t※①练级"<<endl;  
  17.     cout<<"\t\t\t※②查看属性"<<endl;  
  18.     cout<<"\t\t\t※③铁匠铺"<<endl;  
  19.     cout<<"\t\t\t※④挑战BOSS"<<endl;  
  20.     cout<<"\t\t\t※⑤退出游戏"<<endl;  
  21.     cin>>a;  
  22.     cin.ignore(1024,'\n');  
  23.     if(a==1)  
  24.     {  
  25.         Fighting::display("e_name");  
  26.     }  
  27.     else if(a==2)  
  28.     {  
  29.         Character::view_properties();  
  30.     }  
  31.     else if(a==3)  
  32.     {  
  33.         Blacksmith::display();  
  34.     }  
  35.     else if(a==4)  
  36.     {  
  37.        Fighting::display("boss_name");  
  38.     }  
  39.     }while(a!=5);  
  40.  
  41. }  

 

 

  
  
  
  
  1. //Wait.cpp  
  2. #include <iostream>   
  3. #include <windows.h>    
  4. using namespace std;  
  5. #include"wait.h"  
  6. void Wait::display(int time)  
  7. {  
  8.     int j;  
  9.     int k;  
  10.           
  11.         for(j=0;j<time;j++)                  
  12.         {      
  13.  
  14.              cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl;  
  15.             for(k=0;k<=j;k++)  
  16.                 cout<<"     ";  
  17.  
  18.             cout<<"  oooO"<<endl;  
  19.             for(k=0;k<=j;k++)  
  20.                 cout<<"     ";  
  21.             cout<<" (   )"<<endl;  
  22.             for(k=0;k<=j;k++)  
  23.                 cout<<"     ";  
  24.             cout<<"  \\ (   "<<endl;  
  25.             for(k=0;k<=j;k++)  
  26.                  cout<<"     ";  
  27.             cout<<"   \\_)"<<endl;  
  28.               
  29.           
  30.             Sleep(100);   
  31.             system("CLS");                
  32.         }  
  33. }  
  34.  

 

OK了。好困啊接口