123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- #include <iostream>
- #include <map>
- #define NB_MODELS 9
- enum WeaponType { GUN, SNIPER, SHOTGUN, USIANE, SCATTER, BAROUDEUR, SULFATEUSE, TRIPHASEUR, BOMBER };
- class Craft
- {
- public:
- Craft();
- Craft( WeaponType a, WeaponType b );
- ~Craft();
- void debugCout() const;
- bool operator<( const Craft& a) const;
- private:
- WeaponType m_a;
- WeaponType m_b;
- };
- void craftTabler( std::map< Craft, WeaponType > *tabCraft )
- {
- (*tabCraft)[ Craft( SHOTGUN, BAROUDEUR ) ] = BOMBER;
- (*tabCraft)[ Craft( SNIPER, SCATTER ) ] = TRIPHASEUR;
- (*tabCraft)[ Craft( SNIPER, SHOTGUN ) ] = BAROUDEUR;
- (*tabCraft)[ Craft( GUN, USIANE ) ] = SULFATEUSE;
- (*tabCraft)[ Craft( GUN, SHOTGUN ) ] = USIANE;
- (*tabCraft)[ Craft( GUN, SNIPER ) ] = SCATTER;
- }
- int main() /// MAIN
- {
- std::cout << "Surcharge d'opérateurs !" << std::endl;
- std::cout << " GUN:0 SNIPER:1 SHOTGUN:2 USIANE:3 SCATTER:4 BAROUDEUR:5 SULFATEUSE:6 TRIPHASEUR:7 BOMBER:8" << std::endl;
- std::map< Craft, WeaponType > tabCraft;
- std::map< Craft, WeaponType >::iterator it;
- craftTabler( &tabCraft );
- Craft *prod(0x0);
- WeaponType a, b;
- int nbPos(0);
- for ( unsigned short i(0); i<NB_MODELS; i++ )
- for ( unsigned short j(i); j<NB_MODELS; j++ )
- {
- a = (WeaponType)j;
- b = (WeaponType)i;
- prod = new Craft(a,b);
- it = tabCraft.find( *prod );
- prod->debugCout();
- if ( it == tabCraft.end() ) std::cout << "Combinaison inexistante.";
- else {
- std::cout << "Arme obtenue : " << tabCraft[ *prod ];
- nbPos++;
- }
- std::cout << std::endl << std::endl << std::endl;
- delete prod;
- prod = 0x0;
- }
- std::cout << nbPos << " possibilités de craft." << std::endl;
- it = tabCraft.begin();
- while ( it != tabCraft.end() )
- {
- it->first.debugCout();
- std::cout << "Donne " << it->second << std::endl << std::endl << std::endl;
- it++;
- }
- return 0;
- } /// MAIN
- Craft::Craft()
- :m_a(GUN), m_b(SHOTGUN)
- {
- }
- Craft::Craft( WeaponType a, WeaponType b )
- {
- if ( a < b ) {
- m_a = a;
- m_b = b;
- }
- else {
- m_a = b;
- m_b = a;
- }
- }
- Craft::~Craft()
- {
- }
- void Craft::debugCout() const
- {
- std::cout <<"Arme A : "<< m_a << std::endl;
- std::cout <<"Arme B : "<< m_b << std::endl << std::endl;
- }
- bool Craft::operator<( const Craft& a ) const
- {
- if ( m_a < a.m_a )
- return true;
- else
- return m_b < a.m_b;
- }
- /*bool Craft::operator==( const Craft& a) const
- {
- return m_a == a.m_a && m_b == a.m_b;
- }*/
|