Base methods in unit
This commit is contained in:
parent
de44ead6db
commit
7af25040f9
@ -14,3 +14,8 @@ void Junk::draw(QGraphicsScene *scene) const {
|
||||
scene->addEllipse(QRectF(corner.x * UNIT_WIDTH, corner.y * UNIT_HEIGHT,
|
||||
JUNK_RADIUS, JUNK_RADIUS), QPen(), QBrush(JUNK_COLOR));
|
||||
}
|
||||
|
||||
bool Junk::isAlive() const { return false; }
|
||||
bool Junk::isToBeJunked() const { return false; }
|
||||
void Junk::doCrash() {}
|
||||
void Junk::moveTowards(const Point&) const {}
|
||||
|
@ -16,7 +16,12 @@ public:
|
||||
/*
|
||||
* Draws this junk onto the given QGraphicsScene.
|
||||
*/
|
||||
void draw(QGraphicsScene* scene) const;
|
||||
void draw(QGraphicsScene *scene) const override;
|
||||
bool isAlive() const override;
|
||||
bool isToBeJunked() const override;
|
||||
void doCrash() override;
|
||||
void moveTowards(const Point&) const;
|
||||
|
||||
};
|
||||
|
||||
#endif // JUNK_H
|
||||
|
@ -10,13 +10,12 @@ bool Robot::isAlive() const{
|
||||
return !toBeJunked;
|
||||
}
|
||||
|
||||
void Robot::doCrash(){
|
||||
void Robot::doCrash() {
|
||||
toBeJunked = true;
|
||||
}
|
||||
|
||||
bool Robot::isToBeJunked() const{
|
||||
bool Robot::isToBeJunked() const {
|
||||
return toBeJunked;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,23 +17,22 @@ public:
|
||||
/*
|
||||
* did not crash yet
|
||||
*/
|
||||
bool isAlive() const;
|
||||
bool isAlive() const override;
|
||||
|
||||
/*
|
||||
* Crashes and remembers it
|
||||
*/
|
||||
void doCrash();
|
||||
void doCrash() override;
|
||||
|
||||
/*
|
||||
* Return whether the robot crashed
|
||||
*/
|
||||
bool isToBeJunked() const;
|
||||
|
||||
bool isToBeJunked() const override;
|
||||
|
||||
/*
|
||||
* Draws this robot onto the given QGraphicsScene.
|
||||
*/
|
||||
void draw(QGraphicsScene* scene) const;
|
||||
void draw(QGraphicsScene *scene) const override;
|
||||
|
||||
|
||||
};
|
||||
|
@ -57,3 +57,9 @@ void Unit::checkBounds() {
|
||||
if (y < MIN_Y) y = MIN_Y;
|
||||
if (y > MAX_Y) y = MAX_Y;
|
||||
}
|
||||
|
||||
// Default implementation
|
||||
bool Unit::isAlive() const { return true; }
|
||||
bool Unit::isToBeJunked() const { return false; }
|
||||
void Unit::doCrash() {}
|
||||
void Unit::draw(QGraphicsScene *) const {}
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
/*
|
||||
* Take one step closer to point
|
||||
*/
|
||||
void moveTowards(const Point&);
|
||||
virtual void moveTowards(const Point&);
|
||||
|
||||
|
||||
/*
|
||||
@ -54,6 +54,11 @@ public:
|
||||
* Euclidean distance to u
|
||||
*/
|
||||
double distanceTo(const Unit& u) const;
|
||||
|
||||
virtual bool isAlive() const;
|
||||
virtual bool isToBeJunked() const;
|
||||
virtual void doCrash();
|
||||
virtual void draw(QGraphicsScene *scene) const;
|
||||
private:
|
||||
int x; // x position of this unit
|
||||
int y; // y position of this unit
|
||||
|
Loading…
Reference in New Issue
Block a user