File indexing completed on 2024-04-21 07:49:08

0001 /*
0002     SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
0003     SPDX-FileCopyrightText: 2007-2008 Alexandre Galinier <alex.galinier@hotmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef GHOST_H
0009 #define GHOST_H
0010 
0011 #include "character.h"
0012 #include "kapman.h"
0013 
0014 /**
0015  * @brief This class represents a Ghost for kapman.
0016  */
0017 class Ghost : public Character
0018 {
0019     Q_OBJECT
0020 
0021 public:
0022     /** The ghost possible states */
0023     enum State { HUNTER = 0, PREY = 1, EATEN = 2 };
0024 
0025     /** The value of an Ghost */
0026     static const int POINTS;
0027 
0028 private:
0029     /** Max speed ratio, compared with the initial speed  */
0030     static const qreal MAX_SPEED_RATIO;
0031 
0032     /** The path to the Ghost image */
0033     QString m_imageId;
0034 
0035     /** The ghost current state */
0036     State m_state;
0037 
0038     /** A list of Cells to go to the camp from the current cell */
0039     QList<QPoint> m_pathToCamp;
0040 
0041     bool m_preyStateAlmostOver;
0042 
0043 public:
0044     /**
0045      * Creates a new Ghost instance.
0046      * @param p_x the initial x-coordinate
0047      * @param p_y the initial y-coordinate
0048      * @param p_imageId path to the image of the related item
0049      * @param p_maze the Maze the Ghost is on
0050      */
0051     Ghost(qreal p_x, qreal p_y, const QString &p_imageId, Maze *p_maze);
0052 
0053     /**
0054      * Deletes the Ghost instance.
0055      */
0056     ~Ghost() override;
0057 
0058     /**
0059      * Updates the Ghost move.
0060      */
0061     void updateMove() override;
0062 
0063     /**
0064      * Updates the Ghost with a direction to follow.
0065      * @param p_row x coordinate of the cell to reach
0066      * @param p_col y coordinate of the cell to reach
0067      */
0068     void updateMove(int p_row, int p_col);
0069 
0070     /**
0071      * Gets the path to the Ghost image.
0072      * @return the path to the Ghost image
0073      */
0074     QString getImageId() const;
0075 
0076     /**
0077      * Gets the current state of the Ghost.
0078      * @return the Ghost state
0079      */
0080     State getState() const;
0081 
0082     /**
0083      * Sets the Ghost state to the given value.
0084      * @param p_state the new Ghost state
0085      */
0086     void setState(Ghost::State p_state);
0087 
0088     /**
0089      * Manages the collision with the Kapman.
0090      * @param p_kapman the instance of Kapman which collides with the Ghost
0091      */
0092     void doActionOnCollision(Kapman *p_kapman) override;
0093 
0094     /**
0095      * Initializes the Ghost speed from the Character speed.
0096      */
0097     void initSpeedInc() override;
0098 
0099     void setPreyStateAlmostOverEnabled(bool enable);
0100     bool preyStateAlmostOver() const;
0101 
0102 private:
0103     /**
0104      * Makes the Ghost go up.
0105      */
0106     void goUp() override;
0107 
0108     /**
0109      * Makes the Ghost go down.
0110      */
0111     void goDown() override;
0112 
0113     /**
0114      * Makes the Ghost go to the right.
0115      */
0116     void goRight() override;
0117 
0118     /**
0119      * Makes the Ghost go to the left.
0120      */
0121     void goLeft() override;
0122 
0123 Q_SIGNALS:
0124 
0125     /**
0126      * Emitted when the Kapman has lost a life.
0127      */
0128     void lifeLost();
0129 
0130     /**
0131      * Emitted when the Ghost has been eaten.
0132      * @param p_ghost the eaten Ghost (this)
0133      */
0134     void ghostEaten(Ghost *p_ghost);
0135 
0136     /**
0137      * Emitted when the Ghost has changed his state.
0138      */
0139     void stateChanged();
0140 };
0141 
0142 #endif