diff options
| -rw-r--r-- | labb4/GameState.cpp | 2 | ||||
| -rw-r--r-- | labb4/GameState.h | 23 | ||||
| -rw-r--r-- | labb4/Junk.cpp | 14 | ||||
| -rw-r--r-- | labb4/Junk.h | 21 | ||||
| -rw-r--r-- | labb4/Robot.cpp | 8 | ||||
| -rw-r--r-- | labb4/Robot.h | 19 | ||||
| -rw-r--r-- | labb4/Unit.h | 24 |
7 files changed, 52 insertions, 59 deletions
diff --git a/labb4/GameState.cpp b/labb4/GameState.cpp index 47842a1..f9f5c72 100644 --- a/labb4/GameState.cpp +++ b/labb4/GameState.cpp @@ -27,8 +27,6 @@ GameState::GameState(const GameState &other) { hero = other.hero; } -/* -*/ GameState::~GameState() { for (const auto &robot : robots) { delete robot; diff --git a/labb4/GameState.h b/labb4/GameState.h index ac749bb..dfd7ac5 100644 --- a/labb4/GameState.h +++ b/labb4/GameState.h @@ -24,25 +24,28 @@ public: GameState(const GameState &other); ~GameState(); + /* + * Copy assignment. + */ GameState &operator=(const GameState &other); /* - * Clear and redraw entire playing field + * Clear and redraw entire playing field. */ - void draw(QGraphicsScene* scene) const; // Clear and redraw entire playing field + void draw(QGraphicsScene* scene) const; /* - * Teleport hero to random location + * Teleport hero to random location. */ void teleportHero(); /* - * Move robots one step towards hero + * Move robots one step towards hero. */ void moveRobots(); /* Count colliding robots. - * Also converts robots to junk while checking collisions + * Also converts robots to junk while checking collisions. */ int countCollisions (); @@ -59,21 +62,21 @@ public: /* * Can unit safely reside here? */ - bool isSafe (const Unit& unit) const; // Can unit safely reside here? + bool isSafe (const Unit& unit) const; /* - * Move hero towards dir + * Move hero towards dir. */ void moveHeroTowards (const Unit& dir); /* - * Return hero + * Return hero. */ Hero getHero () const; private: - std::vector<Robot *> robots; // the robots and the junk combined - Hero hero; // the hero + std::vector<Robot *> robots; // the robots and the junk combined + Hero hero; // the hero // private helpers bool isEmpty(const Unit& unit) const; diff --git a/labb4/Junk.cpp b/labb4/Junk.cpp index 86493c7..5c467da 100644 --- a/labb4/Junk.cpp +++ b/labb4/Junk.cpp @@ -15,20 +15,6 @@ void Junk::draw(QGraphicsScene *scene) const { JUNK_RADIUS, JUNK_RADIUS), QPen(), QBrush(JUNK_COLOR)); } -void Junk::moveTowards(const Unit&) {} - -bool Junk::attacks(const Unit&) const { - return false; -} - -unsigned int Junk::getCollisionCount() const { - return 1; -}; - -bool Junk::alive() const { - return false; -} - Junk *Junk::clone() const { return new Junk(*this); } diff --git a/labb4/Junk.h b/labb4/Junk.h index 30659ab..65201c4 100644 --- a/labb4/Junk.h +++ b/labb4/Junk.h @@ -16,18 +16,25 @@ public: ~Junk() {} /* - * Draws this junk onto the given QGraphicsScene. - */ + * Draws this junk onto the given QGraphicsScene. + */ void draw(QGraphicsScene* scene) const override; - void moveTowards(const Unit& u) override; + void moveTowards(const Unit& u) override {} - bool attacks(const Unit& u) const override; - - unsigned int getCollisionCount() const override; + /* + * Junk can't attack in any direction. + */ + bool attacks(const Unit&) const override { return false; } - bool alive() const override; + /* + * All junk is dead. + */ + bool alive() const override { return false; } + /* + * Polymorphic clone. + */ Junk *clone() const override; }; diff --git a/labb4/Robot.cpp b/labb4/Robot.cpp index f4c7fb3..444f938 100644 --- a/labb4/Robot.cpp +++ b/labb4/Robot.cpp @@ -18,14 +18,6 @@ void Robot::moveTowards(const Unit& u) { Unit::moveTowards(u); } -unsigned int Robot::getCollisionCount() const { - return 1; -}; - -bool Robot::alive() const { - return true; -} - Robot *Robot::clone() const { return new Robot(*this); } diff --git a/labb4/Robot.h b/labb4/Robot.h index 6f68e9b..224b742 100644 --- a/labb4/Robot.h +++ b/labb4/Robot.h @@ -15,12 +15,19 @@ public: virtual ~Robot() {}; virtual void draw(QGraphicsScene* scene) const; - virtual void moveTowards(const Unit& u); - - virtual unsigned int getCollisionCount() const; - - virtual bool alive() const; - + /* + * Take one step closer to u. + */ + virtual void moveTowards(const Unit& u) override; + + /* + * All robots are alive. + */ + virtual bool alive() const { return true; }; + + /* + * Polymorphic clone. + */ virtual Robot *clone() const; }; diff --git a/labb4/Unit.h b/labb4/Unit.h index 8c3a7a8..65e5db0 100644 --- a/labb4/Unit.h +++ b/labb4/Unit.h @@ -18,36 +18,36 @@ public: Unit(const Point& p); /* - * Return Point representation of Unit - */ + * Return Point representation of Unit + */ Point asPoint() const; /* - * Am I in the same square as u? - */ + * Am I in the same square as u? + */ bool at(const Unit& u) const; /* - * Can I catch u in one move? - */ + * Can I catch u in one move? + */ virtual bool attacks(const Unit& u) const; /* - * Take one step closer to u - */ + * Take one step closer to u + */ virtual void moveTowards(const Unit& u); //TODO comment virtual void draw() const; /* - * Teleport. Does not check for collision - */ + * Teleport. Does not check for collision + */ void teleport(); /* - * Euclidean distance to u - */ + * Euclidean distance to u + */ double distanceTo(const Unit& u) const; private: int x; // x position of this unit |
