魔獸世界之一 備戰

2021-08-27 03:53:20 字數 2290 閱讀 6306

自己的**:

#include#include#includeusing namespace std;

#define num 5//使用const int更好

class warror;

class headqurater;//類的定義要寫在前面

class warror;

class headqurater;

warror::warror( headqurater *h1, int nowarror1, int no1);

void warror::print(int t);

void headqurater::init(int color1, int power1, int rule1, bool stop1);

void headqurater::print( int t);

bool headqurater::isend( );

int headqurater::produce( int t, int ptr);

if(power < warror::life[a]) return -1;

};string warror::name[num] = ;//靜態變數後面定義不需要加 static

int warror::life[num] = ;

int rule1[num] = ;

int rule2[num] = ;

int main();

};if(signr == 1) ;

};if( !blue.isend( ));

};if( signb == 1) ;

};t++;

};}; return 0;

};

老師的**:

#include #include #include using namespace std;

const int warrior_num = 5;

/*string warrior::names[warrior_num] = ;

紅方司令部按照 iceman、lion、wolf、ninja、dragon 的順序製造武士。

藍方司令部按照 lion、dragon、ninja、iceman、wolf 的順序製造武士。*/

class headquarter;

class warrior;

class headquarter;

warrior::warrior( headquarter * p,int no_,int kindno_ )

void warrior::printresult(int ntime)

void headquarter::init(int color_, int lv)

headquarter::~headquarter ()

int headquarter::produce(int ntime)

int kindno = ******seq[color][cur******seqidx];

if( warrior::initiallifevalue[kindno] > totallifevalue )

//製作士兵:

totallifevalue -= warrior::initiallifevalue[kindno];

cur******seqidx = ( cur******seqidx + 1 ) % warrior_num;

pwarriors[totalwarriornum] = new warrior( this,totalwarriornum+1,kindno);

warriornum[kindno]++;

pwarriors[totalwarriornum]->printresult(ntime);

totalwarriornum++;

return 1;}

string headquarter::getcolor()

string warrior::names[warrior_num] = ;

int warrior::initiallifevalue [warrior_num];

int headquarter::******seq[2][warrior_num] = , }; //兩個司令部武士的製作順序序列

int main()

} return 0;

}

總結:老師的**類分的很清晰,儘量減少main函式中的操作,而自己在這一塊做的不是很好,這個是主要的問題,其他的在**中已經標出來了。string中的c_str( )函式的使用方法和介紹:

魔獸世界之一 備戰

原題 題目描述 魔獸世界的西面是紅魔軍的司令部,東面是藍魔軍的司令部。兩個司令部之間是依次排列的若干城市。紅司令部,city 1,city 2,city n,藍司令部 兩軍的司令部都會製造武士。武士一共有 dragon ninja iceman lion wolf 五種。每種武士都有編號 生命值 攻...

Cousera作業 魔獸世界之一 備戰

樣例輸入 1 203 4 5 6 7 樣例輸出 case 1 000 red iceman 1 born with strength 5,1 iceman in red headquarter 000 blue lion 1 born with strength 6,1 lion in blue h...

北大MOOC第三週 005 魔獸世界之一 備戰

題目描述 include include include include includeusing namespace std typedef mapstrintmap static strintmap strength mapstrength 14 30 16 30 class warcraft ...