main.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include <iostream>
  2. #include <map>
  3. #define NB_MODELS 9
  4. enum WeaponType { GUN, SNIPER, SHOTGUN, USIANE, SCATTER, BAROUDEUR, SULFATEUSE, TRIPHASEUR, BOMBER };
  5. class Craft
  6. {
  7. public:
  8. Craft();
  9. Craft( WeaponType a, WeaponType b );
  10. ~Craft();
  11. void debugCout() const;
  12. bool operator<( const Craft& a) const;
  13. private:
  14. WeaponType m_a;
  15. WeaponType m_b;
  16. };
  17. void craftTabler( std::map< Craft, WeaponType > *tabCraft )
  18. {
  19. (*tabCraft)[ Craft( SHOTGUN, BAROUDEUR ) ] = BOMBER;
  20. (*tabCraft)[ Craft( SNIPER, SCATTER ) ] = TRIPHASEUR;
  21. (*tabCraft)[ Craft( SNIPER, SHOTGUN ) ] = BAROUDEUR;
  22. (*tabCraft)[ Craft( GUN, USIANE ) ] = SULFATEUSE;
  23. (*tabCraft)[ Craft( GUN, SHOTGUN ) ] = USIANE;
  24. (*tabCraft)[ Craft( GUN, SNIPER ) ] = SCATTER;
  25. }
  26. int main() /// MAIN
  27. {
  28. std::cout << "Surcharge d'opérateurs !" << std::endl;
  29. std::cout << " GUN:0 SNIPER:1 SHOTGUN:2 USIANE:3 SCATTER:4 BAROUDEUR:5 SULFATEUSE:6 TRIPHASEUR:7 BOMBER:8" << std::endl;
  30. std::map< Craft, WeaponType > tabCraft;
  31. std::map< Craft, WeaponType >::iterator it;
  32. craftTabler( &tabCraft );
  33. Craft *prod(0x0);
  34. WeaponType a, b;
  35. int nbPos(0);
  36. for ( unsigned short i(0); i<NB_MODELS; i++ )
  37. for ( unsigned short j(i); j<NB_MODELS; j++ )
  38. {
  39. a = (WeaponType)j;
  40. b = (WeaponType)i;
  41. prod = new Craft(a,b);
  42. it = tabCraft.find( *prod );
  43. prod->debugCout();
  44. if ( it == tabCraft.end() ) std::cout << "Combinaison inexistante.";
  45. else {
  46. std::cout << "Arme obtenue : " << tabCraft[ *prod ];
  47. nbPos++;
  48. }
  49. std::cout << std::endl << std::endl << std::endl;
  50. delete prod;
  51. prod = 0x0;
  52. }
  53. std::cout << nbPos << " possibilités de craft." << std::endl;
  54. it = tabCraft.begin();
  55. while ( it != tabCraft.end() )
  56. {
  57. it->first.debugCout();
  58. std::cout << "Donne " << it->second << std::endl << std::endl << std::endl;
  59. it++;
  60. }
  61. return 0;
  62. } /// MAIN
  63. Craft::Craft()
  64. :m_a(GUN), m_b(SHOTGUN)
  65. {
  66. }
  67. Craft::Craft( WeaponType a, WeaponType b )
  68. {
  69. if ( a < b ) {
  70. m_a = a;
  71. m_b = b;
  72. }
  73. else {
  74. m_a = b;
  75. m_b = a;
  76. }
  77. }
  78. Craft::~Craft()
  79. {
  80. }
  81. void Craft::debugCout() const
  82. {
  83. std::cout <<"Arme A : "<< m_a << std::endl;
  84. std::cout <<"Arme B : "<< m_b << std::endl << std::endl;
  85. }
  86. bool Craft::operator<( const Craft& a ) const
  87. {
  88. if ( m_a < a.m_a )
  89. return true;
  90. else
  91. return m_b < a.m_b;
  92. }
  93. /*bool Craft::operator==( const Craft& a) const
  94. {
  95. return m_a == a.m_a && m_b == a.m_b;
  96. }*/