Compare commits
No commits in common. "1b49bc799b809366592af42934d3190cc07fca45" and "534b7a35f3acc55095c209d1c152671035623bdd" have entirely different histories.
1b49bc799b
...
534b7a35f3
@ -31,39 +31,6 @@ void GameState::clearUnits(){
|
|||||||
units.clear();
|
units.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
GameState &GameState::operator=(const GameState &other) {
|
|
||||||
if (this == &other)
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
clearUnits();
|
|
||||||
for (const Unit *const unit : other.units)
|
|
||||||
units.push_back(unit->clone());
|
|
||||||
hero = other.hero;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameState::GameState(const GameState &other) : hero(other.hero) {
|
|
||||||
clearUnits();
|
|
||||||
for (const Unit *const unit : other.units)
|
|
||||||
units.push_back(unit->clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
GameState &GameState::operator=(GameState &&other) noexcept {
|
|
||||||
if (this == &other)
|
|
||||||
return *this;
|
|
||||||
clearUnits();
|
|
||||||
|
|
||||||
hero = std::move(other.hero);
|
|
||||||
units = std::move(other.units);
|
|
||||||
other.units.clear();
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameState::GameState(GameState &&other) noexcept : units(std::move(other.units)), hero(std::move(other.hero)) {
|
|
||||||
other.units.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameState::draw(QGraphicsScene *scene) const {
|
void GameState::draw(QGraphicsScene *scene) const {
|
||||||
scene->clear();
|
scene->clear();
|
||||||
hero.draw(scene);
|
hero.draw(scene);
|
||||||
@ -100,6 +67,23 @@ void GameState::updateCrashes() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameState &GameState::operator=(const GameState &other) {
|
||||||
|
if (this == &other)
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
clearUnits();
|
||||||
|
for (const Unit *const unit : other.units)
|
||||||
|
units.push_back(unit->clone());
|
||||||
|
hero = other.hero;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameState::GameState(const GameState &other) : hero(other.hero) {
|
||||||
|
clearUnits();
|
||||||
|
for (const Unit *const unit : other.units)
|
||||||
|
units.push_back(unit->clone());
|
||||||
|
}
|
||||||
|
|
||||||
int GameState::countToBeJunked() const {
|
int GameState::countToBeJunked() const {
|
||||||
int numberDestroyed = 0;
|
int numberDestroyed = 0;
|
||||||
for (const Unit *const unit: units)
|
for (const Unit *const unit: units)
|
||||||
|
@ -27,14 +27,8 @@ public:
|
|||||||
|
|
||||||
~GameState();
|
~GameState();
|
||||||
|
|
||||||
// Copy
|
|
||||||
GameState &operator=(const GameState &other);
|
GameState &operator=(const GameState &other);
|
||||||
GameState(const GameState &other);
|
GameState(const GameState &other);
|
||||||
|
|
||||||
// Move
|
|
||||||
GameState &operator=(GameState &&other) noexcept;
|
|
||||||
GameState(GameState &&other) noexcept;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Clear and redraw entire playing field
|
* Clear and redraw entire playing field
|
||||||
*/
|
*/
|
||||||
|
@ -17,7 +17,3 @@ void Hero::draw(QGraphicsScene *scene) const {
|
|||||||
Unit *Hero::clone() const {
|
Unit *Hero::clone() const {
|
||||||
return new Hero(*this);
|
return new Hero(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Hero::isAlive() const { return true; }
|
|
||||||
bool Hero::isToBeJunked() const { return false; }
|
|
||||||
void Hero::doCrash() {}
|
|
||||||
|
@ -15,12 +15,10 @@ public:
|
|||||||
Unit *clone() const override;
|
Unit *clone() const override;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Draws this hero onto the given QGraphicsScene.
|
* Draws this hero onto the given QGraphicsScene.
|
||||||
*/
|
*/
|
||||||
void draw(QGraphicsScene *scene) const override;
|
void draw(QGraphicsScene *scene) const override;
|
||||||
bool isAlive() const override;
|
|
||||||
bool isToBeJunked() const override;
|
|
||||||
void doCrash() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // HERO_H
|
#endif // HERO_H
|
||||||
|
@ -59,4 +59,7 @@ void Unit::checkBounds() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Default implementation
|
// Default implementation
|
||||||
|
bool Unit::isAlive() const { return true; }
|
||||||
|
bool Unit::isToBeJunked() const { return false; }
|
||||||
|
void Unit::doCrash() {}
|
||||||
|
void Unit::draw(QGraphicsScene *) const {}
|
||||||
|
@ -57,10 +57,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
double distanceTo(const Unit& u) const;
|
double distanceTo(const Unit& u) const;
|
||||||
|
|
||||||
virtual bool isAlive() const = 0;
|
virtual bool isAlive() const;
|
||||||
virtual bool isToBeJunked() const = 0;
|
virtual bool isToBeJunked() const;
|
||||||
virtual void doCrash() = 0;
|
virtual void doCrash();
|
||||||
virtual void draw(QGraphicsScene *scene) const = 0;
|
virtual void draw(QGraphicsScene *scene) const;
|
||||||
private:
|
private:
|
||||||
int x; // x position of this unit
|
int x; // x position of this unit
|
||||||
int y; // y position of this unit
|
int y; // y position of this unit
|
||||||
|
Loading…
x
Reference in New Issue
Block a user