#include <vector>
class Subscriber;
class SubscriberAttack;
class Event{
private:
int foo;
int bar;
protected:
// static std::vector<Publisher*> publishersList;
static std::vector<Subscriber*> subscribersList;
static std::vector<Event*> eventQueue;
public:
Event(){
eventQueue.push_back(this);
}
static int subscribe(Subscriber* ss);
static int unsubscribe(Subscriber* ss);
//static int reg_publisher(Publisher* pp);
//static int unreg_publisher(Publisher* pp);
};
// class Publisher{
// };
class Subscriber{
public:
int (*newEvent) (Event* ee);
Subscriber( ){
Event::subscribe(this);
}
Subscriber( int (*fp) (Event* ee) ):newEvent(fp){
Subscriber();
}
~Subscriber(){
Event::unsubscribe(this);
}
};
class EventAttack: Event{
private:
int foo;
int bar;
protected:
// static std::vector<Publisher*> publishersList;
static std::vector<SubscriberAttack*> subscribersList;
static std::vector<EventAttack*> eventQueue;
public:
EventAttack(){
eventQueue.push_back(this);
}
static int subscribe(SubscriberAttack* ss);
static int unsubscribe(SubscriberAttack* ss);
//static int reg_publisher(Publisher* pp);
//static int unreg_publisher(Publisher* pp);
};
class AttackSubscriber :Subscriber{
public:
int (*newEvent) (EventAttack* ee);
AttackSubscriber( ){
EventAttack::subscribe(this);
}
AttackSubscriber( int (*fp) (EventAttack* ee) ):newEventAttack(fp){
AttackSubscriber();
}
~AttackSubscriber(){
EventAttack::unsubscribe(this);
}
};
paul424 {l Wrote}:How do you model that would support attacks by Fire, Ice, Eletricity, Acid etc.
Towards small, large , of a diffrent aligment creatures , plus resistence by experience, by aligment , by spells , by creature position ( fields etc. ) etc . ?
Afaik there is unit in Starcraft II which is damage only when attacked by small gun callibre, that is , its not touched by any received damage above certain quantity.
using namespace std;
void print(int ind, complex<double> x)
{ cout << "x" << ind << " = ";
notify(EventCout());
if (abs(x.imag()) < 1E-6){
cout << x.real() << endl;
notify(EventCout());}
else {cout << x << endl; notify(EventCout());}
}
int main()
{ complex<double> A, B, C, D;
cout << "A = ";
notify(EventCout());
cin >> A;
notify(EventCin());
if (abs(A)<1E-3)
{ cout << "Not a quadratic equation" << endl;
notify(EventCout());
return 1;
}
cout << "B = ";
notify(EventCout());
cin >> B;
notify(EventCout());
cout << "C = ";
notify(EventCout());
cin >> C;
notify(EventCin());
A *= 2;
D = B*B-A*C*2.0;
if (abs(D)<1E-3){
cout << "x = " << (-B/A).real();
notify(EventCout());
}
else
{ print(1, (-B+sqrt(D))/A);
notify(EventPrint());
print(2, (-B-sqrt(D))/A);
notify(EventPrint());
}
return 0;
}
paul424 {l Wrote}:"Also, I don't see why we would need to use function pointers instead of inheritance."
Yeah it depends whether the subscribing is going to be static or dynamic for the object's life.
Users browsing this forum: No registered users and 1 guest