void City::Attack() { int firsthand; if (flag == -1) firsthand = (num+1)%2; else firsthand = flag; if (pCityWarrior[firsthand]->IsAlive && pCityWarrior[(firsthand+1)%2]->IsAlive) { clock->PrintTime(); pCityWarrior[firsthand]->PrintInfo(); cout << " attacked "; pCityWarrior[(firsthand+1)%2]->PrintInfo(); cout << " in city " << num << " with " << pCityWarrior[firsthand]->HP << " elements"; cout << " and force " << pCityWarrior[firsthand]->atk << endl; pCityWarrior[firsthand]->attack(pCityWarrior[(firsthand+1)%2]); if (pCityWarrior[(firsthand+1)%2]->IsAlive && pCityWarrior[(firsthand+1)%2]->role_num != 1) { clock->PrintTime(); pCityWarrior[(firsthand+1)%2]->PrintInfo(); cout << " fought back against "; pCityWarrior[firsthand]->PrintInfo(); cout << " in city " << num << endl; pCityWarrior[(firsthand+1)%2]->fightback(pCityWarrior[firsthand]); } } PrintKilled(); if (pCityWarrior[firsthand]->IsAlive && pCityWarrior[firsthand]->Willyell()) { clock->PrintTime(); pCityWarrior[firsthand]->PrintInfo(); cout << " yelled in city " << num << endl; } }
void City::CollectElem(int color) { clock->PrintTime(); pCityWarrior[color]->PrintInfo(); printf(" earned %d elements for his headquarter\n",LifeElem); pMyHeadquarter[color]->TotalLifeElem += LifeElem; LifeElem = 0; }
void City::RaiseFlag() { if (WinTime == 2) { flag = LastWinner; clock->PrintTime(); cout << color_name[flag] << " flag raised in city " << num << endl; } }
void GameControl::AllShot() { for (int i = 1; i< N+1; i++) { for (int j=0; j<2; j++) { if (j == 0) { if (pCity[i]->pCityWarrior[0] != NULL && pCity[i+1]->pCityWarrior[1] != NULL && pCity[i]->pCityWarrior[0]->pArrow != NULL) { pCity[i]->ArrowShot(pCity[i+1],j); clock->PrintTime(); pCity[i]->pCityWarrior[j]->PrintInfo(); cout << " shot"; if (!pCity[i+1]->pCityWarrior[1]->IsAlive) { cout << " and killed "; pCity[i+1]->pCityWarrior[1]->PrintInfo(); } cout << endl; } } if (j == 1) { if (pCity[i]->pCityWarrior[1] != NULL && pCity[i-1]->pCityWarrior[0] != NULL && pCity[i]->pCityWarrior[1]->pArrow != NULL) { pCity[i]->ArrowShot(pCity[i-1],j); clock->PrintTime(); pCity[i]->pCityWarrior[j]->PrintInfo(); cout << " shot"; if (!pCity[i-1]->pCityWarrior[0]->IsAlive) { cout << " and killed "; pCity[i-1]->pCityWarrior[0]->PrintInfo(); } cout << endl; } } } } }
void GameControl::PrintMarch() { for (int i = 0; i< N+2; i++) { for (int j = 0; j < 2; j++) { if (pCity[i]->HasMoved[j]) { if (pCity[i]->pCityWarrior[j] == NULL) continue; if (pCity[i]->num != 0 && pCity[i]->num != N+1) { clock->PrintTime(); pCity[i]->pCityWarrior[j]->PrintInfo(); cout << " marched to city " << pCity[i]->num << " with " << pCity[i]->pCityWarrior[j]->HP << " elements and force " << pCity[i]->pCityWarrior[j]->atk << endl; } if (pCity[i]->pCityWarrior[j]!=NULL) { pCity[i]->pCityWarrior[j]->step++; pCity[i]->pCityWarrior[j]->HPToAttack(); if (pCity[i]->num == 0 || pCity[i]->num == N+1) { clock->PrintTime(); pCity[i]->pCityWarrior[j]->PrintInfo(); cout << " reached " << color_name[(j+1)%2] << " headquarter with " << pCity[i]->pCityWarrior[j]->HP; cout << " elements and force " << pCity[i]->pCityWarrior[j]->atk << endl; pCity[i]->pCityWarrior[j]->pHeadquarter->enemy++; pCity[i]->pCityWarrior[j]->pHeadquarter->occupy = pCity[i]->pCityWarrior[j]; if (pCity[i]->pCityWarrior[j]->pHeadquarter->enemy == 2) { clock->PrintTime(); cout << color_name[(j+1)%2] << " headquarter was taken" << endl; Gameover = 0; } pCity[i]->pCityWarrior[j] = NULL; } } } } } }
void City::Boom(int color) { int em = (color+1)%2; if (pCityWarrior[0] == NULL || pCityWarrior[1] == NULL) return; if (!pCityWarrior[color]->IsAlive || !pCityWarrior[em]->IsAlive) return; if (pCityWarrior[color]->pBomb == NULL) return; if (flag == color || flag == -1 && (num+1)%2 == color) { if (pCityWarrior[color]->HP <= (pCityWarrior[em]->getBackATK()) && pCityWarrior[color]->getATK() < pCityWarrior[em]->HP && pCityWarrior[em]->role_num != 1) { clock->PrintTime(); pCityWarrior[color]->PrintInfo(); cout << " used a bomb and killed "; pCityWarrior[em]->PrintInfo(); cout << endl; pCityWarrior[0]->IsAlive = false; pCityWarrior[1]->IsAlive = false; Dead(); } } if (flag == em || flag == -1 && num%2 == color) { if (pCityWarrior[color]->HP <= (pCityWarrior[em]->getATK())) { clock->PrintTime(); pCityWarrior[color]->PrintInfo(); cout << " used a bomb and killed "; pCityWarrior[em]->PrintInfo(); cout << endl; pCityWarrior[0]->IsAlive = false; pCityWarrior[1]->IsAlive = false; Dead(); } } }
void City::PrintKilled() { for (int i = 0; i < 2; i++) { if (pCityWarrior[i] == NULL) continue; if (pCityWarrior[i]->Waskilled) { clock->PrintTime(); pCityWarrior[i]->PrintInfo(); cout << " was killed in city " << num << endl; } } }
void GameControl::AllReportWeapon() { for (int i = 0; i< N+1; i++) { pCity[i]->ReportWeapon(0); } if (pMyHeadquarter[1]->occupy != NULL) { clock->PrintTime(); pMyHeadquarter[1]->ReportBaseWeapon(); } if (pMyHeadquarter[0]->occupy != NULL) { clock->PrintTime(); pMyHeadquarter[0]->ReportBaseWeapon(); } for (int i = 1; i< N+1; i++) { pCity[i]->ReportWeapon(1); } }
void City::LionEscape() { for (int i = 0; i<2; i++) { if (pCityWarrior[i] == NULL) continue; if(pCityWarrior[i]->escape()) { clock->PrintTime(); pCityWarrior[i]->PrintInfo(); cout << " ran away" << endl; pCityWarrior[i] = NULL; } } }
void City::ReportWeapon(int color) { if (pCityWarrior[color] == NULL) return; clock->PrintTime(); pCityWarrior[color]->PrintInfo(); cout << " has "; if (pCityWarrior[color]->pSword == NULL && pCityWarrior[color]->pBomb == NULL && pCityWarrior[color]->pArrow == NULL) cout << "no weapon "; if (pCityWarrior[color]->pArrow != NULL) cout << "arrow(" << pCityWarrior[color]->pArrow->remain << "),"; if (pCityWarrior[color]->pBomb != NULL) cout << "bomb,"; if (pCityWarrior[color]->pSword != NULL) cout << "sword(" << pCityWarrior[color]->pSword->atk << "),"; cout << '\b' << " " << '\b' << endl; }
void Headquarter::Produce(Clock & clock, City** pCity) { if (LifeElem[ProduceOrder[color][sequence % WARR_NUM]] > TotalLifeElem) { Isstopped = true; return; } //current kind of warrior current_role = ProduceOrder[color][sequence % WARR_NUM]; //consume the life elements; TotalLifeElem -= LifeElem[current_role]; //create a new warrior switch (current_role) { case 0: pWarrior[TotalNum] = new dragon(this, current_role, TotalNum+1, pCity); break; case 1: pWarrior[TotalNum] = new ninja(this, current_role, TotalNum+1, pCity); break; case 2: pWarrior[TotalNum] = new iceman(this, current_role, TotalNum+1, pCity); break; case 3: pWarrior[TotalNum] = new lion(this, current_role, TotalNum+1, pCity); break; case 4: pWarrior[TotalNum] = new wolf(this, current_role, TotalNum+1, pCity); break; } clock.PrintTime(); pWarrior[TotalNum]->PrintInfo(); cout << " born" << endl; //increase the total number of warriors TotalNum++; //go to next one sequence++; //producing continue }
void Headquarter::ReportElem(Clock &clock) { LifeToAward = TotalLifeElem; clock.PrintTime(); printf("%d elements in %s headquarter\n",TotalLifeElem, color_name[color].c_str()); }