Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main.cc
- #include "galaxy.hh"
- #include "initialize.hh"
- #include "igamerunner.hh"
- #include "utility.hh"
- #include "eventhandler.hh"
- #include "mainwindow.hh"
- #include <QApplication>
- #include <memory>
- #include <time.h>
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- std::shared_ptr<Common::IEventHandler> handler = std::make_shared<Student::EventHandler>();
- std::shared_ptr<Student::EventHandler> studentHandler;
- // studentHandler = std::dynamic_pointer_cast<Common::IEventHandler>(handler); //static vai dynamic pointer_cast??
- std::shared_ptr<Student::Galaxy> galaxy = std::make_shared<Student::Galaxy>();
- // galaxy->passHandler(studentHandler);
- std::shared_ptr<Common::IGameRunner> gameRunner = Common::getGameRunner(galaxy, handler);
- Common::utilityInit(time(NULL));
- MainWindow w;
- w.show();
- return a.exec();
- }
- evenhadler.hh
- #ifndef EVENTHANDLER_HH
- #define EVENTHANDLER_HH
- #include "galaxy.hh"
- #include "point.hh"
- #include "ship.hh"
- #include "ieventhandler.hh"
- #include "mainwindow.hh"
- namespace Student {
- class EventHandler: public Common::IEventHandler
- {
- public:
- EventHandler();
- ~EventHandler();
- void starSystemSpawned(std::shared_ptr<Common::StarSystem> starSystem);
- void shipSpawned(std::shared_ptr<Common::Ship> ship);
- void shipRemoved(std::shared_ptr<Common::Ship> ship);
- void shipRelocated(std::shared_ptr<Common::Ship> ship,
- std::shared_ptr<Common::StarSystem> starSystem);
- void shipMoved(std::shared_ptr<Common::Ship> ship,
- Common::Point origin,
- Common::Point target);
- void exceptionInExecution(std::shared_ptr<Common::Ship> ship, std::string const& msg);
- void distressOn(std::shared_ptr<Common::Ship> ship);
- void distressOff(std::shared_ptr<Common::Ship> ship);
- void shipAbandoned(std::shared_ptr<Common::Ship> ship);
- private:
- //std::shared_ptr<Student::Galaxy> galaxy_;
- };
- }
- galaxy.hh
- #ifndef GALAXY_HH
- #define GALAXY_HH
- #include "igalaxy.hh"
- #include "ship.hh"
- #include "starsystem.hh"
- #include "eventhandler.hh"
- #include <vector>
- namespace Student {
- class Galaxy : public Common::IGalaxy, public std::enable_shared_from_this<Galaxy>
- {
- public:
- Galaxy();
- ~Galaxy();
- //IGalaxy
- virtual void addShip(std::shared_ptr<Common::Ship> ship);
- virtual void removeShip(std::shared_ptr<Common::Ship> ship);
- virtual void addStarSystem(std::shared_ptr<Common::StarSystem> starSystem);
- virtual std::shared_ptr<ShipVector> getShips();
- virtual Common::StarSystem::StarSystemVector getSystemsInRange
- (std::shared_ptr<Common::StarSystem> origin, int range);
- virtual std::shared_ptr<Common::StarSystem> getRandomSystem();
- ShipVector getShipsInStarSystem(std::string name);
- std::vector<std::string> getSystemNames();
- std::shared_ptr<Common::StarSystem> getStarSystemByName(std::string name);
- std::shared_ptr<Common::StarSystem> getStarSystemById(unsigned id);
- // void passHandler(std::shared_ptr<Student::EventHandler> handler);
- private:
- ShipVector shipPointers_;
- std::vector<std::shared_ptr<Common::StarSystem>> starSystemPointers_;
- // std::shared_ptr<Student::EventHandler> handler_;
- };
- galaxy.cc
- /*
- void Galaxy::passHandler(std::shared_ptr<EventHandler> handler)
- {
- handler_ = handler;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement