zoukankan      html  css  js  c++  java
  • 魔兽2:装备

      1 #include <bits/stdc++.h>
      2 using namespace std;
      3 int dragon=0,ninja=0,iceman=0,lion=0,wolf=0;
      4 int N;
      5 int life;
      6 class HQ{
      7 public:
      8     char * color;
      9     int working=1;
     10     int life;
     11     int cp=0;                                               //目前造到哪一个小兵,SEQUENCE中的下标
     12     int sub=1;                                              // 小兵的下标
     13 
     14     char* na[5]={"dragon","ninja","iceman","lion","wolf"};  //小兵名字
     15     char* we[3]={"sword","bomb","arrow"};
     16     int sequence[5];                                        //造兵顺序
     17     int con[5];                                             //造每个兵的消耗
     18     int num[5]={0,0,0,0,0};                                             //每种小兵的数量
     19 
     20     HQ(int a[5],char *c){
     21         memcpy(sequence,a,5*sizeof(int));
     22         color=new char[10];
     23         strcpy(color,c);
     24     }
     25     void init(int a,int b,int c,int d,int e){
     26         con[0]=a;con[1]=b;con[2]=c;con[3]=d;con[4]=e;
     27     }
     28     void reset(){
     29         working=1;
     30         for(int i=0;i<5;i++)
     31             num[i]=0;
     32         cp=0;
     33         sub=1;
     34     }
     35 
     36     void stop(){
     37         if(!working){
     38             cout<<color<<" headquarter stops making warriors"<<endl;
     39         }
     40     }
     41     void weapon(){
     42         if(sequence[cp]==4)
     43             return;
     44         else if(sequence[cp]==3){
     45             cout<<"It's loyalty is "<<life<<endl;
     46             return;
     47         }
     48         else if(sequence[cp]==0){
     49             cout<<"It has a "<<we[sub%3]<<",and it's morale is ";
     50             printf("%.2f
    ",(float)life/con[sequence[cp]]);
     51             return;
     52         }
     53         else if(sequence[cp]==1) {
     54             cout << "It has a " << we[sub % 3] << " and a "<< we[(sub + 1) % 3]<<endl;
     55             return;
     56         }
     57         else if(sequence[cp]==2){
     58             cout<<"It has a "<<we[sub%3]<<endl;
     59         }
     60 
     61     }
     62     void making(){
     63         if(!working)
     64             return;
     65         int j;
     66         for(j=1;j<=5;j++){
     67             if(life>=con[sequence[cp]]){
     68                 num[sequence[cp]]++;
     69                 cout<<color<<" "<<na[sequence[cp]]<<" "<<sub<<" "<<"born with strength "<<con[sequence[cp]];
     70                 cout<<','<<num[sequence[cp]]<<' '<<na[sequence[cp]]<<" in "<<color<<" headquarter"<<endl;
     71                 life-=con[sequence[cp]];
     72                 weapon();
     73 
     74                 cp=(cp+1)%5;
     75                 sub++;
     76                 break;
     77             }
     78             cp=(cp+1)%5;
     79 
     80         }
     81         if(j==6){
     82             working=0;
     83             stop();
     84         }
     85     }
     86 };
     87 
     88 
     89 
     90 int main() {
     91     int a[5]={2,3,4,1,0};
     92     int b[5]={3,0,1,2,4};
     93     HQ red(a,"red"),blue(b,"blue");
     94 
     95     cin>>N;
     96     for(int i=1;i<=N;i++){
     97         red.reset();
     98         blue.reset();
     99         cin>>life;
    100         red.life=life;
    101         blue.life=life;
    102 
    103         cin>>dragon>>ninja>>iceman>>lion>>wolf;
    104         red.init(dragon,ninja,iceman,lion,wolf);
    105         blue.init(dragon,ninja,iceman,lion,wolf);
    106 
    107         cout<<"Case:"<<i<<endl;
    108         for(int j=0;;j++){
    109             if(red.working){
    110                 printf("%03d ",j);
    111                 red.making();
    112             }
    113             if(blue.working){
    114                 printf("%03d ",j);
    115                 blue.making();
    116             }
    117 
    118 
    119             if(!red.working&&!blue.working)
    120                 break;
    121         }
    122     }
    123     return 0;
    124 }

     好像还挺好玩的??

  • 相关阅读:
    git pull fatal: refusing to merge unrelated histories
    Git报错:Your branch is ahead of 'origin/master' by 1 commit
    java读取大文件内容到Elasticsearch分析(手把手教你java处理超大csv文件)
    Java try catch语句块中try()的括号中代码作用
    Redis这15个“雷坑”,别问我咋知道的……
    MySql死锁
    MQ限流应用
    什么是 JWT -- JSON WEB TOKEN
    mybatis-plus查询指定字段
    数据库炸了----我就重启了一下啊(Communications link failure)
  • 原文地址:https://www.cnblogs.com/maskoff/p/8627481.html
Copyright © 2011-2022 走看看