Log in

View Full Version : C++


Zkhava
09-05-2004, 03:44 PM
Heres Some Code for ya !

#include
using std::cout;
using std::string;

class Extension {
public:
virtual ~Extension() { }
void registerOwner( class Image* o ) { owner = o; }
protected:
Image* owner;
};

class MosaicExtension : public Extension { public:
void doMosaic();
};

class HeatExtension : public Extension { public:
void doThermalSpectrum();
};


class Image {
string name;
public:
Image( string n ) : name(n) { }
string getName() { return name; }
void display() { cout getName() getName() registerOwner( this );
}
~Lsat() { delete exten; }
/*virtual*/ Extension* getExtension( const type_info& ti ) {
if (typeid(MosaicExtension) == ti) return exten;
return Image::getExtension( ti );
}
};

class IR : public Image {
Extension* exten;
public:
IR( string n, Extension* ex ) : Image( n ) {
exten = ex;
exten->registerOwner( this );
}
~IR() { delete exten; }
/*virtual*/ Extension* getExtension( const type_info& ti ) {
if (typeid(HeatExtension) == ti) return exten;
return Image::getExtension( ti );
}
};


void main( void ) {
Image* images[4] = {
new Lsat( "Western hemisphere", new MosaicExtension() ),
new IR( "Desert Storm", new MosaicExtension() ),
new Lsat( "Amazon rain forest", new HeatExtension() ),
new IR( "Gulf of Oman", new HeatExtension() ) };
Extension* ext;
MosaicExtension* mosaicExt;
HeatExtension* heatExt;

for (int i=0; i < 4; i++) {
images[i]->display();
if (ext = images[i]->getExtension( typeid(MosaicExtension) )) {
if (mosaicExt = dynamic_cast( ext ))
mosaicExt->doMosaic();
} else if (ext = images[i]->getExtension( typeid(HeatExtension) )) {
if (heatExt = dynamic_cast( ext ))
heatExt->doThermalSpectrum();
} }
for (i=0; i < 4; i++) delete images[i];


&

// Purpose: messages travel both up and down the layers,
// message interface per layer per direction,
// one concrete Facade per layer (implements 1 or 2 interfaces)
// Singleton access to Facade objects

#include
using namespace std;

class ChildOf3 { public: virtual void downMessage() = 0; };
class ParentOf2 { public: virtual void upMessage() = 0; };
class ChildOf2 { public: virtual void downMessage() = 0; };
class ParentOf1 { public: virtual void upMessage() = 0; };

class C : public ParentOf2 { public:
void execute();
void upMessage();
};
class B : public ParentOf1, public ChildOf3 { public:
void upMessage();
void downMessage();
};
class A : public ChildOf2 { public:
void downMessage();
void execute();
};

class SC { // Singleton Collection
public:
static C& layer3() { return cObject; }
static B& layer2() { return bObject; }
static A& layer1() { return aObject; }
private:
static C cObject; static B bObject; static A aObject;
};
C SC::cObject; B SC::bObject; A SC::aObject;

void thirdParty( ChildOf2& obj1, ChildOf3& obj2, ParentOf2& obj3 ) {
obj1.downMessage();
obj2.downMessage();
obj3.upMessage();
}

void main( void ) {
SC::layer3().execute();
SC::layer1().execute();
thirdParty( SC::layer1(), SC::layer2(), SC::layer3() );
}

// C::execute // A::execute // A::downMessage
// B::downMessage // B::upMessage // B::downMessage
// A::downMessage // C::upMessage // A::downMessage
// C::upMessage

void C::execute() { cout

Developers..... These are for a Little game im making so msg me on msn or something ! :)

Zkhava~!

sotonin
09-05-2004, 04:10 PM
couple questions.

1. What are you smoking?
2. Why do the developers care
3. Why would anybody care about a few random code snippets about *some* game u'r making without any explanation what it is or what you *think* this code does.

Zkhava
09-05-2004, 04:24 PM
mmm maybe because i got c++ down a lil bit ... Im smoking nothing..... im showing developers bout that i know c++ & would try to get to junior developer ....


So stfu sotonin! argh...

Anarchy
09-05-2004, 05:11 PM
i think sotonins title needs to be changed back to "I need to flame to feel self worthy" :roll:
this is what makes the project bad...

molimo140
09-05-2004, 05:27 PM
Word.

Zkhava
09-05-2004, 05:31 PM
Thx you 2 :)


true......... sotonin is "Negative" !$!!!

Cisyouc
09-05-2004, 05:47 PM
Er you just said that your friend knew C++ and not you....

Hmmm

Zkhava
09-05-2004, 06:14 PM
We been friends for 1year now....... I collect c++ just from watching him......


Bout 1/10 of this is from him.......

Cisyouc
09-05-2004, 06:51 PM
mmmm

#include
#include
??

Charmy
09-05-2004, 07:03 PM
i am no C++ dev but doesn't cout getName() getName() registerOwner( this ); require the stream insertion operator? <<?? i.e cout<<"Welcome BoB!!" << functionoutput() << function2output();

and as cisyouc pointed out what are you including?

Your program isn't very programmer portable friendly either, its hard to determine what exactly each of these A,B,C, Objects are suppose to represent, are they characters? are they npcs? are they animation sprites?

Zkhava
09-05-2004, 07:27 PM
Characters Charmy........

Charmy
09-05-2004, 07:30 PM
So a game your making?

If its your game i take it you wrote the code?


Sadly i have no life at this time in the moring, and when i can't sleep i wander the internet looking at hawt male porn and searching for answers, and in my quest i found the following.


// Purpose: messages travel both up and down the layers,
// message interface per layer per direction,
// one concrete Facade per layer (implements 1 or 2 interfaces)
// Singleton access to Facade objects

#include <iostream>
using namespace std;

class ChildOf3 { public: virtual void downMessage() = 0; };
class ParentOf2 { public: virtual void upMessage() = 0; };
class ChildOf2 { public: virtual void downMessage() = 0; };
class ParentOf1 { public: virtual void upMessage() = 0; };

class C : public ParentOf2 { public:
void execute();
void upMessage();
};
class B : public ParentOf1, public ChildOf3 { public:
void upMessage();
void downMessage();
};
class A : public ChildOf2 { public:
void downMessage();
void execute();
};

class SC { // Singleton Collection
public:
static C& layer3() { return cObject; }
static B& layer2() { return bObject; }
static A& layer1() { return aObject; }
private:
static C cObject; static B bObject; static A aObject;
};
C SC::cObject; B SC::bObject; A SC::aObject;

void thirdParty( ChildOf2& obj1, ChildOf3& obj2, ParentOf2& obj3 ) {
obj1.downMessage();
obj2.downMessage();
obj3.upMessage();
}

void main( void ) {
SC::layer3().execute();
SC::layer1().execute();
thirdParty( SC::layer1(), SC::layer2(), SC::layer3() );
}

// C::execute // A::execute // A::downMessage
// B::downMessage // B::upMessage // B::downMessage
// A::downMessage // C::upMessage // A::downMessage
// C::upMessage

void C::execute() { cout << "C::execute" << endl;
SC::layer2().downMessage(); }
void C::upMessage() { cout << "C::upMessage" << endl; }

void B::upMessage() { cout << "B::upMessage" << endl;
SC::layer3().upMessage(); }
void B::downMessage() { cout << "B::downMessage" << endl;
SC::layer1().downMessage(); }

void A::execute() { cout << "A::execute" << endl;
SC::layer2().upMessage(); }
void A::downMessage() { cout << "A::downMessage" << endl; }


looks familiar....

http://home.earthlink.net/~huston2/dp/layersCpp
http://home.earthlink.net/~huston2/dp/ExtensionObjectCpp

Really, don't take credit for other ppls work, its not cool, infact in all of the code network sites they say if you use this code give credit where credit is due =/ you just went and ripped this off. that or you were trying to retype it with about a 1% accuracy.

The only other thing i can think of is you were taking a tutorial from this site or somthing, and got confused somewhere.

**Just a note, before you go and say this is your friends site you might want to double check what you wrote up a little earlier about only 1/10 of this code being written by him.**

I am not one to usually bring this up, but if there is one thing being a jew has taught me its don't take credit for shit you didn't do, it just pisses people off.

And Finally
Characters Charmy........As if its suppose to be obvious using variable names like objectA, ParentB and ChildC? errm.....

gayfag~
09-05-2004, 08:49 PM
ownzed.

and he deserve sotonin's post for making this thread. if he wanst retarded he would talk to the dev on irc and pm them the code or something.

bluejam
09-06-2004, 01:32 AM
ownzed.

Hell yeah :)

Melwin
09-06-2004, 03:01 AM
Topic locked. Don't do this again.

I think the replies speak for themselves. Nice eDetective work there, Charmy. :P