summaryrefslogtreecommitdiffstats
path: root/labb4
diff options
context:
space:
mode:
Diffstat (limited to 'labb4')
-rw-r--r--labb4/GameState.cpp1
-rw-r--r--labb4/GameState.h2
-rw-r--r--labb4/mainwindow.cpp6
3 files changed, 6 insertions, 3 deletions
diff --git a/labb4/GameState.cpp b/labb4/GameState.cpp
index a21e49c..120e91a 100644
--- a/labb4/GameState.cpp
+++ b/labb4/GameState.cpp
@@ -35,6 +35,7 @@ GameState::~GameState() {
}
GameState& GameState::operator=(const GameState& other) {
+ if (this == &other) return *this;
for (const auto& robot : robots) {
delete robot;
}
diff --git a/labb4/GameState.h b/labb4/GameState.h
index 17b86de..eb10a70 100644
--- a/labb4/GameState.h
+++ b/labb4/GameState.h
@@ -76,7 +76,7 @@ public:
private:
std::vector<Robot*> robots; // the robots and the junk combined
- Hero hero; // the hero
+ Hero hero; // the hero
// private helpers
bool isEmpty(const Unit& unit) const;
diff --git a/labb4/mainwindow.cpp b/labb4/mainwindow.cpp
index 6fd4422..31ceff2 100644
--- a/labb4/mainwindow.cpp
+++ b/labb4/mainwindow.cpp
@@ -153,9 +153,11 @@ bool MainWindow::tryMove(Hero hero, const Point& point) {
* Process results of viable move
*/
void MainWindow::processMove(bool waiting) {
- GameState copy=gameState;
+ GameState copy = gameState;
copy.moveRobots();
- gameState=copy;
+ gameState = copy;
+
+ gameState = gameState;
score += gameState.countCollisions() * (POINTS_PER_ROBOT +
(waiting ? WAIT_BONUS : 0));