Commit a8d0f3b8 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

use override

parent c0deef60
......@@ -49,7 +49,7 @@ public:
* Computes an action on a collision with the Kapman.
* @param p_kapman the Kapman instance that collides with the Bonus
*/
void doActionOnCollision(Kapman *p_kapman) Q_DECL_OVERRIDE;
void doActionOnCollision(Kapman *p_kapman) override;
/**
* Sets the given value to the Bonus.
......
......@@ -34,7 +34,7 @@ class CharacterItem : public ElementItem
protected:
/** Timer used to make the character blink */
QTimer *m_blinkTimer;
QTimer *m_blinkTimer = nullptr;
/** Number of ticks of the blink timer */
int m_nbBlinks;
......@@ -57,7 +57,7 @@ public:
* This function is used to determinate collision between items
* @return QPainterPath the new shape of the Character
*/
QPainterPath shape() const Q_DECL_OVERRIDE;
QPainterPath shape() const override;
public slots:
......@@ -66,7 +66,7 @@ public slots:
* @param p_x the new x-coordinate
* @param p_y the new y-coordinate
*/
void update(qreal p_x, qreal p_y) Q_DECL_OVERRIDE;
void update(qreal p_x, qreal p_y) override;
/**
* Starts the character blinking.
......
......@@ -32,12 +32,12 @@ class ElementItem : public QGraphicsSvgItem
private:
/** The Label containing the points won when eaten, to display on the scene */
QGraphicsTextItem *m_pointsToDisplay;
QGraphicsTextItem *m_pointsToDisplay = nullptr;
protected:
/** The instance of Element the ElementItem will represent */
Element *m_model;
Element *m_model = nullptr;
public:
......@@ -61,7 +61,7 @@ public:
/**
* Reimplement QGraphicsItem::shape() to return an ellipse to improve collisions.
*/
QPainterPath shape() const Q_DECL_OVERRIDE;
QPainterPath shape() const override;
public slots:
......
......@@ -61,7 +61,7 @@ public:
* Computes an action on a collision with the Kapman.
* @param p_kapman the instance of Kapman which collides with the Energyzer
*/
void doActionOnCollision(Kapman *p_kapman) Q_DECL_OVERRIDE;
void doActionOnCollision(Kapman *p_kapman) override;
};
#endif
......
......@@ -49,7 +49,7 @@ public:
* Resizes the items when the view is resized.
* @param p_event the resize event
*/
void resizeEvent(QResizeEvent *p_event) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *p_event) override;
protected:
......@@ -57,13 +57,13 @@ protected:
* Manages the player actions by hanlding the key press events.
* @param p_event the key press event
*/
void keyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE;
void keyPressEvent(QKeyEvent *p_event) override;
/**
* Pauses the game on focus lost.
* @param p_event the focus event
*/
void focusOutEvent(QFocusEvent *p_event) Q_DECL_OVERRIDE;
void focusOutEvent(QFocusEvent *p_event) override;
signals:
......
......@@ -20,6 +20,7 @@
#include <QPointF>
#include <KgDifficulty>
#include <QRandomGenerator>
#include <cstdlib>
#include <ctime>
......@@ -34,8 +35,6 @@ Ghost::Ghost(qreal p_x, qreal p_y, const QString &p_imageId, Maze *p_maze) : Cha
m_type = Element::GHOST;
m_state = Ghost::HUNTER;
m_maxSpeed = m_normalSpeed * MAX_SPEED_RATIO;
// Initialize the random-number generator
qsrand(std::time(nullptr));
// Makes the ghost move as soon as the game is created
goLeft();
}
......@@ -112,7 +111,7 @@ void Ghost::updateMove()
}
}
// Random number generation to choose one of the directions
nb = int(double(qrand()) / (double(RAND_MAX) + 1) * directionsList.size());
nb = int(double(QRandomGenerator::global()->bounded(RAND_MAX)) / (double(RAND_MAX) + 1) * directionsList.size());
// If there is no directions in the list, the character goes backward
if (directionsList.size() == 0) {
m_xSpeed = -m_xSpeed;
......
......@@ -75,7 +75,7 @@ public:
/**
* Updates the Ghost move.
*/
void updateMove() Q_DECL_OVERRIDE;
void updateMove() override;
/**
* Updates the Ghost with a direction to follow.
......@@ -106,34 +106,34 @@ public:
* Manages the collision with the Kapman.
* @param p_kapman the instance of Kapman which collides with the Ghost
*/
void doActionOnCollision(Kapman *p_kapman) Q_DECL_OVERRIDE;
void doActionOnCollision(Kapman *p_kapman) override;
/**
* Initializes the Ghost speed from the Character speed.
*/
void initSpeedInc() Q_DECL_OVERRIDE;
void initSpeedInc() override;
private:
/**
* Makes the Ghost go up.
*/
void goUp() Q_DECL_OVERRIDE;
void goUp() override;
/**
* Makes the Ghost go down.
*/
void goDown() Q_DECL_OVERRIDE;
void goDown() override;
/**
* Makes the Ghost go to the right.
*/
void goRight() Q_DECL_OVERRIDE;
void goRight() override;
/**
* Makes the Ghost go to the left.
*/
void goLeft() Q_DECL_OVERRIDE;
void goLeft() override;
signals:
......
......@@ -33,7 +33,7 @@ class GhostItem : public CharacterItem
private:
/** Timer to start the ghosts blinking */
QTimer *m_startBlinkingTimer;
QTimer *m_startBlinkingTimer = nullptr;
public:
......@@ -60,7 +60,7 @@ public slots:
* @param p_x the new x-coordinate
* @param p_y the new y-coordinate
*/
void update(qreal p_x, qreal p_y) Q_DECL_OVERRIDE;
void update(qreal p_x, qreal p_y) override;
/**
* Update the image function of the Ghost state.
......@@ -70,7 +70,7 @@ public slots:
/**
* Implements the CharacterItem method.
*/
void blink() Q_DECL_OVERRIDE;
void blink() override;
};
#endif
......
......@@ -59,27 +59,27 @@ public:
/**
* Makes the Kapman ask to go up
*/
void goUp() Q_DECL_OVERRIDE;
void goUp() override;
/**
* Makes the Kapman ask to go down
*/
void goDown() Q_DECL_OVERRIDE;
void goDown() override;
/**
* Makes the Kapman ask to go to the right
*/
void goRight() Q_DECL_OVERRIDE;
void goRight() override;
/**
* Makes the Kapman ask to go to the left
*/
void goLeft() Q_DECL_OVERRIDE;
void goLeft() override;
/**
* Updates the Kapman move
*/
void updateMove() Q_DECL_OVERRIDE;
void updateMove() override;
/**
* @return the asked x speed value
......@@ -110,7 +110,7 @@ public:
/**
* Initializes the Kapman speed from the Character speed.
*/
void initSpeedInc() Q_DECL_OVERRIDE;
void initSpeedInc() override;
private:
......
......@@ -77,7 +77,7 @@ public slots:
* @param p_x the new x-coordinate
* @param p_y the new y-coordinate
*/
void update(qreal p_x, qreal p_y) Q_DECL_OVERRIDE;
void update(qreal p_x, qreal p_y) override;
/**
* Starts the KapmanItem animation.
......@@ -108,12 +108,12 @@ public slots:
/**
* Implements the CharacterItem method.
*/
void startBlinking() Q_DECL_OVERRIDE;
void startBlinking() override;
/**
* Implements the CharacterItem method.
*/
void blink() Q_DECL_OVERRIDE;
void blink() override;
/**
* Set if the KapmanItem should be rotated (set by theme flag RotateKapman).
......
......@@ -41,15 +41,15 @@ class KapmanMainWindow : public KXmlGuiWindow
private :
/** The GameView instance that manages the game drawing and the collisions */
GameView *m_view;
GameView *m_view = nullptr;
/** The Game instance that manages the main loop and events */
Game *m_game;
Game *m_game = nullptr;
QStatusBar *m_statusBar;
QLabel *mLevel;
QLabel *mScore;
QLabel *mLives;
QStatusBar *m_statusBar = nullptr;
QLabel *mLevel = nullptr;
QLabel *mScore = nullptr;
QLabel *mLives = nullptr;
public:
......
......@@ -55,17 +55,17 @@ public:
/**
* Implement QXmlDefaultHandler::characters
*/
bool characters(const QString &ch) Q_DECL_OVERRIDE;
bool characters(const QString &ch) override;
/**
* Implements QXmlDefaultHandler::startElement()
*/
bool startElement(const QString &, const QString &, const QString &p_qName, const QXmlAttributes &p_atts) Q_DECL_OVERRIDE;
bool startElement(const QString &, const QString &, const QString &p_qName, const QXmlAttributes &p_atts) override;
/**
* Implements QXmlDefaultHandler::endElement()
*/
bool endElement(const QString &, const QString &, const QString &p_qName) Q_DECL_OVERRIDE;
bool endElement(const QString &, const QString &, const QString &p_qName) override;
};
......
......@@ -49,7 +49,7 @@ public:
* Computes an action on a collision with the Kapman.
* @param p_kapman the instance of Kapman which collides with the Pill
*/
void doActionOnCollision(Kapman *p_kapman) Q_DECL_OVERRIDE;
void doActionOnCollision(Kapman *p_kapman) override;
};
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment