From 6f5cb7a9babdf57f5eae54fb468773857f48ecdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 10 Nov 2020 15:33:46 +0100 Subject: copy assignment return when this == &other --- labb4/GameState.cpp | 1 + labb4/GameState.h | 2 +- labb4/mainwindow.cpp | 6 ++++-- 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 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)); -- cgit v1.2.1