作业6-魔兽3
我真的真的有必要单独为魔兽三写一个随笔!!!!!!!!
呜呜呜呜呜 暴风哭泣
22个小时,真的濒临崩溃,终于!!!
史诗级的时刻!!!!
我要把代码贴在这里:
1 #define _CRT_SECURE_NO_WARNINGS 2 // 魔兽世界3.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 3 // erase的用法!删了之后就不能再移下标了!! 4 //缴获武器啊!!!!!!!!!!!!!!!!!!!!! 5 #include<iostream> 6 #include<string> 7 #include<cmath> 8 #include<cstring> 9 #include<cstdio> 10 #include<vector> 11 #include<algorithm> 12 using namespace std; 13 //武士一共有 dragon 、ninja、iceman、lion、wolf 五种。每种武士都有编号、生命值、攻击力这三种属性 14 //红方司令部按照iceman、lion、wolf、ninja、dragon的顺序循环制造武士。 15 //蓝方司令部按照lion、dragon、ninja、iceman、wolf的顺序循环制造武士。 16 //编程规范:变量名中间字母大写,类名、函数名首字母大写 17 //莫名其妙的问题看看循环的下标是不是写错了! 18 const int interval[7] = { 5, 5, 25, 5, 10, 5, 5 }; 19 int t, M, N, K, T; 20 int win; 21 22 class Command; //复合关系 23 24 class weapon { 25 protected: 26 int dura;//能用的次数 27 int a_on_enemy; 28 int a_on_user; 29 int per_aoe;//攻击力的百分之多少 30 int per_aou;//对使用者的伤害值是百分之多少 31 int id; //为0或1或2 32 public: 33 weapon() { id = -1; a_on_enemy = 0; a_on_user = 0; dura = 0; per_aoe = 0; per_aou = 0; } 34 weapon(int dura, int per_aoe, int per_aou, int user_attack, int id) { 35 this->dura = dura; 36 this->id = id; 37 this->per_aoe = per_aoe; 38 this->per_aou = per_aou; 39 cal_attack(user_attack); 40 } 41 void cal_attack(int user_attack) { //user_attack是攻击力 42 a_on_enemy = (int)(floor((double)user_attack * this->per_aoe / 10)); 43 a_on_user = (int)(floor((double)a_on_enemy * this->per_aou / 10)); 44 } 45 int get_aoe() { return a_on_enemy; }; 46 int get_aou() { return a_on_user; } 47 int get_d() const { return dura; } 48 int get_id() const { return id; } 49 void damage() { --dura; } 50 friend class Soldier; 51 }; 52 53 class sword : public weapon { 54 public: 55 sword() : weapon() {} 56 sword(int user_attack) : weapon(100000000, 2, 0, user_attack, 0) {} 57 }; 58 59 class bomb : public weapon { 60 public: 61 bomb() : weapon() {} 62 bomb(int user_attack, bool isninja) : weapon(1, 4, isninja ? 0 : 5, user_attack, 1) {}//ninja使用炸弹不受伤 63 }; 64 65 class arrow : public weapon { 66 public: 67 arrow() : weapon() {} 68 arrow(int user_attack) : weapon(2, 3, 0, user_attack, 2) {} 69 }; 70 71 bool cmp1(const weapon& t, const weapon& a) { //用于战斗前的排序 72 if (t.get_id() == a.get_id()) return t.get_d() < a.get_d(); 73 else return t.get_id() < a.get_id(); 74 } 75 76 bool cmp2(const weapon& t, const weapon& a) { //用于wolf抢武器 77 if (t.get_id() == a.get_id()) return t.get_d() > a.get_d();//优先拿使用次数多的武器 78 else return t.get_id() < a.get_id(); 79 } 80 81 class Soldier { //武士 82 protected: 83 Command* com; //属于哪个司令部 84 int kind; //是哪种武士 85 int id; //编号 86 int health;//生命值 87 int attack; //攻击力 88 int curcity; //当前所在城市 89 int loyalty; //士气(狮子独有) 90 vector<weapon>weapon_list; //武器名单 91 public: 92 Soldier(Command* p, int kindd, int idd); 93 static weapon new_weapon(int type, int ori_attack, string user_name) { 94 if (type == 0) return sword(ori_attack); 95 if (type == 1 && user_name == "ninja") return bomb(ori_attack, true); 96 if (type == 1 && user_name != "ninja") return bomb(ori_attack, false); 97 return arrow(ori_attack); 98 } 99 void Print(int time); 100 void PrintInfo() { //狮子诞生 101 printf("Its loyalty is %d\n", loyalty); 102 } 103 104 static int life[5]; //生命值 105 static string weaponname[3]; //新加武器 106 static string name[5]; //dragon 、ninja、iceman、lion、wolf 107 static int attacklist[5]; //攻击力 108 109 110 int& get_curcity() { return curcity; } 111 int& get_loyalty() { return loyalty; } 112 int get_id() const { return id; } 113 int& get_health() { return health; } 114 int get_kind() const { return kind; } 115 int get_attack() const { return this->attack; } 116 int get_first_weapon_id() const { //第一个武器的id 117 if (weapon_list.size() == 0) return -1; 118 return this->weapon_list[0].get_id(); 119 } 120 int get_weapon_num() const { return this->weapon_list.size(); } //武器有几件 121 int get_full_weapon_status() { //每种武器各有多少件,并压缩成一个数 122 int num_sword = 0, num_bomb = 0, num_arrow = 0; 123 for (int i = 0; i < weapon_list.size(); i++) { 124 if (weapon_list[i].get_id() == 0) num_sword++; 125 if (weapon_list[i].get_id() == 1) num_bomb++; 126 if (weapon_list[i].get_id() == 2) num_arrow++; 127 } 128 return num_sword * 10000 + num_bomb * 100 + num_arrow; //压缩成一个数 129 } 130 131 bool launch_attack(int temp, Soldier* a) {//用第几个武器攻击谁,返回值是有没有删掉武器 132 if (weapon_list[temp].id == 1) {//如果是炸弹 133 if (kind == 1) weapon_list[temp].per_aou = 0; 134 else weapon_list[temp].per_aou = 5; 135 } 136 weapon_list[temp].cal_attack(attack); //要更新武器攻击力 137 a->health -= weapon_list[temp].get_aoe(); 138 this->health -= weapon_list[temp].get_aou(); 139 weapon_list[temp].damage(); 140 vector<weapon>::iterator itr = weapon_list.begin() + temp; 141 if (weapon_list[temp].get_d() <= 0) { 142 itr = weapon_list.erase(itr); 143 return true; 144 } 145 return false; 146 } 147 148 friend class City; 149 }; 150 151 class Command { //司令部 152 private: 153 Soldier* mySoldier[1000]; //都有哪些士兵 154 int HP; //总血量 155 int color; //蓝方为1, 红方为0 156 int sNum[5]; //存放每种士兵的数量 157 int curID; //当前制造到了第curID个士兵 158 int curkind; //当前制造的种类(用在该颜色的order里是第几个表示,即相对编号) 159 bool flag; //用来记录生命值用完了没有 160 public: 161 static int order[2][5]; //制造顺序 162 void Init(int col, int life); 163 bool Creat(int time); 164 ~Command(); 165 string get_color() { 166 if (color == 0) return "red"; 167 else return "blue"; 168 } 169 void Match(int time) {//行军 170 for (int i = 1; i < curID; i++) { 171 if (mySoldier[i] == NULL) continue; //因为有狮子会逃走,所以会出现空指针 172 if (mySoldier[i]->get_health() <= 0) {//清理牺牲士兵 173 delete mySoldier[i]; 174 mySoldier[i] = NULL; 175 continue; 176 } 177 if (mySoldier[i]->get_kind() == 3) { //如果是狮子 178 mySoldier[i]->get_loyalty() -= K; 179 } 180 if (mySoldier[i]->get_kind() == 2) { //如果是iceman 181 mySoldier[i]->get_health() -= floor(mySoldier[i]->get_health() * 0.1); 182 } 183 if (color == 0 && mySoldier[i]->get_curcity() < N + 1) { 184 mySoldier[i]->get_curcity()++; 185 if (mySoldier[i]->get_curcity() == N + 1) win = color; //赢了 186 } 187 else if (color == 1 && mySoldier[i]->get_curcity() > 0) { 188 mySoldier[i]->get_curcity()--; 189 if (mySoldier[i]->get_curcity() == 0) win = color;//赢了 190 } 191 } 192 193 } 194 195 void Escape(int time) { 196 for (int i = 1; i < curID; i++) { 197 if (mySoldier[i] == NULL) continue; 198 if (mySoldier[i]->get_kind() == 3 && mySoldier[i]->get_loyalty() <= 0) { 199 printf("%03d:05 %s %s %d ran away\n", 200 time, get_color().c_str(), Soldier::name[mySoldier[i]->get_kind()].c_str(), mySoldier[i]->get_id()); 201 //从城市中删掉狮子 202 delete mySoldier[i]; 203 mySoldier[i] = NULL; 204 } 205 } 206 } 207 208 void SentSoldier(); //送士兵到城市 209 210 int get_HP() { return this->HP; } 211 friend class Soldier; //友元关系不可继承 212 friend class Dragon; 213 friend class Lion; 214 friend class City; 215 }; 216 217 class Dragon : public Soldier { 218 double morale; //降生后其司令部剩余生命元的数量除以造dragon所需的生命元数量 219 public: 220 Dragon(Command* p, int kindd, int idd) :Soldier(p, kindd, idd), morale((double(p->HP) - Soldier::life[kindd]) / life[0]) { 221 weapon_list.push_back(new_weapon(id % 3, attack, "dragon")); 222 } 223 224 void Printinfo() { 225 printf("It has a %s,and it's morale is %.2lf\n", weaponname[id % 3].c_str(), morale); 226 } 227 }; 228 229 class Ninja : public Soldier { 230 public: 231 Ninja(Command* p, int kindd, int idd) :Soldier(p, kindd, idd) { 232 weapon_list.push_back(new_weapon(id % 3, attack, "ninja")); 233 weapon_list.push_back(new_weapon((id + 1) % 3, attack, "ninja")); 234 } 235 void Printinfo() { 236 printf("It has a %s and a %s\n", weaponname[id % 3].c_str(), weaponname[(id + 1) % 3].c_str()); 237 } 238 }; 239 240 class Iceman : public Soldier { 241 public: 242 Iceman(Command* p, int kindd, int idd) :Soldier(p, kindd, idd) { 243 weapon_list.push_back(new_weapon(id % 3, attack, "iceman")); 244 } 245 void Printinfo() { 246 printf("It has a %s\n", weaponname[id % 3].c_str()); 247 } 248 }; 249 250 class Lion : public Soldier { 251 public: 252 Lion(Command* p, int kindd, int idd) :Soldier(p, kindd, idd) { 253 loyalty = p->HP - Soldier::life[kindd]; 254 weapon_list.push_back(new_weapon(id % 3, attack, "lion")); 255 } 256 }; 257 258 class Wolf : public Soldier { 259 public: 260 Wolf(Command* p, int kindd, int idd) :Soldier(p, kindd, idd) {} 261 }; 262 263 class City { 264 public: 265 int id; 266 Soldier* red; 267 Soldier* blue; 268 public: 269 City(int idd = -1) { 270 id = idd; 271 red = NULL; 272 blue = NULL; 273 } 274 void wolf_grab_weapon(int time) {//抢对方武器 wolf是kind4 275 if (red == NULL || blue == NULL)return; 276 if (red->get_kind() == 4 && blue->get_kind() != 4) { 277 if (!(blue->weapon_list.empty())) { 278 sort(blue->weapon_list.begin(), blue->weapon_list.end(), cmp2); 279 int minid = blue->weapon_list[0].get_id(); // 最小的武器编号 280 int count = red->weapon_list.size();//狼可能已经拥有武器了! 281 int i = 0; 282 vector<weapon>::iterator itc = blue->weapon_list.begin(); 283 while (count < 10 && !blue->weapon_list.empty()) { //最多拿十个武器 284 if (blue->weapon_list[0].get_id() != minid) break; 285 red->weapon_list.push_back(blue->weapon_list[0]); 286 itc = blue->weapon_list.erase(itc); 287 count++; i++; 288 } 289 //000:35 blue wolf 2 took 3 bomb from red dragon 2 in city 4 290 printf("%03d:35 red wolf %d took %d %s from blue %s %d in city %d\n", 291 time, red->get_id(), i, Soldier::weaponname[minid].c_str(), Soldier::name[blue->get_kind()].c_str(), blue->get_id(), id); 292 } 293 } 294 else if (blue->get_kind() == 4 && red->get_kind() != 4) { 295 if (!(red->weapon_list.empty())) { 296 sort(red->weapon_list.begin(), red->weapon_list.end(), cmp2); 297 int minid = red->weapon_list[0].get_id(); // 最小的武器编号 298 int count = blue->weapon_list.size();//狼可能已经拥有武器了! 299 int i = 0; 300 vector<weapon>::iterator itc = red->weapon_list.begin(); 301 while (count < 10 && !red->weapon_list.empty()) { //最多拿十个武器 302 if (red->weapon_list[0].get_id() != minid) break; 303 blue->weapon_list.push_back(red->weapon_list[0]); 304 itc = red->weapon_list.erase(itc); 305 count++; 306 i++; 307 } 308 printf("%03d:35 blue wolf %d took %d %s from red %s %d in city %d\n", 309 time, blue->get_id(), i, Soldier::weaponname[minid].c_str(), Soldier::name[red->get_kind()].c_str(), red->get_id(), id); 310 } 311 } 312 } 313 void grab_weapon(Soldier* a, Soldier* b) { //a把b的武器拿走 314 sort(b->weapon_list.begin(), b->weapon_list.end(), cmp2); 315 while (a->weapon_list.size() < 10 && !b->weapon_list.empty()) { 316 a->weapon_list.push_back(b->weapon_list.back()); 317 b->weapon_list.pop_back(); 318 } 319 } 320 void Battle(int time) { 321 if (red == NULL || blue == NULL) return; 322 if(!red->weapon_list.empty()) sort(red->weapon_list.begin(), red->weapon_list.end(), cmp1); 323 if(!blue->weapon_list.empty()) sort(blue->weapon_list.begin(), blue->weapon_list.end(), cmp1); 324 Soldier* first; 325 Soldier* second; 326 if (id % 2 == 1) { 327 first = red; second = blue; 328 } 329 else { 330 first = blue; second = red; 331 } 332 int first_weapon = 0, second_weapon = 0; 333 int win = -1; 334 bool flag = false; 335 int times = 0; //循环太多轮自动视作平局 336 while (times < 100 && (!first->weapon_list.empty() || !second->weapon_list.empty())) { 337 times++; 338 if (!first->weapon_list.empty()) { 339 flag = first->launch_attack(first_weapon, second); //有没有删掉武器 340 if (second->get_health() <= 0 && first->get_health() > 0)win = 1; 341 else if (second->get_health() <= 0 && first->get_health() <= 0) win = 0; 342 else if (second->get_health() > 0 && first->get_health() <= 0) win = 2; 343 } 344 if (!first->weapon_list.empty() && flag == false) { 345 first_weapon = (first_weapon + 1) % first->weapon_list.size(); 346 } 347 if (first_weapon == first->weapon_list.size()) {//如果是最后一个武器删掉了,那么下标需要直接移到开头 348 first_weapon = 0; 349 } 350 if (win == -1) { //如果没结束那就换sec打fir 351 if (!second->weapon_list.empty()) { 352 flag = second->launch_attack(second_weapon, first); //有没有删掉武器 353 if (first->get_health() <= 0 && second->get_health() > 0) win = 2; 354 else if (second->get_health() <= 0 && first->get_health() <= 0) win = 0; 355 else if (first->get_health() > 0 && second->get_health() <= 0) win = 1; 356 } 357 if (!second->weapon_list.empty() && flag == false) { 358 second_weapon = (second_weapon + 1) % second->weapon_list.size(); 359 } 360 if (second_weapon == second->weapon_list.size()) {//如果是最后一个武器删掉了,那么下标需要直接移到开头 361 second_weapon = 0; 362 } 363 } 364 //输出结果 365 if (win == 1) {//000:40 red iceman 1 killed blue lion 12 in city 2 remaining 20 elements 366 printf("%03d:40 %s %s %d killed %s %s %d in city %d remaining %d elements\n", time, first->com->get_color().c_str(), 367 Soldier::name[first->get_kind()].c_str(), first->get_id(), second->com->get_color().c_str(), 368 Soldier::name[second->get_kind()].c_str(), second->get_id(), id, first->get_health()); 369 grab_weapon(first, second); 370 if (red == second)red = NULL; if (blue == second)blue = NULL; 371 Yell(time); 372 return; 373 } 374 else if (win == 2) { 375 printf("%03d:40 %s %s %d killed %s %s %d in city %d remaining %d elements\n", time, second->com->get_color().c_str(), 376 Soldier::name[second->get_kind()].c_str(), second->get_id(), first->com->get_color().c_str(), 377 Soldier::name[first->get_kind()].c_str(), first->get_id(), id, second->get_health()); 378 grab_weapon(second, first); 379 if (red == first)red = NULL; if (blue == first)blue = NULL; 380 Yell(time); 381 return; 382 } 383 else if (win == 0) {//000:40 both red iceman 1 and blue lion 12 died in city 2 384 printf("%03d:40 both red %s %d and blue %s %d died in city %d\n", time, Soldier::name[red->get_kind()].c_str(), 385 red->get_id(), Soldier::name[blue->get_kind()].c_str(), blue->get_id(), id); 386 red = NULL; blue = NULL; 387 return; 388 } 389 } 390 //000:40 both red iceman 1 and blue lion 12 were alive in city 2 391 printf("%03d:40 both red %s %d and blue %s %d were alive in city %d\n", time, Soldier::name[red->get_kind()].c_str(), 392 red->get_id(), Soldier::name[blue->get_kind()].c_str(), blue->get_id(), id); 393 Yell(time); 394 } 395 void Yell(int time) { 396 if (red!=NULL&&red->kind == 0) {//003:40 blue dragon 2 yelled in city 4 397 printf("%03d:40 red dragon %d yelled in city %d\n", time, red->id, id); 398 } 399 if (blue != NULL && blue->kind == 0) {//003:40 blue dragon 2 yelled in city 4 400 printf("%03d:40 blue dragon %d yelled in city %d\n", time, blue->id, id); 401 } 402 } 403 void report_status(int time) { 404 if (red!=NULL) {//000:55 blue wolf 2 has 2 sword 3 bomb 0 arrow and 7 elements 405 printf("%03d:55 red ", time); 406 printf("%s %d has ", Soldier::name[red->get_kind()].c_str(),red->get_id()); 407 int full_weapon_status = red->get_full_weapon_status(); 408 int num_arrow = full_weapon_status % 100; full_weapon_status /= 100; 409 int num_bomb = full_weapon_status % 100; full_weapon_status /= 100; 410 int num_sword = full_weapon_status; 411 printf("%d sword %d bomb %d arrow and %d elements\n", num_sword, num_bomb, num_arrow, red->get_health()); 412 } 413 if (blue!=NULL) {//000:55 blue wolf 2 has 2 sword 3 bomb 0 arrow and 7 elements 414 printf("%03d:55 blue ", time); 415 printf("%s %d has ", Soldier::name[blue->get_kind()].c_str(), blue->get_id()); 416 int full_weapon_status = blue->get_full_weapon_status(); 417 int num_arrow = full_weapon_status % 100; full_weapon_status /= 100; 418 int num_bomb = full_weapon_status % 100; full_weapon_status /= 100; 419 int num_sword = full_weapon_status; 420 printf("%d sword %d bomb %d arrow and %d elements\n", num_sword, num_bomb, num_arrow, blue->get_health()); 421 } 422 } 423 424 friend class Command; 425 friend class Soldier; 426 }; 427 428 429 string Soldier::name[5] = { "dragon","ninja","iceman","lion","wolf" }; 430 int Soldier::life[5]; 431 int Soldier::attacklist[5]; 432 string Soldier::weaponname[3] = { "sword", "bomb", "arrow" };//编号分别为0,1,2 433 int Command::order[2][5] = { {2,3,4,1,0},{3,0,1,2,4} }; 434 vector<City>cities; 435 436 437 Soldier::Soldier(Command* p, int kindd, int idd) { //哪一方/士兵类型/id 438 com = p; 439 kind = kindd; 440 id = idd; 441 if (kindd != 3) 442 loyalty = 0; 443 else loyalty = p->HP - life[kindd]; 444 health = life[kindd]; 445 attack = attacklist[kindd]; 446 curcity = -1; 447 } 448 449 void Soldier::Print(int time) { 450 string color = "red"; 451 if (com->color == 1) color = "blue"; //char字符串可以直接用=初始化,但不能这么赋值 452 else color = "red"; 453 printf("%03d:00 %s %s %d born\n", 454 time, color.c_str(), name[kind].c_str(), id); 455 } 456 457 void Command::Init(int col, int life) { //初始化 458 color = col; 459 HP = life; 460 flag = false; 461 curID = 1; 462 curkind = 0; 463 for (int i = 0; i < 1000; i++) 464 mySoldier[i] = NULL; 465 memset(sNum, 0, sizeof(sNum)); 466 } 467 468 //string Soldier::name[5]={"dragon","ninja","iceman","lion","wolf"}; 469 bool Command::Creat(int time) { 470 if (flag) return false; //已经不能再造了 471 int i, kind; 472 kind = order[color][curkind]; //这里是绝对编号 473 if (Soldier::life[kind] > HP) return false; 474 switch (kind) { //case里不能定义局部变量,除非加作用域符号{} 475 case 0: 476 {mySoldier[curID] = new Dragon(this, kind, curID); break; } 477 case 1: 478 {mySoldier[curID] = new Ninja(this, kind, curID); break; } 479 case 2: 480 {mySoldier[curID] = new Iceman(this, kind, curID); break; } 481 case 3: 482 {mySoldier[curID] = new Lion(this, kind, curID); break; } 483 case 4: 484 {mySoldier[curID] = new Wolf(this, kind, curID); break; } 485 } 486 mySoldier[curID]->get_curcity() = (color == 0 ? 0 : N + 1); //确定是在哪个大本营里 487 sNum[kind]++; 488 HP -= Soldier::life[kind]; 489 mySoldier[curID]->Print(time); 490 if (kind == 3)mySoldier[curID]->PrintInfo(); 491 //各种序号要+1 492 curkind = (curkind + 1) % 5; 493 curID++; 494 return true; 495 } 496 497 void Command::SentSoldier() { //把士兵到城市 498 for (int i = 1; i < curID; i++) { 499 if (mySoldier[i] != NULL) { 500 if (color == 0) { 501 cities[mySoldier[i]->get_curcity()].red = mySoldier[i]; 502 } 503 else cities[mySoldier[i]->get_curcity()].blue = mySoldier[i]; 504 } 505 } 506 //000:10 red iceman 1 marched to city 1 with 20 elements and force 30 507 } 508 509 Command::~Command() { 510 for (int i = 1; i < curID; i++) 511 delete mySoldier[i]; 512 } 513 514 515 int main() { 516 Command Blue, Red; 517 scanf("%d", &t); 518 for (int casetime = 1; casetime <= t; casetime++) { 519 printf("Case %d:\n", casetime); 520 scanf("%d %d %d %d", &M, &N, &K, &T); 521 win = -1; //谁都没赢呢 522 Blue.Init(1, M); 523 Red.Init(0, M); 524 for (int j = 0; j <= 4; j++) 525 scanf("%d", &Soldier::life[j]); 526 for (int j = 0; j <= 4; j++) 527 scanf("%d", &Soldier::attacklist[j]); 528 int time = 0; 529 for (int j = 0; j <= N + 1; j++) 530 cities.push_back(City(j)); 531 532 for (int timing = 0, con = 0, hour = -1; timing <= T; timing += interval[con], con = (con + 1) % 7) { 533 if (win != -1) break; 534 if (con == 0)hour++; 535 if (con == 0) { 536 bool flagred = Red.Creat(hour); 537 bool flagblue = Blue.Creat(hour); 538 } 539 if (con == 1) { 540 Red.Escape(hour); 541 Blue.Escape(hour); 542 } 543 if (con == 2) { 544 Red.Match(hour); 545 Blue.Match(hour); 546 for (int i = 0; i < cities.size(); i++) { //先把所有指针都清空 547 cities[i].red = NULL; cities[i].blue = NULL; 548 } 549 Red.SentSoldier(); 550 Blue.SentSoldier(); 551 if (cities[0].blue != NULL) {//001:10 red iceman 1 reached blue headquarter with 20 elements and force 30 552 printf("%03d:10 blue %s %d reached red headquarter with %d elements and force %d\n", hour, 553 Soldier::name[cities[0].blue->get_kind()].c_str(), cities[0].blue->get_id(), 554 cities[0].blue->get_health(), cities[0].blue->get_attack()); 555 printf("%03d:10 red headquarter was taken\n", hour); 556 win = 1; 557 } 558 for (int i = 1; i < cities.size()-1; i++) { //要按城市顺序输出 559 if (cities[i].red != NULL) { 560 printf("%03d:10 red %s %d marched to city %d with %d elements and force %d\n", hour, 561 Soldier::name[cities[i].red->get_kind()].c_str(), cities[i].red->get_id(), cities[i].red->get_curcity(), 562 cities[i].red->get_health(), cities[i].red->get_attack()); 563 } 564 if (cities[i].blue != NULL) { 565 printf("%03d:10 blue %s %d marched to city %d with %d elements and force %d\n", hour, 566 Soldier::name[cities[i].blue->get_kind()].c_str(), cities[i].blue->get_id(), cities[i].blue->get_curcity(), 567 cities[i].blue->get_health(), cities[i].blue->get_attack()); 568 } 569 } 570 if (cities[N+1].red != NULL) {//001:10 red iceman 1 reached blue headquarter with 20 elements and force 30 571 printf("%03d:10 red %s %d reached blue headquarter with %d elements and force %d\n", hour, 572 Soldier::name[cities[N+1].red->get_kind()].c_str(), cities[N+1].red->get_id(), 573 cities[N+1].red->get_health(), cities[N+1].red->get_attack()); 574 printf("%03d:10 blue headquarter was taken\n", hour); 575 win = 1; 576 } 577 if (win == 1) break; 578 } 579 if (con == 3) { 580 for (int i = 0; i <= N + 1; i++) 581 cities[i].wolf_grab_weapon(hour); 582 } 583 if (con == 4) { 584 for (int i = 1; i <= N; i++) { 585 cities[i].Battle(hour); 586 } 587 } 588 if (con == 5){//001:50 20 elements in red headquarter 589 printf("%03d:50 %d elements in red headquarter\n", hour, Red.get_HP()); 590 printf("%03d:50 %d elements in blue headquarter\n", hour, Blue.get_HP()); 591 } 592 if (con == 6){ 593 for(int i=0;i<=N+1;i++) 594 cities[i].report_status(hour); 595 } 596 } 597 cities.clear(); 598 } 599 return 0; 600 }
居然不小心凑了个600行的整数啊!!我粘贴之前真的都没有注意到QAQ
武器部分我借鉴了网上一个代码的思路,把武器状态压缩成一个数那个地方有点意思orz后来我觉得他的其他地方太复杂了我看不懂,所以就又都是自己写的了orz
我养成了写超详细注释的习惯!!
大声赞美visual studio2019!!!好过dev C++ 100000000倍!!
大声再感谢图老师救我于水火之中。
魔兽2和魔兽3之间真的是鸿沟orz
我想不起来都出过什么错了,倒数第二步有审题不仔细输出格式的错误,最后一步是一用wolf抢武器erase部分处理的错误。至于再之前的……罢了,我不想去回忆了。
其实这个程序写的有点乱七八糟,最后几个大类都互为友元了,私有和保护形同虚设,那些get函数其实也可以不用的。
但总之,就这样了!!!!!!!!!我还有一堆事情要干!!!!这几天单词都没背!今天晚上还有ppt!orz 加油苟住!!!