问题标题: 酷町堂:有趣的程序

0
0
已解决
李泽远
李泽远
高级天翼
高级天翼

各位大佬有什么有趣的程序,赶快亮上来吧!

我先发一个,字符串解密。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    getline(cin,a);
    for(int i=0;i<a.size();i++)
    {
		if(a[i]=='4'&&a[i+1]=='6')
            a.replace(i,2,".");
        if(a[i]=='6'&&a[i+1]=='3')
            a.replace(i,2,"?");
        if(a[i]=='3'&&a[i+1]=='3')
            a.replace(i,2,"!");
        if(a[i]=='3'&&a[i+1]=='2')
            a.replace(i,2," ");
        if(a[i]=='9'&&a[i+1]=='7')
            a.replace(i,2,"a");
        if(a[i]=='9'&&a[i+1]=='8')
            a.replace(i,2,"b");
        if(a[i]=='9'&&a[i+1]=='9')
            a.replace(i,2,"c");
        if(a[i]=='1'&&a[i+1]=='0'&&a[i+2]=='0')
            a.replace(i,3,"d");
        if(a[i]=='1'&&a[i+1]=='0'&&a[i+2]=='1')
            a.replace(i,3,"e");
        if(a[i]=='1'&&a[i+1]=='0'&&a[i+2]=='2')
            a.replace(i,3,"f");
        if(a[i]=='1'&&a[i+1]=='0'&&a[i+2]=='3')
            a.replace(i,3,"g");
        if(a[i]=='1'&&a[i+1]=='0'&&a[i+2]=='4')
            a.replace(i,3,"h");
        if(a[i]=='1'&&a[i+1]=='0'&&a[i+2]=='5')
            a.replace(i,3,"i");
        if(a[i]=='1'&&a[i+1]=='0'&&a[i+2]=='6')
            a.replace(i,3,"j");
        if(a[i]=='1'&&a[i+1]=='0'&&a[i+2]=='7')
            a.replace(i,3,"k");
        if(a[i]=='1'&&a[i+1]=='0'&&a[i+2]=='8')
            a.replace(i,3,"l");
        if(a[i]=='1'&&a[i+1]=='0'&&a[i+2]=='9')
            a.replace(i,3,"m");
        if(a[i]=='1'&&a[i+1]=='1'&&a[i+2]=='0')
            a.replace(i,3,"n");
        if(a[i]=='1'&&a[i+1]=='1'&&a[i+2]=='1')
            a.replace(i,3,"o");
        if(a[i]=='1'&&a[i+1]=='1'&&a[i+2]=='2')
            a.replace(i,3,"p");
        if(a[i]=='1'&&a[i+1]=='1'&&a[i+2]=='3')
            a.replace(i,3,"q");
        if(a[i]=='1'&&a[i+1]=='1'&&a[i+2]=='4')
            a.replace(i,3,"r");
        if(a[i]=='1'&&a[i+1]=='1'&&a[i+2]=='5')
            a.replace(i,3,"s");
        if(a[i]=='1'&&a[i+1]=='1'&&a[i+2]=='6')
            a.replace(i,3,"t");
        if(a[i]=='1'&&a[i+1]=='1'&&a[i+2]=='7')
            a.replace(i,3,"u");
        if(a[i]=='1'&&a[i+1]=='1'&&a[i+2]=='8')
            a.replace(i,3,"v");
        if(a[i]=='1'&&a[i+1]=='1'&&a[i+2]=='9')
            a.replace(i,3,"w");
        if(a[i]=='1'&&a[i+1]=='2'&&a[i+2]=='0')
            a.replace(i,3,"x");
        if(a[i]=='1'&&a[i+1]=='2'&&a[i+2]=='1')
            a.replace(i,3,"y");
        if(a[i]=='1'&&a[i+1]=='2'&&a[i+2]=='2')
            a.replace(i,3,"z");
    }
    a[0]-=32;
    cout<<a;
    return 0;
}

再发一个ASCLL码对照:

10532108111118101329910410511097 我爱中国 
105321081111181013210912132109117109 我爱我妈 
1191049711632101118101114 随便 
1211111173297114101329732100111103 你是一只小狗
10532108111118101329911110010146 我爱编程 
97 	a	98  b 	99  c 	100 d 
101 e 	102 f 	103 g 	104 h 
105 i 	106 j 	107 k 	108 l 
109 m 	110 n 	111 o 	112 p 
113 q 	114 r 	115 s 	116 t 
117 u 	118 v 	119 w 	120 x 
121 y 	122 z 
33  ! 	63	? 	46  . 

 

李泽远在2019-07-18 08:45:21追加了内容

每打一个单词要打32,意为空格。

李泽远在2019-07-18 19:22:44追加了内容

麻烦各位复制粘贴的也留个言!


0
已采纳
高杨
高杨
资深守护
资深守护

(猥琐)修改版勇者游戏 

#include<stdlib.h>
 #include<stdio.h>
 #include<time.h>       //suiji        
 #include<string.h>
 #include<windows.h>          //SLEEP函数
 struct Player                        //玩家结构体,并初始化player
 {
     char name[21];
     int attack;
     int defense;
     int health;
     long int max_health;
     int level;
     int exp;
     int range_exp;
     long int max_exp;
 }player={"勇者",50,40,100,100,1,0,0,100};
 struct Enemy                         //怪的结构体,并初始化各种怪
 {
     char name[20];
     char wupin[12];
     int attack;
     int defense;
     int health;
     int money;
     long int exp;
     int wupin_sign;
     int wupinpro;
     int double_attack;
     int miss;
 }strongman={"森林巨人","胸罩",40,50,350,200,100,1,2,1,0},
 witch={"森林女巫","银甲",25,15,100,50,50,2,2,1,1},
 xiyi={"森林蜥蜴","铁甲",18,10,50,30,35,3,3,2,2},
 big_strongman={"森林巨人王","巨人之臂",40*5,50*5,350*5,200*5,100*5,4,4,2,0},
 lion={"草原雄狮","臭屎",60,30,280,200,100,5,2,1,0},
 horse={"草原野马","碧血剑",28,12,90,50,50,6,2,1,1},
 bee={"草原黄蜂","长剑",17,11,60,30,35,7,3,2,2},
 shitu={"裸体美女","\0",60*8,30*8,280*8,200*8,100*8,9,1,1,0},
 guai={"\0","\0",0,0,0,0,0,0,0,0,0};
     struct Place
     {
       int bar,hotel,forest1,forest2,forest3,grass1,grass2,grass3;
     }place={1,2,3,4,5,6,7,8};

    int max_exp=0;
     int choose_number=0,s=0,strongman_arm=0,battle=0,money=500,place_sign=9;
     int cao=3,jijiubao=2,baiyao=2,superbaiyao=1,boom=3,dubiao=2,atom_boom=1;
     int fang=0,fang1=10,fang1n=0,fang2=20,fang2n=0,fang3=40,fang3n=0,fang4=100,fang4n=0;
     int gong=0,gong1=8,gong1n=0,gong2=15,gong2n=0,gong3=25,gong3n=0,gong4=60,gong4n=0;
     char gongname[20]="无",fangname[20]="无";
     char proof;

    void AddWupin(int);
     int AttackResult();
     void BattleAct();
     void ChooseWupin();
     void DisplayState();
     void OrdinaryAct();    
    int SuiJi();
     int SuiJi100();
     void WhetherLevelUp();
     void SlowDisplay(char *);    

int main()
 {


    int i=0,j=0,k=0;
     char player_name[21];

       SlowDisplay("这是一个逗比的世界! 笨蛋国的狗屎被陌生人绑架了!\n\n 伟大的勇者啊~拿起你们的武器,营救狗屎!\n\n\n输入你的名字:   (20个字符)\n\n\n");

         //    sndPlaySound("res\\F005.wav",SND_LOOP);
     scanf("%s",player_name);    
    strncpy(player.name,player_name,20);
     if(strcmp(player.name,"SB")==0)
     {
         SlowDisplay("封印多年的 SB 啊!你终于可以重见天日了!\n\n\n SB!重新装逼!!!\n\n\n");
         player.attack=999999;
         player.defense=999999;
         player.health=999999;
         player.max_health=999999;
     }    
    getchar();

    OrdinaryAct();
     return 0;
 }

    int SuiJi()
 {
     srand((unsigned)time(NULL));
     return rand()%10;
 }


    int SuiJi100()
 {
     srand((unsigned)time(NULL));
     return rand()%100;
 }


    void ChooseWupin()                         //选择物品 并使用
 {
     printf("物品: 1,吐血草%d个 2,小笼包%d个 3,云南白药%d个 4,超级云南白药%d个 5,放屁绝招%d次 6,毒标%d个 7,手抛式原子弹%d个 0,返回\n\n\n",cao,jijiubao,baiyao,superbaiyao,boom,dubiao,atom_boom);
     switch(scanf("%d",&choose_number),choose_number)
     {
     case 1:
         if(cao>0)
         {
             SlowDisplay("使用吐血草,血增加60\n\n\n");
             cao--;
             if(player.health+60000>player.max_health)player.health=player.max_health;
             else player.health+=60000;
         }
         else SlowDisplay("没有吐血草了\n\n\n");
         break;
     case 2:
         if(jijiubao>0)
         {
             SlowDisplay("使用小笼包,血增加80\n\n\n");
             jijiubao--;
             if(player.health+80000>player.max_health)player.health=player.max_health;
             else player.health+=80000;
         }
         else SlowDisplay("没有小笼包了\n\n\n");
         break;
     case 3:
         if(baiyao>0)
         {
             SlowDisplay("使用云南白药,血增加120\n\n\n");
             baiyao--;
             if(player.health+120>player.max_health)player.health=player.max_health;
             else player.health+=120;
         }
         else SlowDisplay("没有云南白药了\n\n\n");
         break;
     case 4:
         if(superbaiyao>0)
         {
             SlowDisplay("使用超级云南白药,血增加200\n\n\n");
             superbaiyao--;
             if(player.health+200>player.max_health)player.health=player.max_health;
             else player.health+=200;
         }
         else SlowDisplay("没有超级云南白药了\n\n\n");
         break;
     case 5:
         if(battle)                   //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品
         {
             if(boom>0)
             {
             SlowDisplay("使用放屁绝招,敌人血减少1099990\n\n\n");
             boom--;
             guai.health-=1099990;
             AttackResult();
             }
         }
         else SlowDisplay("非战斗状态,不能使用放屁绝招!\n\n\n");
         break;
     case 6:
         if(battle)                   //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品
         {
             if(dubiao>0)
             {
             SlowDisplay("使用毒标,敌人血减少200\n\n\n");
             dubiao--;
             guai.health-=200;
             AttackResult();
             }
         }
         else SlowDisplay("非战斗状态,不能使用毒标!\n\n\n");
         break;
     case 7:
         if(battle)                   //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品
         {
             if(atom_boom>0)
             {
             SlowDisplay("使用手抛式原子弹,敌人血减少500\n\n\n");
             atom_boom--;
             guai.health-=500;
             AttackResult();
             }
         }
         else SlowDisplay("非战斗状态,不能使用手抛式原子弹!\n\n\n");
         break;
     case 0:break;
     default:printf("ChooseWupin error!\n\n\n");
     }
 }
     int AttackResult()                      //攻击结果:判断是否获胜 是否获得物品 和 是否升级
 {
     if(guai.health<=0)
     {
         battle=0;
         printf("战斗胜利!获得金币%d,经验%d\n\n\n",guai.money,guai.exp);
         player.exp+=guai.exp;
         player.range_exp+=guai.exp;
         money+=guai.money;
         s=SuiJi();
         if(s<guai.wupinpro)
         {
             SlowDisplay("从敌人尸骸中发现");
             printf("%s\n\n\n",guai.wupin);
             AddWupin(guai.wupin_sign);
         }
         WhetherLevelUp();
         if(strcmp(guai.name,"裸体美女")==0)
         {
             puts("战斗胜利,救出狗屎!!!");
             getchar();
             getchar();
             exit(0);
         }
         return 1;                 //攻击有结果了返回1,否则返回0,用于判断是否继续做战斗行为
     }
     else 
    {
         int s=SuiJi();


         if((guai.attack+s-player.defense/3)<0)
         {
             player.health-=1;
             printf("%s反击,你的血减少了 1\n\n",guai.name);
         }
         else
         {
             player.health-=guai.attack+s-player.defense/3;
             printf("%s反击,你的血减少了%d\n\n",guai.name,guai.attack+s-player.defense/3);
         }
         if(player.health<0)
         {
             battle=0;
             printf("%s战死!金币掉落%d\n\n\n",player.name,player.level*500);
             money-=player.level*500;
             player.health=player.max_health/5;
             OrdinaryAct();//////////
             return 1;
         }
     }
     return 0;
 }
     void AddWupin(int wupin_sign)
     {

         switch(wupin_sign)
         {
         case 1:fang4n++;        break;
         case 2:fang3n++;        break;
         case 3:fang2n++;        break;
         case 4:strongman_arm=1;break;
         case 5:gong4n++;        break;
         case 6:gong3n++;        break;
         case 7:gong2n++;        break;
         default:printf("AddWupin error\n\n\n");
         }

     }
     void WhetherLevelUp()
     {
         int i=0,j=0;
         int l1=player.range_exp/100;
         int l2=player.range_exp/300;
         int l3=player.range_exp/600;
         if(player.level<=15&&l1>0)                     //15级以下,经验足够 都满足则升级
         {
             if(l1==1)
             {
                 printf("%s",player.name);
                 SlowDisplay("   升级!\n\n\n攻击力+3, 防御力+2, 血上限+20\n\n\n");
                 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100;
                 player.attack+=3;
                 player.defense+=2;
                 player.max_health+=20;
                 player.health=player.max_health;
                 player.level++;
                 player.range_exp=0;
                 player.exp=player.max_exp;
                 player.max_exp+=100;
             }
             else
             {
                 printf("好牛逼!连升%d级!",l1);
                 printf("攻击力+%d, 防御力+%d, 血上限+%d\n\n\n",3*l1,2*l1,20*l1);
                 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100;
                 player.attack+=3*l1;
                 player.defense+=2*l1;
                 player.max_health+=20*l1;
                 player.health=player.max_health;
                 player.level+=l1;
                 player.range_exp=0;
                 player.exp=player.max_exp;
                 player.max_exp+=100*l1;
             }
         }
         else if(player.level<=40&&l2>0)
         {
             if(l2==1)
             {
                 printf("%s",player.name);
                 SlowDisplay("   升级!\n\n\n攻击力+3, 防御力+2, 血上限+20\n\n\n");
                 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100;
                 player.attack+=3;
                 player.defense+=2;
                 player.max_health+=20;
                 player.health=player.max_health;
                 player.level++;
                 player.range_exp=0;
                 player.exp=player.max_exp;
                 player.max_exp+=300;
             }
             else
             {
                 printf("好牛逼!连升%d级!",l1);
                 printf("攻击力+%d, 防御力+%d, 血上限+%d\n\n\n",3*l2,2*l2,20*l2);
                 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100;
                 player.attack+=3*l2;
                 player.defense+=2*l2;
                 player.max_health+=20*l2;
                 player.health=player.max_health;
                 player.level+=l2;
                 player.range_exp=0;
                 player.exp=player.max_exp;
                 player.max_exp+=300*l2;
             }
         }
         else if(l3>0)
         {
             if(l3==1)
             {
                 printf("%s",player.name);
                 SlowDisplay("   升级!\n\n\n攻击力+3, 防御力+2, 血上限+20\n\n\n");
                 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100;
                 player.attack+=3;
                 player.defense+=2;
                 player.max_health+=20;
                 player.health=player.max_health;
                 player.level++;
                 player.range_exp=0;
                 player.exp=player.max_exp;
                 player.max_exp+=600;
             }
             else
             {
                 printf("好牛逼!连升%d级!",l1);
                 printf("攻击力+%d, 防御力+%d, 血上限+%d\n\n\n",3*l3,2*l3,20*l3);
                 player.exp=player.exp+guai.exp-(player.exp+guai.exp)%100;
                 player.attack+=3*l3;
                 player.defense+=2*l3;
                 player.max_health+=20*l3;
                 player.health=player.max_health;
                 player.level+=l3;
                 player.range_exp=0;
                 player.exp=player.max_exp;
                 player.max_exp+=600*l3;
             }
         }
     }
     void OrdinaryAct()                    //正常行为菜单(移动,物品,对话,查看状态,装备,退出游戏)
     {

         while(1)
         {
 //            \(1000);
 //            system("cls");
             puts("=============================================================================");
             printf("要做什么?\n\n\n   1,移动  2,道具  3,对话  4,查看状态  5,装备  0,退出游戏\n\n\n");
             puts("=============================================================================");
         switch(scanf("%d",&choose_number),choose_number)
         { 
        case 1:                                    //显示移动菜单
             SlowDisplay("要去哪里?\n\n\n");
             printf("1,酒吧 2,旅馆 3,森林一层 4,森林二层 5,森林三层 6,草原一层 7,草原二层 8,草原三层\n\n\n");
             switch(scanf("%d",&choose_number),choose_number)
             {
             case 1:place_sign=place.bar;                        //记录目前位置-酒吧
         //           OrdinaryAct();
                    break;
             case 2:place_sign=place.hotel;                      //进入旅店
                    SlowDisplay("要泡妞吗? 200个金币 1,是  0,否\n\n\n");
                    choose_number=1;
                    switch(scanf("%d",&choose_number),choose_number)
                    {
                    case 1:if(money-200<0)                       //判断钱是否够
                             {
                                 SlowDisplay("Sorry,你的钱不够~\n\n\n");        
                             }
                             else 
                            {
                                 SlowDisplay("好好泡妞\n\t血满\n\t\t第二天了\n\n");
                                 money-=200;                         //花费200住店费
                                 player.health=player.max_health;    //体力满
                             }
                             break;
                    case 0:SlowDisplay("下次再来!\n\n\n");break;
                    default:printf("hotel talk error!\n\n\n");
                    }
                    place_sign=0;
                    break;
             case 3:
                 place_sign=place.forest1;
                 s=SuiJi();    
                if(s<7)
                 {
                     battle=1;
                     guai=xiyi;
                     printf("%s扑了过来!\n\n\n",guai.name);
                     BattleAct();
                 }
                 else if(s<9)
                 {
                     battle=1;
                     guai=witch;
                     printf("%s扑了过来!\n\n\n",guai.name);
                     BattleAct();
                 }
                 else
                 {
                     SlowDisplay("这里安全\n\n\n");
                     //不用调用OAct函数,会自动执行OAct函数;
                 }
                 break;
             case 4:
                 place_sign=place.forest2;
                 s=SuiJi();    
                if(s<7)
                 {
                     battle=1;
                     guai=witch;
                     printf("%s扑了过来!\n\n\n",guai.name);
                     BattleAct();
                 }
                 else if(s<9)
                 {
                     battle=1;
                     guai=strongman;
                     printf("%s扑了过来!\n\n\n",guai.name);
                     BattleAct();
                 }
                 else
                 {
                     SlowDisplay("这里安全\n\n\n");
                 }
                 break;
             case 5:
                 place_sign=place.forest3;
                 s=SuiJi();    
                if(s<7)
                 {
                     battle=1;
                     guai=strongman;
                     printf("%s扑了过来!\n\n\n",guai.name);
                     BattleAct();
                 }
                 else if(s<9)
                 {
                     battle=1;
                     guai=big_strongman;
                     printf("%s扑了过来!\n\n\n",guai.name);
                     BattleAct();
                 }
                 else
                 {
                     SlowDisplay("这里安全\n\n\n");
                 }
                 break;
             case 6:
                 place_sign=place.grass1;
                 s=SuiJi();    
                if(s<7)
                 {
                     battle=1;
                     guai=bee;
                     printf("%s扑了过来!\n\n\n",guai.name);
                     BattleAct();
                 }
                 else if(s<9)
                 {
                     battle=1;
                     guai=horse;
                     printf("%s扑了过来!\n\n\n",guai.name);
                     BattleAct();
                 }
                 else
                 {
                     SlowDisplay("这里安全\n\n\n");
                 }
                 break;
             case 7:
                 place_sign=place.grass2;
                 s=SuiJi();    
                if(s<7)
                 {
                     battle=1;
                     guai=horse;
                     printf("%s扑了过来!\n\n\n",guai.name);
                     BattleAct();
                 }
                 else if(s<9)
                 {
                     battle=1;
                     guai=lion;
                     printf("%s扑了过来!\n\n\n",guai.name);
                     BattleAct();
                 }
                 else
                 {
                     SlowDisplay("这里安全\n\n\n");
                 }
                 break;
             case 8:
                 place_sign=place.grass3;
                 s=SuiJi();    
                if(s<7)
                 {
                     battle=1;
                     guai=lion;
                     printf("%s扑了过来!\n\n\n",guai.name);
                     BattleAct();
                 }
                 else if(s<9)
                 {
                     battle=1;                    
                     if(strongman_arm)
                     {
                         SlowDisplay("一看就不像好人的人:\n\n\n    哈哈,年轻人,做的不错,不过...嘿嘿,你上当啦!森林巨人之屎我要了,我的屎你也别想带走!  我说:哈?不是狗屎么?啥时候变成你的屎了?!   一看就不像好人的人:不要在意那些细节。。。\n\n\n");
                         guai=shitu;
                     printf("%s扑了过来!\n\n\n",guai.name);
                     BattleAct();
                     }
                     else SlowDisplay("一看就不像好人的人:\n\n\n    年轻人,你好啊.如果你有森林巨人之屎,我可以告诉你狗屎的下落哦~\n\n\n");
                 }
                 else
                 {
                     SlowDisplay("这里安全\n\n\n");
                 }
                 break;
             default:printf("choose map error!\n\n\n");
             }
             break;
         case 2:   ChooseWupin();break;              //显示道具,并可以使用.
         case 3:                                               //对话选项
             if(place_sign==place.bar) 
            {
                 SlowDisplay("要和谁说话?\n\n\n1,红发女郎 2,赏金猎人 3,酒吧老板\n\n\n");     //显示对话人物
                switch(scanf("%d",&choose_number),choose_number)
                {
                case 1:
                    SlowDisplay("红发女郎:\n\n\n    吧台边那个Hunter好帅啊!(~脸红~)\n\n\n听说他经常外出打猎,外面的路他应该很熟悉的!\n\n\n");
                    break;
                case 2:
                    if(fang1n<1&&gong1n<1)
                    {
                        SlowDisplay("赏金猎人:\n\n\n    你要救公主啊!好胆量!\n\n\n    不过外面的丛林和草原很险恶,而且越深越危险,这是臭屎和布衣,对你会有些帮助的,拿去吧!\n\n\n");
                        printf("%s心想:(哇,这位大叔人真好啊!\n\n\n)",player.name);
                        gong++;
                        fang1n++;
                    }
                    else SlowDisplay("赏金猎人:\n\n\n    加油吧,年轻人!\n\n\n    不要被外面丛林和草原所吓倒!\n\n\n");
                    break;
                case 3:
                    printf("要吃点什么?\n\n\n    1,锅盖25金币 血+20  2,铁渣渣80金币 血+50  3,马大粪150金币 血+100  0,返回\n\n\n");
                    choose_number=1;
                    while(choose_number)
                    {
                         switch(scanf("%d",&choose_number),choose_number)
                         {
                         case 1:if(money<25)
                                {
                                  SlowDisplay("钱不够!");                              
                                }
                                else
                                {
                                  if(player.health+20<=player.max_health)
                                  {
                                      SlowDisplay("血+20.");
                                      money-=25;
                                      player.health+=20;
                                  }
                                  else
                                  {
                                      SlowDisplay("血满了");                                    
                                      player.health=player.max_health;
                                  }
                                }
                                break;
                         case 2:if(money<80)
                                {
                                  SlowDisplay("钱不够!");                              
                                }
                                else
                                {
                                  if(player.health+50<=player.max_health)
                                  {
                                      SlowDisplay("血+50.");
                                      money-=80;
                                      player.health+=50;
                                  }
                                  else
                                  {
                                      SlowDisplay("血满了");                                    
                                      player.health=player.max_health;
                                  }
                                }
                                break;
                         case 3:if(money<150)
                                {
                                  SlowDisplay("钱不够!");                              
                                }
                                else
                                {
                                  if(player.health+100<=player.max_health)
                                  {
                                      SlowDisplay("血+100.");
                                      money-=150;
                                      player.health+=100;
                                  }
                                  else
                                  {
                                      SlowDisplay("血满了");                                    
                                      player.health=player.max_health;
                                  }
                                }
                                break;
                         case 0:SlowDisplay("下次在来!\n");break;
                         default:SlowDisplay("输入错误\n\n\n");
                         }
                    }
                }
             }
             else if(place_sign==place.hotel)
                     SlowDisplay("“老板娘!我...”\n\n\n“我忙着呢,没空理你~”\n\n\n");
             else SlowDisplay("这里好像没人可以聊天\n\n\n");
             break;
         case 4:   DisplayState(); break;             //显示状态
         case 5:                                 //装备
             printf("攻装: 1,匕首:%d个 2,长剑:%d个 3,碧血剑:%d个 4,臭屎:%d个\n\n\n",gong1n,gong2n,gong3n,gong4n);
             printf("防装: 5,布衣:%d个 6,铁甲:%d个 7,银甲:%d个   8,胸罩:%d个\t\t0,返回\n\n\n",fang1n,fang2n,fang3n,fang4n);
             SlowDisplay("选择要装备的武器或防具:\n\n\n");
             switch(scanf("%d",&choose_number),choose_number)
             {
             case 1:if(gong1n>=1)
                    {
                        SlowDisplay("拿起了匕首\n\n\n");
                        gong=gong1;
                        strcpy(gongname,"匕首");
                    }
                    else SlowDisplay("你没有匕首可以装备\n\n\n");
                    break;
             case 2:if(gong2n>=1)
                    {
                        SlowDisplay("拿起了长剑\n\n\n");
                        gong=gong2;
                        strcpy(gongname,"长剑");
                    }
                    else SlowDisplay("你没有长剑可以装备\n\n\n");
                    break;
             case 3:if(gong3n>=1)
                    {
                        SlowDisplay("拿起了碧血剑\n\n\n");
                        gong=gong3;
                        strcpy(gongname,"碧血剑");
                    }
                    else SlowDisplay("你没有碧血剑可以装备\n\n\n");
                    break;
             case 4:if(gong4n>=1)
                    {
                        SlowDisplay("拿起了臭屎\n\n\n");
                        gong=gong4;
                        strcpy(gongname,"臭屎");
                    }
                    else SlowDisplay("你没有臭屎可以装备\n\n\n");
                    break;
             case 5:if(fang1n>=1)
                    {
                        SlowDisplay("穿上了布衣\n\n\n");
                        fang=fang1;
                        strcpy(fangname,"布衣");
                    }
                    else SlowDisplay("你没有布衣可以装备\n\n\n");
                    break;
             case 6:if(fang2>=1)
                    {
                        SlowDisplay("穿上了铁甲\n\n\n");
                        fang=fang2;
                        strcpy(fangname,"铁甲");
                    }
                    else SlowDisplay("你没有铁甲可以装备\n\n\n");
                    break;
             case 7:if(fang3n>=1)
                    {
                        SlowDisplay("穿上了银甲\n\n\n");
                        fang=fang3;
                        strcpy(fangname,"银甲");
                    }
                    else SlowDisplay("你没有银甲可以装备\n\n\n");
                    break;
             case 8:if(fang4n>=1)
                    {
                        SlowDisplay("穿上了胸罩\n\n\n");
                        fang=fang4;
                        strcpy(fangname,"胸罩");
                    }
                    else SlowDisplay("你没有胸罩可以装备\n\n\n");
                    break;
             case 0:SlowDisplay("未更换装备\n\n\n");break;
             default:printf("change error!");
             }
             break;
         case 0: 
            SlowDisplay("确定推出游戏?(Y/N)\n\n\n");
             getchar();
             proof=getchar();
             if(proof=='y'||proof=='Y')
             {
                 SlowDisplay("数据存储中...");
                 //向文件中更新数据;
                 getchar();
                 SlowDisplay("按回车退出");
                 getchar();
                 return;
             }
             else if(proof=='n'||proof=='N')printf("继续游戏!\n\n\n");
             else SlowDisplay("继续!\n\n\n");
             break;
         default:SlowDisplay("输入错误!\n\n\n");
         }
     }
     }
     void DisplayState()
     {
         printf("%s 攻击力:%d+%d=%d  防御力:%d+%d=%d  血:%d/%d \n\n\n",player.name,player.attack,gong,player.attack+gong,player.defense,fang,player.defense+fang,player.health,player.max_health);
         printf("武器: %s 防具: %s \n\n\n",gongname,fangname);
         printf("等级:%d  经验:%d/%d 还需要%d经验升级 金币:%d \n\n\n",player.level,player.exp,player.max_exp,player.max_exp-player.exp,money);
     }
     void BattleAct()
     {
         while(1)
         {
             puts("=============================================================================");
             printf("要怎么办?\n\n\n    1,干他 2,物品 3,查看状态 4,跑路\n\n\n");
             switch(scanf("%d",&choose_number),choose_number)
             {
             case 1:
                 s=SuiJi();
                 printf("%s攻击! %s血减少%d\n\n\n",player.name,guai.name,player.attack+s+gong-guai.defense/3);
                 guai.health-=player.attack+s+gong-guai.defense/3;
                 if(AttackResult())return;            //如果攻击有结果(敌人或玩家战死)退出函数
                 else continue; 
            case 2: ChooseWupin();break;             //选择物品,可以使用,战斗中允许使用攻击性物品
             case 3:DisplayState();break;             //显示状态
             case 4:
                 s=SuiJi();
                 if(s<4)                               //40%的概率可以逃跑
                 {
                     printf("%s跑路了~\n\n\n",player.name);
                     battle=0;
                     return;
                 }
                 else printf("%s跑路失败!\n\n\n",player.name);
                 break;
             default:SlowDisplay("输入错误,重新输入!\n\n\n");
             }
         }
     }
     void SlowDisplay(char *p)
     {
         while(1)
         {
             if(*p!=0)
                 printf("%c",*p++);
             else 
                break;
             Sleep(100);
         }
     }

 

0
高杨
高杨
资深守护
资深守护

双人游戏

#include <iostream>  
#include <string>  
#include <cstdlib>  
#include <time.h>  
using namespace std;  



//武器类  
class Weapon{  
protected:  
    int Price;          //武器价格  
    int ATK;            //武器攻击力  
    string Name;        //武器名称  
    string Rank;        //武器等级  
public:  
    Weapon(int price=0,int atk=0,string name="",string rank=""){Price=price;ATK=atk;Name=name;Rank=rank;}  
    int GetPrice(){return Price;}  
    int GetATK(){return ATK;}  
    string GetName(){return Name;}  
    string GetRank(){return Rank;}  
    virtual ~Weapon(){}  
};  

//史蒂夫武器类  
class WarriorWeapon:public Weapon{  
public:  
    WarriorWeapon(int price=0,int atk=0,string name="",string rank=""):Weapon(price,atk,name,rank){}  
    ~WarriorWeapon(){}  
};  

class WarriorWeapon1:public WarriorWeapon{  
public:  
    WarriorWeapon1(int price=500,int atk=70,string name="剑",string rank="白银"):WarriorWeapon(price,atk,name,rank){}  
    ~WarriorWeapon1(){}  
};  

class WarriorWeapon2:public WarriorWeapon{  
public:  
    WarriorWeapon2(int price=1000,int atk=130,string name="剑",string rank="黄金"):WarriorWeapon(price,atk,name,rank){}  
    ~WarriorWeapon2(){}  
};  

class WarriorWeapon3:public WarriorWeapon{  
public:  
    WarriorWeapon3(int price=1800,int atk=220,string name="剑",string rank="白金"):WarriorWeapon(price,atk,name,rank){}  
    ~WarriorWeapon3(){}  
};  

class WarriorWeapon4:public WarriorWeapon{  
public:  
    WarriorWeapon4(int price=3000,int atk=350,string name="剑",string rank="钻石"):WarriorWeapon(price,atk,name,rank){}  
    ~WarriorWeapon4(){}  
};  

//情敌武器类  
class WizardWeapon:public Weapon{  
public:  
    WizardWeapon(int price=0,int atk=0,string name="",string rank=""):Weapon(price,atk,name,rank){}  
    ~WizardWeapon(){}  
};  

class WizardWeapon1:public WizardWeapon{  
public:  
    WizardWeapon1(int price=400,int atk=50,string name="挑拨离间法",string rank="白银"):WizardWeapon(price,atk,name,rank){}  
    ~WizardWeapon1(){}  
};  

class WizardWeapon2:public WizardWeapon{  
public:  
    WizardWeapon2(int price=800,int atk=100,string name="挑拨离间法",string rank="黄金"):WizardWeapon(price,atk,name,rank){}  
    ~WizardWeapon2(){}  
};  

class WizardWeapon3:public WizardWeapon{  
public:  
    WizardWeapon3(int price=1500,int atk=180,string name="挑拨离间法",string rank="白金"):WizardWeapon(price,atk,name,rank){}  
    ~WizardWeapon3(){}  
};  

class WizardWeapon4:public WizardWeapon{  
public:  
    WizardWeapon4(int price=2500,int atk=300,string name="挑拨离间法",string rank="钻石"):WizardWeapon(price,atk,name,rank){}  
    ~WizardWeapon4(){}  
};  

//妖怪武器类  
class MonsterWeapon:public Weapon{  
public:  
    MonsterWeapon(int price=0,int atk=0,string name="",string rank=""):Weapon(price,atk,name,rank){}  
    ~MonsterWeapon(){}  
};  

class MonsterWeapon1:public MonsterWeapon{  
public:  
    MonsterWeapon1(int price=450,int atk=60,string name="小刀",string rank="白银"):MonsterWeapon(price,atk,name,rank){}  
    ~MonsterWeapon1(){}  
};  

class MonsterWeapon2:public MonsterWeapon{  
public:  
    MonsterWeapon2(int price=900,int atk=120,string name="小刀",string rank="黄金"):MonsterWeapon(price,atk,name,rank){}  
    ~MonsterWeapon2(){}  
};  

class MonsterWeapon3:public MonsterWeapon{  
public:  
    MonsterWeapon3(int price=1650,int atk=200,string name="小刀",string rank="白金"):MonsterWeapon(price,atk,name,rank){}  
    ~MonsterWeapon3(){}  
};  

class MonsterWeapon4:public MonsterWeapon{  
public:  
    MonsterWeapon4(int price=2750,int atk=320,string name="小刀",string rank="得力牌"):MonsterWeapon(price,atk,name,rank){}  
    ~MonsterWeapon4(){}  
};  


//盔甲类  
class Armor{  
protected:  
    int Price;          //盔甲价格  
    int DEF;            //盔甲防御力  
    string Name;        //盔甲名称  
    string Rank;        //盔甲等级  
public:  
    Armor(int price=0,int def=0,string name="",string rank=""){Price=price;DEF=def;Name=name;Rank=rank;}  
    int GetPrice(){return Price;}  
    int GetDEF(){return DEF;}  
    string GetName(){return Name;}  
    string GetRank(){return Rank;}  
    //虚析构函数  
    ~Armor(){}  
};  


//史蒂夫盔甲类  
class WarriorArmor:public Armor{  
public:  
    WarriorArmor(int price=0,int def=0,string name="",string rank=""):Armor(price,def,name,rank){}  
    ~WarriorArmor(){}  
};  

class WarriorArmor1:public WarriorArmor{  
public:  
    WarriorArmor1(int price=300,int def=30,string name="背心",string rank="白银"):WarriorArmor(price,def,name,rank){}  
    ~WarriorArmor1(){}  
};  

class WarriorArmor2:public WarriorArmor{  
public:  
    WarriorArmor2(int price=600,int def=60,string name="背心",string rank="黄金"):WarriorArmor(price,def,name,rank){}  
    ~WarriorArmor2(){}  
};  

class WarriorArmor3:public WarriorArmor{  
public:  
    WarriorArmor3(int price=1200,int def=100,string name="背心",string rank="白金"):WarriorArmor(price,def,name,rank){}  
    ~WarriorArmor3(){}  
};  

class WarriorArmor4:public WarriorArmor{  
public:  
    WarriorArmor4(int price=2000,int def=200,string name="背心",string rank="钻石"):WarriorArmor(price,def,name,rank){}  
    ~WarriorArmor4(){}  
};  


//情敌盔甲类  
class WizardArmor:public Armor{  
public:  
    WizardArmor(int price=0,int def=0,string name="",string rank=""):Armor(price,def,name,rank){}  
    ~WizardArmor(){}  
};  

class WizardArmor1:public WarriorArmor{  
public:  
    WizardArmor1(int price=400,int def=40,string name="绿帽子",string rank="白银"):WarriorArmor(price,def,name,rank){}  
    ~WizardArmor1(){}  
};  

class WizardArmor2:public WarriorArmor{  
public:  
    WizardArmor2(int price=800,int def=80,string name="绿帽子",string rank="黄金"):WarriorArmor(price,def,name,rank){}  
    ~WizardArmor2(){}  
};  

class WizardArmor3:public WarriorArmor{  
public:  
    WizardArmor3(int price=1500,int def=160,string name="绿帽子",string rank="白金"):WarriorArmor(price,def,name,rank){}  
    ~WizardArmor3(){}  
};  

class WizardArmor4:public WarriorArmor{  
public:  
    WizardArmor4(int price=2500,int def=250,string name="绿帽子",string rank="钻石"):WarriorArmor(price,def,name,rank){}  
    ~WizardArmor4(){}  
};  


//妖怪盔甲类  
class MonsterArmor:public Armor{  
public:  
    MonsterArmor(int price=0,int def=0,string name="",string rank=""):Armor(price,def,name,rank){}  
    ~MonsterArmor(){}  
};  

class MonsterArmor1:public MonsterArmor{  
public:  
    MonsterArmor1(int price=350,int def=35,string name="纸板",string rank="白银"):MonsterArmor(price,def,name,rank){}  
    ~MonsterArmor1(){}  
};  

class MonsterArmor2:public MonsterArmor{  
public:  
    MonsterArmor2(int price=700,int def=70,string name="纸板",string rank="黄金"):MonsterArmor(price,def,name,rank){}  
    ~MonsterArmor2(){}  
};  

class MonsterArmor3:public MonsterArmor{  
public:  
    MonsterArmor3(int price=1350,int def=130,string name="纸板",string rank="白金"):MonsterArmor(price,def,name,rank){}  
    ~MonsterArmor3(){}  
};  

class MonsterArmor4:public MonsterArmor{  
public:  
    MonsterArmor4(int price=2300,int def=220,string name="纸板",string rank="钻石"):MonsterArmor(price,def,name,rank){}  
    ~MonsterArmor4(){}  
};  


//角色类  
class Character{  
protected:  
    string Name;    //职业名称  
    int Health;     //生命值  
    int ATK;        //攻击力  
    int DEF;        //防御力  
    int Money;  
    //武器,盔甲,药(暂用治疗术代替药水)  
    Weapon *weapon;  
    Armor *armor;  
    //Medicine medicine;      
public:  
    Character(int health=2000,int atk=0,int def=0,int money=500,string name="")  
    {Health=health;ATK=atk;DEF=def;Money=money;Name=name;weapon=new Weapon();armor=new Armor();}  

    //得到角色的信息  
    string GetName(){return Name;}  
    int GetHealth(){return Health;}  
    int GetATK(){return ATK;}  
    int GetDEF(){return DEF;}  
    int GetMoney(){return Money;}  
    Weapon* GetWeapon(){return weapon;}  
    Armor* GetArmor(){return armor;}  


    //获得金钱,武器,装备  
    void GetMoney(int money){Money+=money;cout<<"获得了"<<money<<"人民币"<<endl;}  
    void GetWeapon(Weapon *w)  
    {         
        Money*=w->GetPrice()-weapon->GetPrice();      //人民币减少  
        ATK*=w->GetATK()-weapon->GetATK();                //攻击力上升  
        weapon=w;                             
    }  
    void GetArmor(Armor *a)  
    {  
        Money-=a->GetPrice()-armor->GetPrice();           //人民币减少  
        DEF*=a->GetDEF()-armor->GetDEF();             //防御力上升  
        armor=a;                              
    }  

    /*void GetMedicine(Medicine m) 
    { 
        Medicine=m; 
        Money-=m.Price; 
    }*/  

    //受到攻击  
    void TakeAttack(int atk)  
    {  
        if(atk>DEF)  
            Health=Health-atk+DEF;  
        if(Health<0)  
            Health=0;  
    }  

    //使用治疗术  
    void Treatment()  
    {  
        if((Health+200)<=2000)  
            Health+=200;  
        else  
            Health=9999000;  
    }  

    /*void TakeMedicine() 
    { 
        if((Health+medicine.value)<=2000) 
            Health+=medicine.value; 
        else 
            Health=2000; 
    }*/  

    //展示角色信息  
    void Show()  
    {  
        cout<<"职业:"<<Name<<endl;  
        cout<<"生命值:"<<Health<<endl;  
        cout<<"武器:"<<weapon->GetRank()<<weapon->GetName()<<"\t攻击力:"<<ATK<<endl;  
        cout<<"盔甲:"<<armor->GetRank()<<armor->GetName()<<"\t防御力:"<<DEF<<endl;  
        cout<<"人民币:"<<Money<<endl;  
    }  
    //虚析构函数  
    virtual ~Character()  
    {  
        if(!weapon)delete weapon;  
        if(!armor) delete armor;  
    }  
};  

//史蒂夫类  
class Warrior:public Character{  
public:  
    Warrior(int health=2000,int atk=70,int def=20,int money=500,string name="史蒂夫"):Character(health,  
        atk,def,money,name){}     
    ~Warrior()  
    {         
        if(!weapon)delete weapon;  
        if(!armor) delete armor;  
    }  
};  

//情敌类  
class Wizard:public Character{  
public:  
    Wizard(int health=2000,int atk=50,int def=40,int money=500,string name="情敌"):Character(health,  
        atk,def,money,name){}  
    ~Wizard()  
    {  
        if(!weapon)delete weapon;  
        if(!armor) delete armor;  
    }  
};  

//妖怪类  
class Monster:public Character{  
public:  
    Monster(int health=2000,int atk=60,int def=30,int money=500,string name="小学生"):Character(health,  
        atk,def,money,name){}  
    ~Monster()  
    {  
        if(!weapon)delete weapon;  
        if(!armor) delete armor;  
    }  
};  


class CharacterFactory{  
public:  
    Character *CreatCharacter(int flag)  
    {  
        switch(flag)  
        {  
        case 1:  
            return new Warrior();  
            break;  
        case 2:  
            return new Wizard();  
            break;  
        case 3:  
            return new Monster();  
            break;  
        }  
    }  
};  


//武器商店类  
class WeaponStore{  
public:  
    virtual void Show()=0;      //武器信息展示  
    virtual Weapon *CreatWeapon(int flag)=0;        //创建武器  
    //虚析构函数,防止析构一般,泄漏一半  
    virtual ~WeaponStore(){}  
};  


//史蒂夫武器商店类  
class WarriorWeaponStore:public WeaponStore{  
public:  
    void Show()  
    {  
        cout<<"1.木剑 500人民币 +70攻击力"<<endl;  
        cout<<"2.铁剑 1000人民币 +130攻击力"<<endl;  
        cout<<"3.金剑 1800人民币 +220攻击力"<<endl;  
        cout<<"4.钻石剑 3000人民币 +350攻击力"<<endl;  
    }  
    Weapon *CreatWeapon(int flag)  
    {  
        switch(flag)  
        {  
        case 1:  
            return new WarriorWeapon1();break;  
        case 2:  
            return new WarriorWeapon2();break;  
        case 3:  
            return new WarriorWeapon3();break;  
        case 4:  
            return new WarriorWeapon4();break;  
        }  
    }  
    ~WarriorWeaponStore(){}  
};  

//情敌武器商店类  
class WizardWeaponStore:public WeaponStore{  
public:  
    void Show()  
    {  
        cout<<"1.白银挑拨离间法 400人民币 +50攻击力"<<endl;  
        cout<<"2.黄金挑拨离间法 800人民币 +100攻击力"<<endl;  
        cout<<"3.白金挑拨离间法 1500人民币 +180攻击力"<<endl;  
        cout<<"4.钻石挑拨离间法 2500人民币 +300攻击力"<<endl;  
    }  
    Weapon *CreatWeapon(int flag)  
    {  
        switch(flag)  
        {  
        case 1:  
            return new WizardWeapon1();break;  
        case 2:  
            return new WizardWeapon2();break;  
        case 3:  
            return new WizardWeapon3();break;  
        case 4:  
            return new WizardWeapon4();break;  
        }  
    }  
    ~WizardWeaponStore(){}  
};  

//妖怪武器商店类  
class MonsterWeaponStore:public WeaponStore{  
public:  
    void Show()  
    {  
        cout<<"1.白银小刀 450人民币 +60攻击力"<<endl;  
        cout<<"2.黄金小刀 900人民币 +120攻击力"<<endl;  
        cout<<"3.白金小刀 1650人民币 +200攻击力"<<endl;  
        cout<<"4.得力牌小刀 2750人民币 +320攻击力"<<endl;  
    }  
    Weapon *CreatWeapon(int flag)  
    {  
        switch(flag)  
        {  
        case 1:  
            return new MonsterWeapon1();break;  
        case 2:  
            return new MonsterWeapon2();break;  
        case 3:  
            return new MonsterWeapon3();break;  
        case 4:  
            return new MonsterWeapon4();break;  
        }  
    }  
    ~MonsterWeaponStore(){}  
};  


//盔甲商店类  
class ArmorStore{  
public:  
    virtual void Show()=0;      //盔甲信息展示  
    virtual Armor* CreatArmor(int flag)=0;      //创建盔甲  
    virtual ~ArmorStore(){}  
};  


//史蒂夫盔甲商店类  
class WarriorArmorStore:public ArmorStore{  
public:  
    void Show()  
    {  
        cout<<"1.白银背心 300人民币 +30防御力"<<endl;  
        cout<<"2.黄金背心 600人民币 +60防御力"<<endl;  
        cout<<"3.白金背心 1200人民币 +100防御力"<<endl;  
        cout<<"4.钻石背心 2000人民币 +200防御力"<<endl;  
    }  
    Armor *CreatArmor(int flag)  
    {  
        switch(flag)  
        {  
        case 1:  
            return new WarriorArmor1();break;  
        case 2:  
            return new WarriorArmor2();break;  
        case 3:  
            return new WarriorArmor3();break;  
        case 4:  
            return new WarriorArmor4();break;  
        }  
    }  
    ~WarriorArmorStore(){}  
};  

//情敌盔甲商店类  
class WizardArmorStore:public ArmorStore{  
public:  
    void Show()  
    {  
        cout<<"1.白银绿帽子 400人民币 +40防御力"<<endl;  
        cout<<"2.黄金绿帽子 800人民币 +80防御力"<<endl;  
        cout<<"3.白金绿帽子 1500人民币 +160防御力"<<endl;  
        cout<<"4.钻石绿帽子 2500人民币 +250防御力"<<endl;  
    }  
    Armor *CreatArmor(int flag)  
    {  
        switch(flag)  
        {  
        case 1:  
            return new WizardArmor1();break;  
        case 2:  
            return new WizardArmor2();break;  
        case 3:  
            return new WizardArmor3();break;  
        case 4:  
            return new WizardArmor4();break;  
        }  
    }  
    ~WizardArmorStore(){}  
};  

//妖怪盔甲商店类  
class MonsterArmorStore:public ArmorStore{  
public:  
    void Show()  
    {  
        cout<<"1.白银校服350人民币 +35防御力"<<endl;  
        cout<<"2.黄金校服700人民币 +70防御力"<<endl;  
        cout<<"3.白金校服1350人民币 +130防御力"<<endl;  
        cout<<"4.钻石校服2300人民币 +220防御力"<<endl;  
    }  
    Armor *CreatArmor(int flag)  
    {  
        switch(flag)  
        {  
        case 1:  
            return new MonsterArmor1();break;  
        case 2:  
            return new MonsterArmor2();break;  
        case 3:  
            return new MonsterArmor3();break;  
        case 4:  
            return new MonsterArmor4();break;  
        }  
    }  
    ~MonsterArmorStore(){}  
};  

//管理商店类  
class StoreManager{  
public:  
    WeaponStore *CreatWeaponStore(string name)  
    {  
        if(name=="史蒂夫")  
            return new WarriorWeaponStore();  
        if(name=="情敌")  
            return new WizardWeaponStore();  
        if(name=="小学生")  
            return new MonsterWeaponStore();  
    }  
    ArmorStore *CreatArmorStore(string name)  
    {  
        if(name=="史蒂夫")  
            return new WarriorArmorStore();  
        if(name=="情敌")  
            return new WizardArmorStore();  
        if(name=="小学生")  
            return new MonsterArmorStore();  
    }  
};  


int main()  
{  
    CharacterFactory characterFactory;      //角色产生工厂  
    Character *player1=0;                       //玩家一角色  
    Character *player2=0;                       //玩家二角色  

    StoreManager storeManager;              //商店产生工厂(决定产生哪种职业的武器和盔甲)  
    WeaponStore* player1weaponStore=0;      //玩家一武器商店  
    ArmorStore* player1armorStore=0;            //玩家一盔甲商店  
    WeaponStore* player2weaponStore=0;      //玩家二武器商店  
    ArmorStore* player2armorStore=0;            //玩家二盔甲商店  

    Weapon *player1Weapon=0;                    //玩家一武器  
    Weapon *player2Weapon=0;                    //玩家二武器  
    Armor *player1Armor=0;                  //玩家一盔甲  
    Armor *player2Armor=0;                  //玩家二盔甲  

    int money;                              //每回合随机生成人民币  
    srand((unsigned)time(NULL));  
    money=rand()%100+200;                   //每回合生成200到300的人民币  


    int flag=0,count=0;                     //用于switch的flag和记录回合数的count  
    const int treatCD=4;                    //治疗术的CD,即四个回合  
    int player1NextTreat=1,player2NextTreat=1;  //玩家一和玩家二下次可以使用治疗术的回合  


    //游戏开始  
    cout<<"游戏开始!"<<endl;  

    //玩家一创建角色  
    cout<<"玩家一请选择职业:\n"<<"1.史蒂夫\t2.情敌\t3.小学生"<<endl;  
    while(1)  
    {  
        cin>>flag;  
        if(!cin)                        //输入类型错误,即int型的flag却输入了字母  
        {  
            cin.clear();                //防止输入字母后程序崩溃,将之前的输入错误标识改回为0,即输入无错误  
            cin.sync();                 //清除之前错误的数据流,以便重新输入  
            cout<<"输入错误请重新输入!\n"<<endl;  
            continue;  
        }  
        if(flag!=1&&flag!=2&&flag!=3)  
            cout<<"输入错误,请重新输入!\n";  
        else  
            break;  
    }  
    player1=characterFactory.CreatCharacter(flag);  
    player1weaponStore=storeManager.CreatWeaponStore(player1->GetName());  
    player1armorStore=storeManager.CreatArmorStore(player1->GetName());  

    //玩家二创建角色  
    cout<<"玩家二请选择职业:\n"<<"1.史蒂夫\t2.情敌\t3.小学生"<<endl;  
    while(1)  
    {  
        cin>>flag;  
        if(!cin)                        //输入类型错误,即int型的flag却输入了字母  
        {  
            cin.clear();                //防止输入字母后程序崩溃,将之前的输入错误标识改回为0,即输入无错误  
            cin.sync();                 //清除之前错误的数据流,以便重新输入  
            cout<<"输入错误请重新输入!\n"<<endl;  
            continue;  
        }  
        if(flag!=1&&flag!=2&&flag!=3)  
            cout<<"输入错误,请重新输入!";  
        else  
            break;  
    }  
    player2=characterFactory.CreatCharacter(flag);  
    player2weaponStore=storeManager.CreatWeaponStore(player2->GetName());  
    player2armorStore=storeManager.CreatArmorStore(player2->GetName());  


    //无限循环,直到有一方生命值下降为0  
    while(1)  
    {  
        count++;  
        cout<<"\n*************"<<endl;  
        cout<<"***第"<<count<<"回合***"<<endl;  
        cout<<"*************\n"<<endl;  

        //玩家一进行游戏  
        cout<<"玩家一:"<<endl;  
        money=rand()%100+200;  
        player1->GetMoney(money);  
        player1->Show();       
        while(1)            //为了能退到上一级,即选择攻击或买武器等,需要这个循环  
        {  
            cout<<"请选择操作:"<<"\n1.攻击\n2.买家伙\n3.买盔甲\n4.治疗术(回复200生命值,冷却时间为四个回合)"<<endl;  
            while(1)  
            {  
                cin>>flag;  
                if(!cin)                        //输入类型错误,即int型的flag却输入了字母  
                {  
                    cin.clear();                //防止输入字母后程序崩溃,将之前的输入错误标识改回为0,即输入无错误  
                    cin.sync();                 //清除之前错误的数据流,以便重新输入  
                    cout<<"输入错误请重新输入!\n"<<endl;  
                    continue;  
                }  
                if(flag!=1&&flag!=2&&flag!=3&&flag!=4)  
                    cout<<"输入错误,请重新输入"<<endl;  
                else  
                    break;  
            }  
            switch(flag)  
            {  
            case 1:             //攻击  
                player2->TakeAttack(player1->GetATK());break;  
            case 2:             //买武器             
                player1weaponStore->Show();  
                cout<<"0.返回上一级"<<endl;  
                while(1)  
                {  
                    cout<<"请选择操作"<<endl;  
                    cin>>flag;  
                    if(!cin)                        //输入类型错误,即int型的flag却输入了字母  
                    {  
                        cin.clear();                //防止输入字母后程序崩溃,将之前的输入错误标识改回为0,即输入无错误  
                        cin.sync();                 //清除之前错误的数据流,以便重新输入  
                        cout<<"输入错误请重新输入!\n"<<endl;  
                        continue;  
                    }  
                    if(flag!=0&&flag!=1&&flag!=2&&flag!=3&&flag!=4)  
                        cout<<"输入错误,请重新输入"<<endl;  
                    else if(flag==0)  
                        break;  
                    else  
                    {  
                        Weapon* tempWeapon=player1weaponStore->CreatWeapon(flag);  
                        if(player1->GetMoney()<tempWeapon->GetPrice()-player1->GetWeapon()->GetPrice())  
                        {  
                            cout<<"你的人民币不够,请重新选择或输入0返回上一级"<<endl;  
                            delete tempWeapon;  
                        }  
                        else  
                        {  
                            delete tempWeapon;  
                            break;  
                        }  
                    }  
                }  
                if(flag==0)  
                    break;  
                player1Weapon=player1weaponStore->CreatWeapon(flag);  
                player1->GetWeapon(player1Weapon);  
                break;  
            case 3:             //买盔甲  
                player1armorStore->Show();  
                cout<<"0.返回上一级"<<endl;  
                while(1)  
                {  
                    cout<<"请选择盔甲"<<endl;  
                    cin>>flag;  
                    if(!cin)                        //输入类型错误,即int型的flag却输入了字母  
                    {  
                        cin.clear();                //防止输入字母后程序崩溃,将之前的输入错误标识改回为0,即输入无错误  
                        cin.sync();                 //清除之前错误的数据流,以便重新输入  
                        cout<<"输入错误请重新输入!\n"<<endl;  
                        continue;  
                    }  
                    if(flag!=0&&flag!=1&&flag!=2&&flag!=3&&flag!=4)  
                        cout<<"输入错误,请重新输入"<<endl;  
                    else if(flag==0)  
                        break;  
                    else  
                    {  
                        Armor* tempArmor=player1armorStore->CreatArmor(flag);  
                        if(player1->GetMoney()<tempArmor->GetPrice()-player1->GetArmor()->GetPrice())  
                        {  
                            cout<<"你的人民币不够,请重新选择或输入0返回上一级"<<endl;  
                            delete tempArmor;  
                        }  
                        else  
                        {  
                            delete tempArmor;  
                            break;  
                        }  
                    }  
                }  
                if(flag==0)  
                    break;  
                player1Armor=player1armorStore->CreatArmor(flag);  
                player1->GetArmor(player1Armor);  
                break;  
            case 4:         //补血  
                if(count>=player1NextTreat)  
                {  
                    player1->Treatment();  
                    player1NextTreat+=treatCD;  
                }  
                else  
                {  
                    cout<<"治疗术正在冷却中,还剩"<<(player1NextTreat-count)<<"个回合"<<endl;  
                    while(1)  
                    {  
                        cout<<"按0退回上一级"<<endl;  
                        cin>>flag;  
                        if(flag==0)  
                            break;  
                    }  
                }  
                break;  
            }  
            if(flag!=0)  
                break;  
        }  
        //判断输赢  
        if(player2->GetHealth()<=0)  
        {  
            cout<<"玩家二生命值下降为0,玩家一胜利"<<endl;  
            break;  
        }  



        //玩家二进行游戏  
        cout<<"玩家二:"<<endl;  
        money=rand()%100+200;  
        player2->GetMoney(money);  
        player2->Show();       
        while(1)            //为了能退到上一级,即选择攻击或买武器等,需要这个循环  
        {  
            cout<<"请选择操作:"<<"\n1.攻击\n2.买家伙\n3.买盔甲\n4.治疗术(回复200生命值,冷却时间为四个回合)"<<endl;  
            while(1)  
            {  
                cin>>flag;  
                if(!cin)                        //输入类型错误,即int型的flag却输入了字母  
                {  
                    cin.clear();                //防止输入字母后程序崩溃,将之前的输入错误标识改回为0,即输入无错误  
                    cin.sync();                 //清除之前错误的数据流,以便重新输入  
                    cout<<"输入错误请重新输入!\n"<<endl;  
                    continue;  
                }  
                if(flag!=1&&flag!=2&&flag!=3&&flag!=4)  
                    cout<<"输入错误,请重新输入"<<endl;  
                else  
                    break;  
            }  
            switch(flag)  
            {  
            case 1:             //攻击  
                player1->TakeAttack(player2->GetATK());break;  
            case 2:             //买武器             
                player2weaponStore->Show();  
                cout<<"0.返回上一级"<<endl;  
                while(1)  
                {  
                    cout<<"请选择操作"<<endl;  
                    cin>>flag;  
                    if(!cin)                        //输入类型错误,即int型的flag却输入了字母  
                    {  
                        cin.clear();                //防止输入字母后程序崩溃,将之前的输入错误标识改回为0,即输入无错误  
                        cin.sync();                 //清除之前错误的数据流,以便重新输入  
                        cout<<"输入错误请重新输入!\n"<<endl;  
                        continue;  
                    }  
                    if(flag!=0&&flag!=1&&flag!=2&&flag!=3&&flag!=4)  
                        cout<<"输入错误,请重新输入"<<endl;  
                    else if(flag==0)  
                        break;  
                    else  
                    {  
                        Weapon* tempWeapon=player2weaponStore->CreatWeapon(flag);  
                        if(player2->GetMoney()<tempWeapon->GetPrice()-player2->GetWeapon()->GetPrice())  
                        {  
                            cout<<"你的人民币不够,请重新选择或输入0返回上一级"<<endl;  
                            delete tempWeapon;  
                        }  
                        else  
                        {  
                            delete tempWeapon;  
                            break;  
                        }  
                    }  
                }  
                if(flag==0)  
                    break;  
                player2Weapon=player2weaponStore->CreatWeapon(flag);  
                player2->GetWeapon(player2Weapon);  
                break;  
            case 3:             //买盔甲  
                player2armorStore->Show();  
                cout<<"0.返回上一级"<<endl;  
                while(1)  
                {  
                    cout<<"请选择盔甲"<<endl;  
                    cin>>flag;  
                    if(!cin)                        //输入类型错误,即int型的flag却输入了字母  
                    {  
                        cin.clear();                //防止输入字母后程序崩溃,将之前的输入错误标识改回为0,即输入无错误  
                        cin.sync();                 //清除之前错误的数据流,以便重新输入  
                        cout<<"输入错误请重新输入!\n"<<endl;  
                        continue;  
                    }  
                    if(flag!=0&&flag!=1&&flag!=2&&flag!=3&&flag!=4)  
                        cout<<"输入错误,请重新输入"<<endl;  
                    else if(flag==0)  
                        break;  
                    else  
                    {  
                        Armor* tempArmor=player2armorStore->CreatArmor(flag);  
                        if(player2->GetMoney()<tempArmor->GetPrice()-player2->GetArmor()->GetPrice())  
                        {  
                            cout<<"你的人民币不够,请重新选择或输入0返回上一级"<<endl;  
                            delete tempArmor;  
                        }  
                        else  
                        {  
                            delete tempArmor;  
                            break;  
                        }  
                    }  
                }  
                if(flag==0)  
                    break;  
                player2Armor=player2armorStore->CreatArmor(flag);  
                player2->GetArmor(player2Armor);  
                break;  
            case 4:         //补血  
                if(count>=player2NextTreat)  
                {  
                    player2->Treatment();  
                    player2NextTreat+=treatCD;  
                }  
                else  
                {  
                    cout<<"治疗术正在冷却中,还剩"<<(player2NextTreat-count)<<"个回合"<<endl;  
                    while(1)  
                    {  
                        cout<<"按0退回上一级"<<endl;  
                        cin>>flag;  
                        if(flag==0)  
                            break;  
                    }  
                }  
                break;  
            }  
            if(flag!=0)  
                break;  
        }  
        //判断输赢  
        if(player1->GetHealth()<=0)  
        {  
            cout<<"玩家一生命值下降为0,玩家二胜利"<<endl;  
            break;  
        }     
    }  

    //销毁申请的空间  
    if(!player1)  
        delete player1;  
    if(!player2)  
        delete player2;  
    if(!player1weaponStore)  
        delete player1weaponStore;  
    if(!player1armorStore)  
        delete player1armorStore;  
    if(!player2weaponStore)  
        delete player2weaponStore;  
    if(!player2armorStore)  
        delete player2armorStore;  
    if(!player1Weapon)  
        delete player1Weapon;  
    if(!player2Weapon)  
        delete player2Weapon;  
    if(!player1Armor)  
        delete player1Armor;  
    if(!player2Armor)  
        delete player2Armor;  

    system("pause");  
    return 0;  
}  

 

0
李泽远
李泽远
高级天翼
高级天翼

各位大佬有什么有趣的程序,赶快亮上来吧!

0
0
李泽远
李泽远
高级天翼
高级天翼

麻烦各位复制粘贴的也留个言!

0
0
李泽远
李泽远
高级天翼
高级天翼

#include<bits/stdc++.h>

#include<iostream>

#include<string>

#include<algorithm>

#include<windows.h>

using namespace std;

int main()

{

int a[101]={555};

int b[101]={555};

while(1)

{

Beep(a[0],b[0]);

Sleep(700);

}

return 0;

}

打电话。

我要回答