魔兽世界一 备战

第一次写..分了好几个类..希望扩展性强一些

#include <iostream>
using namespace std;
string WarriorType[5] = {"dragon","ninja","iceman","lion","wolf"};//dragon,ninja,iceman,lion,wolf
int redOrder[6] = {0,3,4,5,2,1};
int blueOrder[6] = {0,4,1,2,3,5};
int _i = 1,_j = 1;
int openingNo = 0;
int warriorHP[6];
int minHp;

class Warrior{
public:
    int hp;
    int id;
    int type;//1d,2n,3i,4l,5w
    Warrior(){}
    Warrior(int _hp,int _id,int _type):hp(_hp),id(_id),type(_type){}
};

class HeadQuarter{
public:
    int mana;
    int redNo = 0;
    int blueNo = 0;
    string HQtype;
    bool isOver = 0;
    HeadQuarter(){};
    HeadQuarter(int _mana,string _type){
        mana = _mana;
        HQtype = _type;
    }
    int warriorCount[6] = {0};


    void SpawnFunc(string _HQtype){

        if(isOver)return;
        if(mana<minHp){
            isOver = 1;
            printf("%03d ",openingNo);
            cout <<_HQtype<<" headquarter stops making warriors\n";
            return;
        }
        if(HQtype == "RED"){
            for(;;){
                int i = _i;
                if(i >5){
                    i%=5;
                    if(i==0)i=5;
                }
                if(warriorHP[redOrder[i]]>mana) {
                    ++_i;
                    continue;
                }

                else{
                    Warrior troop(warriorHP[redOrder[i]],++redNo,redOrder[i]);
                    //cout << i<< _i<<endl;
                    printf("%03d red %s %d born with strength %d,%d %s in red headquarter\n",openingNo,
                           WarriorType[troop.type-1].c_str(),redNo,warriorHP[troop.type],
                           ++warriorCount[troop.type],WarriorType[troop.type-1].c_str());

                    ++_i;
                    mana-=troop.hp;
                    //cout << "Current RED mana:"<<mana<<endl;
                   // cout << "Current RED minHP:"<<minHp<<endl;
                    break;
            }
            }
        }
        else{
            for(;;){
                int j = _j;
                if(j >5){
                    j%=5;
                    if(j==0)j=5;
                };

                if(warriorHP[blueOrder[j]]>mana){
                    ++_j;
                    continue;
                }
                else{
                    Warrior troop(warriorHP[blueOrder[j]],++blueNo,blueOrder[j]);
                   // cout << j <<_j<<endl;
                    printf("%03d blue %s %d born with strength %d,%d %s in blue headquarter\n",openingNo,
                           WarriorType[troop.type-1].c_str(),blueNo,warriorHP[troop.type],
                           ++warriorCount[troop.type],WarriorType[troop.type-1].c_str());

                    ++_j;
                    mana-=troop.hp;
                   //cout << "Current BLUE mana:"<<mana<<endl;
                    break;
                }
            }
        }
    }

};

class Game {
public:
   int M;
    HeadQuarter RED,BLUE;
    void reset(){
        _i = _j =1;
        openingNo = 0;

    }
    void GameStart(){
       RED.HQtype = "RED";BLUE.HQtype ="BLUE";
        while(true){
            if(RED.isOver&&BLUE.isOver)break;
            RED.SpawnFunc("red");
            BLUE.SpawnFunc("blue");
            openingNo++;
      }
    }
    void initHQ(){
        cin>>M;
        RED.mana = BLUE.mana = M;
    }
    void initWarrior(){
        for(int i = 1;i<=5;i++){
            cin>>warriorHP[i];
        }
        minHp = 10000;
        for(int i = 1;i<=5;i++){
            if(warriorHP[i]<minHp){
                minHp = warriorHP[i];
            }
        }
    }
};

int main(){

        int t;
        cin >> t;
        for(int i = 0; i < t; i++){
            Game game;
            game.reset();
            cout<<"Case:"<<i+1<<endl;
            game.initHQ();
            game.initWarrior();
            game.GameStart();
        }
        return  0;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值