1 | /* |
2 | * Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr> |
3 | * Copyright 2007-2008 Alexandre Galinier <alex.galinier@hotmail.com> |
4 | * |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as |
7 | * published by the Free Software Foundation; either version 2 of |
8 | * the License, or (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | */ |
18 | |
19 | #ifndef GHOST_H |
20 | #define GHOST_H |
21 | |
22 | #include "character.h" |
23 | #include "kapman.h" |
24 | |
25 | |
26 | /** |
27 | * @brief This class represents a Ghost for kapman. |
28 | */ |
29 | class Ghost : public Character { |
30 | |
31 | Q_OBJECT |
32 | |
33 | public: |
34 | |
35 | /** The ghost possible states */ |
36 | enum State { |
37 | HUNTER = 0, |
38 | PREY = 1, |
39 | EATEN = 2 |
40 | }; |
41 | |
42 | /** The value of an Ghost */ |
43 | static const int POINTS; |
44 | |
45 | |
46 | private: |
47 | |
48 | /** Max speed ratio, compared with the initial speed */ |
49 | static const qreal MAX_SPEED_RATIO; |
50 | |
51 | /** The path to the Ghost image */ |
52 | QString m_imageId; |
53 | |
54 | /** The ghost current state */ |
55 | State m_state; |
56 | |
57 | /** A list of Cells to go to the camp from the current cell */ |
58 | QList<QPoint> m_pathToCamp; |
59 | |
60 | public: |
61 | |
62 | /** |
63 | * Creates a new Ghost instance. |
64 | * @param p_x the initial x-coordinate |
65 | * @param p_y the initial y-coordinate |
66 | * @param p_imageId path to the image of the related item |
67 | * @param p_maze the Maze the Ghost is on |
68 | */ |
69 | Ghost(qreal p_x, qreal p_y, const QString & p_imageId, Maze* p_maze); |
70 | |
71 | /** |
72 | * Deletes the Ghost instance. |
73 | */ |
74 | ~Ghost(); |
75 | |
76 | /** |
77 | * Updates the Ghost move. |
78 | */ |
79 | void updateMove(); |
80 | |
81 | /** |
82 | * Updates the Ghost with a direction to follow. |
83 | * @param p_row x coordinate of the cell to reach |
84 | * @param p_col y coordinate of the cell to reach |
85 | */ |
86 | void updateMove(int p_row, int p_col); |
87 | |
88 | /** |
89 | * Gets the path to the Ghost image. |
90 | * @return the path to the Ghost image |
91 | */ |
92 | QString getImageId() const; |
93 | |
94 | /** |
95 | * Gets the current state of the Ghost. |
96 | * @return the Ghost state |
97 | */ |
98 | State getState() const; |
99 | |
100 | /** |
101 | * Sets the Ghost state to the given value. |
102 | * @param p_state the new Ghost state |
103 | */ |
104 | void setState(Ghost::State p_state); |
105 | |
106 | /** |
107 | * Manages the collison with the Kapman. |
108 | * @param p_kapman the instance of Kapman which collides with the Ghost |
109 | */ |
110 | void doActionOnCollision(Kapman* p_kapman); |
111 | |
112 | /** |
113 | * Initializes the Ghost speed from the Character speed. |
114 | */ |
115 | void initSpeedInc(); |
116 | |
117 | private: |
118 | |
119 | /** |
120 | * Makes the Ghost go up. |
121 | */ |
122 | void goUp(); |
123 | |
124 | /** |
125 | * Makes the Ghost go down. |
126 | */ |
127 | void goDown(); |
128 | |
129 | /** |
130 | * Makes the Ghost go to the right. |
131 | */ |
132 | void goRight(); |
133 | |
134 | /** |
135 | * Makes the Ghost go to the left. |
136 | */ |
137 | void goLeft(); |
138 | |
139 | signals: |
140 | |
141 | /** |
142 | * Emitted when the Kapman has lost a life. |
143 | */ |
144 | void lifeLost(); |
145 | |
146 | /** |
147 | * Emitted when the Ghost has been eaten. |
148 | * @param p_ghost the eaten Ghost (this) |
149 | */ |
150 | void ghostEaten(Ghost* p_ghost); |
151 | |
152 | /** |
153 | * Emitted when the Ghost has changed his state. |
154 | */ |
155 | void stateChanged(); |
156 | }; |
157 | |
158 | #endif |
159 | |
160 | |