int main(){ window w( vector( 128, 64 ), 2 ); ball b( w, vector( 50, 20 ), 9, vector( 5, 5 ) ); wall top(w, vector(4,0), vector(119,3), 1, vector(1,-1)); wall right(w, vector(120,0), vector(124,60), 1 ,vector(-1,1)); wall bottom(w, vector(4,61), vector(119,64), 1, vector(1,-1)); wall left(w, vector(4,4), vector(8,60), 1, vector(-1, 1)); wall box(w, vector(50,40), vector(90,40),1, vector(-1, 1)); victim foe(w, vector(50,40), vector(60,50)); drawable * objects[] = { &b, &right, &bottom, &top, &left, &foe}; for(;;){ w.clear(); for( auto & p : objects ){ p->draw(); } wait_ms( 200 ); for( auto & p : objects ){ p->update(); } for( auto & p : objects ){ for( auto & other : objects ){ p->interact( *other ); } } } }
void QgsApplication::setFileOpenEventReceiver( QObject * receiver ) { // Set receiver for FileOpen events mFileOpenEventReceiver = receiver; // Propagate any events collected before the receiver has registered. if ( mFileOpenEventList.count() > 0 ) { QStringListIterator i( mFileOpenEventList ); while ( i.hasNext() ) { QFileOpenEvent foe( i.next() ); QgsApplication::sendEvent( mFileOpenEventReceiver, &foe ); } mFileOpenEventList.clear(); } }
// make the two Warriors ``self'' and ``other'' fight until one of the die void fight(Warrior& self, Warrior& other) { std::thread foe(start_fight, std::ref(other), std::ref(self)); start_fight(std::ref(self), std::ref(other)); foe.join(); }
void BattleInput::dealWithCommandInfo(DataStream &in, uchar command, int spot) { switch (command) { case BC::SendOut: { bool silent; quint8 prevIndex; auto poke = mk<ShallowBattlePoke>(); in >> silent; in >> prevIndex; in >> *poke; output<BattleEnum::SendOut>(spot, prevIndex, &poke, silent); break; } case BC::SendBack: { bool silent; in >> silent; output<BattleEnum::SendBack>(spot, silent); break; } case BC::UseAttack: { qint16 attack; bool silent; bool special; in >> attack >> silent >> special; output<BattleEnum::UseAttack>(spot, attack, silent, special); break; } case BC::UsePP: { qint16 attack; quint8 ppsum; in >> attack >> ppsum; output<BattleEnum::UsePP>(spot, attack, ppsum); break; } case BC::BeginTurn: { int turn; in >> turn; output<BattleEnum::Turn>(turn); break; } case BC::ChangeHp: { quint16 newHp; in >> newHp; output<BattleEnum::NewHp>(spot, newHp); break; } case BC::Ko: output<BattleEnum::Ko>(spot); break; case BC::Hit: { quint8 number; in >> number; output<BattleEnum::Hits>(spot, number); break; } case BC::Effective: { quint8 eff; in >> eff; output<BattleEnum::Effectiveness>(spot, eff); break; } case BC::CriticalHit: output<BattleEnum::CriticalHit>(spot); break; case BC::Miss: { output<BattleEnum::Miss>(spot); break; } case BC::Avoid: { output<BattleEnum::Avoid>(spot); break; } case BC::StatChange: { qint8 stat, boost; bool silent; in >> stat >> boost >> silent; output<BattleEnum::StatChange>(spot, stat, boost, silent); break; } case BC::CappedStat: { qint8 stat; bool maxi; in >> stat >> maxi; output<BattleEnum::CappedStat>(spot, stat, maxi); break; } case BC::StatusChange: { qint8 status; in >> status; bool multipleTurns, silent; in >> multipleTurns >> silent; output<BattleEnum::ClassicStatusChange>(spot, status, multipleTurns, silent); break; } case BC::AbsStatusChange: { qint8 poke, status; in >> poke >> status; if (poke < 0 || poke >= 6) break; output<BattleEnum::AbsoluteStatusChange>(spot,poke,status); break; } case BC::AlreadyStatusMessage: { quint8 status; in >> status; output<BattleEnum::AlreadyStatusMessage>(spot,status); break; } case BC::StatusMessage: { qint8 status; in >> status; static const QPair<BattleEnum, int> corr[]= { QPair<BattleEnum, int>(BattleEnum::StatusFeel, Pokemon::Confused), QPair<BattleEnum, int>(BattleEnum::StatusHurt, Pokemon::Confused), QPair<BattleEnum, int>(BattleEnum::StatusFree, Pokemon::Confused), QPair<BattleEnum, int>(BattleEnum::StatusFeel, Pokemon::Paralysed), QPair<BattleEnum, int>(BattleEnum::StatusFeel, Pokemon::Frozen), QPair<BattleEnum, int>(BattleEnum::StatusFree, Pokemon::Frozen), QPair<BattleEnum, int>(BattleEnum::StatusFeel, Pokemon::Asleep), QPair<BattleEnum, int>(BattleEnum::StatusFree, Pokemon::Asleep), QPair<BattleEnum, int>(BattleEnum::StatusHurt, Pokemon::Burnt), QPair<BattleEnum, int>(BattleEnum::StatusHurt, Pokemon::Poisoned) }; static const int num = sizeof(corr)/sizeof(*corr); if (status >= 0 && status < num) { switch (corr[status].first) { case BattleEnum::StatusFeel: output<BattleEnum::StatusFeel>(spot, corr[status].second); break; case BattleEnum::StatusFree: output<BattleEnum::StatusFree>(spot, corr[status].second); break; case BattleEnum::StatusHurt: output<BattleEnum::StatusHurt>(spot, corr[status].second); default: break; } } break; } case BC::Failed: { bool silent; in >> silent; output<BattleEnum::Fail>(spot, silent); break; } case BC::BattleChat: { auto message = mk<QString>(); in >> *message; output<BattleEnum::PlayerMessage>(spot, &message, false); break; } case BC::EndMessage: { auto message = mk<QString>(); in >> *message; output<BattleEnum::PlayerMessage>(spot, &message, true); break; } case BC::Spectating: { bool come; qint32 id; in >> come >> id; if (conf && conf->isInBattle(id)) { if (come) { output<BattleEnum::Reconnect>(id); } else { output<BattleEnum::Disconnect>(id); } } else { if (come) { auto name = mk<QString>(); in >> *name; output<BattleEnum::SpectatorEnter>(id, &name); } else { output<BattleEnum::SpectatorLeave>(id); } } break; } case BC::SpectatorChat: { qint32 id; auto message = mk<QString>(); in >> id >> *message; output<BattleEnum::SpectatorMessage>(id, &message); break; } case BC::MoveMessage: { quint16 move=0; uchar part=0; qint8 type(0), foe(0); qint16 other(0); auto q = mk<QString>(); in >> move >> part >> type >> foe >> other >> *q; if (move == 57) { output<BattleEnum::StartWeather>(spot, part+1, false); //False for non-ability weather } else { output<BattleEnum::MoveMessage>(spot, move, part, type, foe, other, &q); } break; } case BC::NoOpponent: output<BattleEnum::NoTargetMessage>(spot); break; case BC::ItemMessage: { quint16 item=0; uchar part=0; qint8 foe = 0; qint32 other=0; qint16 berry = 0; in >> item >> part >> foe >> berry >> other; output<BattleEnum::ItemMessage>(spot, item, part, foe, berry, other); break; } case BC::Flinch: { output<BattleEnum::Flinch>(spot); break; } case BC::Recoil: { bool damage; in >> damage; if (damage) output<BattleEnum::Recoil>(spot); else output<BattleEnum::Drained>(spot); break; } case BC::WeatherMessage: { qint8 wstatus, weather; in >> wstatus >> weather; if (weather == BC::NormalWeather) break; switch(wstatus) { case BC::EndWeather: output<BattleEnum::EndWeather>(weather); break; case BC::HurtWeather: output<BattleEnum::WeatherDamage>(spot, weather); break; case BC::ContinueWeather: output<BattleEnum::WeatherMessage>(weather); break; } } break; case BC::StraightDamage: { qint16 damage; in >> damage; output<BattleEnum::Damaged>(spot, damage); break; } case BC::AbilityMessage: { quint16 ab=0; uchar part=0; qint8 type(0), foe(0); qint16 other(0); in >> ab >> part >> type >> foe >> other; if (ab == 14) { /* Weather message */ output<BattleEnum::StartWeather>(spot, part+1, true); //true is for ability-weather } else if (ab == 126 && other < 1) { output<BattleEnum::StartWeather>(spot, part+5, true); //true is for ability-weather } else { output<BattleEnum::AbilityMessage>(spot, ab, part, type, foe, other); } break; } case BC::Substitute: { bool sub; in >> sub; output<BattleEnum::SubstituteStatus>(spot, sub); break; } case BC::BattleEnd: { qint8 res; in >> res; output<BattleEnum::BattleEnd>(res, spot); break; } case BC::BlankMessage: { output<BattleEnum::BlankMessage>(); break; } case BC::Clause: { output<BattleEnum::ClauseMessage>(spot); break; } case BC::Rated: { bool rated; in >> rated; output<BattleEnum::RatedInfo>(rated); break; } case BC::TierSection: { auto tier = mk<QString>(); in >> *tier; output<BattleEnum::TierInfo>(&tier); break; } case BC::DynamicInfo: { BattleDynamicInfo info; in >> info; output<BattleEnum::StatBoostsAndField>(spot, info); break; } case BC::ChangeTempPoke: { quint8 type; in >> type; if (type == BC::TempMove || type == BC::DefMove) { qint8 slot; quint16 move; in >> slot >> move; output<BattleEnum::MoveChange>(spot, slot, move, type==BC::DefMove); } else if (type == BC::TempAbility) {