bool Fighter::attack(Fighter& f, bool counter) { int attk = counter ? defend() : specialAttack(); if (counter) { std::cout << "Mighty " << name << " strikes back " << f.getName() << " with " << attk << " !!!" << std::endl << std::endl; } else { std::cout << "Legendary " << name << " attacks " << f.getName() << " with " << attk << " !!!" << std::endl; } f.reduceLife(attk); if (f.dead()) return true; if (!counter) return f.attack(*this, true); return false; }
void ClientDefending::executeNoMore() { if (getGameWindow().getServerProxy() != NULL) { std::vector<std::string> parameters; std::ostringstream armyCountStr; std::ostringstream firstPlayerStr; std::ostringstream secondPlayerStr; armyCountStr << getArmyCount(); firstPlayerStr << getGameWindow().getServerProxy()->getMe(); secondPlayerStr << attackerId; parameters.push_back(attackedCountry); parameters.push_back(armyCountStr.str()); parameters.push_back(firstPlayerStr.str()); parameters.push_back(secondPlayerStr.str()); Defend defend(parameters); defend.setFrom(getGameWindow().getServerProxy()->getMe()); defend.setTo(attackerId); getGameWindow().getServerProxy()->notify(defend); ReferenceCountPtr<ClientState> waiting = new ClientWaiting(getGameWindow()); getGameWindow().setState(waiting); } }
int main(void) { robockey_init(); while(1) { comm(command); mode = check_mode(); if(wii_flag && command == PLAY) { location_flag = localization(blobs, calibration, location); wii_flag = 0; } switch(mode) { case 0: // normal mode(GOAL A), need command PLAY TO START if(switch_flag) { goal[0] = -125; goal[1] = 0; goal[2] = 0; if(command == HALFTIME) { goal[0] = 125; switch_flag = 0; } } if(command == PLAY) { //if(!found) //{ //found = find(adc1, adc2, &count, location, goal); //set(TIMSK0,OCIE0A); // Enable timer0 interrupt //} found_flag = find(adc1, adc2, &count, location, goal); if(found_flag) { m_green(TOGGLE); m_red(OFF); //move(location, goal); defend(location, goal, found_flag); } } break; case 1: // normal mode(GOAL B), need command PLAY TO START //qualify_test(&command, blobs, location, &orientation_flag, &west_flag, &east_flag, calibration); if(switch_flag) { goal[0] = 125; goal[1] = 0; goal[2] = 0; if(command == HALFTIME) { goal[0] = -125; switch_flag = 0; } } if(command == PLAY) { found_flag = find(adc1, adc2, &count, location, goal); if(found_flag) { m_red(TOGGLE); m_green(OFF); //move(location, goal); defend(location, goal, found_flag); } } break; case 2: // calibrate the center of the rink m_green(ON); m_red(ON); if(wii_flag) { float calibrationDefault[2] = {0, 0}; float calibrationResult[3] = {0, 0, 0}; if(localization(blobs, calibrationDefault, calibrationResult)) { //m_green(ON); //m_red(ON); calibration[0] = calibrationResult[0]; calibration[1] = calibrationResult[1]; } } break; case 3: // test mode(GOAL A), always play while the power is on. m_green(TOGGLE); m_red(OFF); found_flag = find(adc1, adc2, &count, location, goal); if(found_flag) { if(wii_flag) { //if(!found) //{ //found = find(adc1, adc2, &count, location, goal); //set(TIMSK0,OCIE0A); // Enable interrupt //} if(localization(blobs, calibration, location)) { float goal[3] = {-125, 0, 0}; //move(location, goal); defend(location, goal, found_flag); } } } break; case 4: // test mode(GOAL B), always play while the power is on. m_red(TOGGLE); m_green(OFF); found_flag = find(adc1, adc2, &count, location, goal); if(found_flag) { if(wii_flag) { if(localization(blobs, calibration, location)) { float goal[3] = {125, 0, 0}; //move(location, goal); defend(location, goal, found_flag); } } } break; case 5: m_green(ON); m_red(ON); set(PORTB, 4); set(PORTB, 5); OCR1B = OCR1A; OCR1C = OCR1A; break; case 6: qualify_test(&command, blobs, location, &orientation_flag, &west_flag, &east_flag, calibration); break; case 7: set(PORTD, 4); m_red(ON); m_wait(1600); // 1600/16ms = 0.1s clear(PORTD, 4); m_wait(60000); break; default: // reset everything OCR1B = 0; OCR1C = 0; m_green(OFF); m_red(OFF); } m_usb_tx_int((int)(location[0])); m_usb_tx_char('\t'); m_usb_tx_int((int)(location[1])); m_usb_tx_char('\t'); m_usb_tx_int((int)(adc1[0])); m_usb_tx_char('\t'); m_usb_tx_int((int)(adc2[0])); m_usb_tx_char('\t'); m_usb_tx_int((int)(check(PORTB, 4))); m_usb_tx_char('\t'); m_usb_tx_int((int)(check(PORTB, 5))); m_usb_tx_char('\t'); m_usb_tx_int((int)(check(PINF, 6))); m_usb_tx_char('\t'); m_usb_tx_int((int)(check(PINF, 7))); m_usb_tx_char('\t'); m_usb_tx_int((int)(mode)); m_usb_tx_char('\t'); m_usb_tx_char('\r'); if(!check(ADCSRA, ADIF)) set(ADCSRA,ADSC); } }