Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.38 KB | None | 0 0
  1. main.cc
  2.  
  3. #include "galaxy.hh"
  4. #include "initialize.hh"
  5. #include "igamerunner.hh"
  6. #include "utility.hh"
  7. #include "eventhandler.hh"
  8. #include "mainwindow.hh"
  9. #include <QApplication>
  10. #include <memory>
  11. #include <time.h>
  12.  
  13. int main(int argc, char *argv[])
  14. {
  15.     QApplication a(argc, argv);
  16.  
  17.     std::shared_ptr<Common::IEventHandler> handler = std::make_shared<Student::EventHandler>();
  18.     std::shared_ptr<Student::EventHandler> studentHandler;
  19. //    studentHandler = std::dynamic_pointer_cast<Common::IEventHandler>(handler); //static vai dynamic pointer_cast??
  20.     std::shared_ptr<Student::Galaxy> galaxy = std::make_shared<Student::Galaxy>();
  21. //    galaxy->passHandler(studentHandler);
  22.     std::shared_ptr<Common::IGameRunner> gameRunner = Common::getGameRunner(galaxy, handler);
  23.     Common::utilityInit(time(NULL));
  24.  
  25.     MainWindow w;
  26.     w.show();
  27.  
  28.     return a.exec();
  29.  
  30.  
  31. }
  32.  
  33.  
  34. evenhadler.hh
  35.  
  36. #ifndef EVENTHANDLER_HH
  37. #define EVENTHANDLER_HH
  38. #include "galaxy.hh"
  39. #include "point.hh"
  40. #include "ship.hh"
  41. #include "ieventhandler.hh"
  42. #include "mainwindow.hh"
  43.  
  44.  
  45. namespace Student {
  46. class EventHandler: public Common::IEventHandler
  47. {
  48. public:
  49.     EventHandler();
  50.     ~EventHandler();
  51.     void starSystemSpawned(std::shared_ptr<Common::StarSystem> starSystem);
  52.     void shipSpawned(std::shared_ptr<Common::Ship> ship);
  53.     void shipRemoved(std::shared_ptr<Common::Ship> ship);
  54.     void shipRelocated(std::shared_ptr<Common::Ship> ship,
  55.                        std::shared_ptr<Common::StarSystem> starSystem);
  56.     void shipMoved(std::shared_ptr<Common::Ship> ship,
  57.                    Common::Point origin,
  58.                    Common::Point target);
  59.     void exceptionInExecution(std::shared_ptr<Common::Ship> ship, std::string const& msg);
  60.     void distressOn(std::shared_ptr<Common::Ship> ship);
  61.     void distressOff(std::shared_ptr<Common::Ship> ship);
  62.     void shipAbandoned(std::shared_ptr<Common::Ship> ship);
  63. private:
  64.     //std::shared_ptr<Student::Galaxy> galaxy_;
  65. };
  66. }
  67.  
  68. galaxy.hh
  69.  
  70. #ifndef GALAXY_HH
  71. #define GALAXY_HH
  72. #include "igalaxy.hh"
  73. #include "ship.hh"
  74. #include "starsystem.hh"
  75. #include "eventhandler.hh"
  76. #include <vector>
  77. namespace Student {
  78.  
  79. class Galaxy : public Common::IGalaxy, public std::enable_shared_from_this<Galaxy>
  80. {
  81. public:
  82.     Galaxy();
  83.     ~Galaxy();
  84.     //IGalaxy
  85.     virtual void addShip(std::shared_ptr<Common::Ship> ship);
  86.     virtual void removeShip(std::shared_ptr<Common::Ship> ship);
  87.     virtual void addStarSystem(std::shared_ptr<Common::StarSystem> starSystem);
  88.  
  89.     virtual std::shared_ptr<ShipVector> getShips();
  90.  
  91.     virtual Common::StarSystem::StarSystemVector getSystemsInRange
  92.     (std::shared_ptr<Common::StarSystem> origin, int range);
  93.     virtual std::shared_ptr<Common::StarSystem> getRandomSystem();
  94.  
  95.     ShipVector getShipsInStarSystem(std::string name);
  96.     std::vector<std::string> getSystemNames();
  97.     std::shared_ptr<Common::StarSystem> getStarSystemByName(std::string name);
  98.     std::shared_ptr<Common::StarSystem> getStarSystemById(unsigned id);
  99.  
  100. //    void passHandler(std::shared_ptr<Student::EventHandler> handler);
  101.  
  102. private:
  103.     ShipVector shipPointers_;
  104.     std::vector<std::shared_ptr<Common::StarSystem>> starSystemPointers_;
  105. //    std::shared_ptr<Student::EventHandler> handler_;
  106.  
  107.  
  108. };
  109.  
  110. galaxy.cc
  111.  
  112. /*
  113. void Galaxy::passHandler(std::shared_ptr<EventHandler> handler)
  114. {
  115.     handler_ = handler;
  116. }
  117. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement