1 | /* |
2 | * Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr> |
3 | * |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License as |
6 | * published by the Free Software Foundation; either version 2 of |
7 | * the License, or (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ |
17 | |
18 | #ifndef ELEMENT_H |
19 | #define ELEMENT_H |
20 | |
21 | #include <QObject> |
22 | |
23 | #include "maze.h" |
24 | |
25 | class Kapman; |
26 | |
27 | /** |
28 | * @brief This class describes the common characteristics and behaviour of any game Element (character or item). |
29 | */ |
30 | class Element : public QObject { |
31 | |
32 | Q_OBJECT |
33 | |
34 | public: |
35 | |
36 | /** The Element possible types */ |
37 | enum Type { |
38 | KAPMAN = 0, |
39 | GHOST = 1, |
40 | PILL = 2, |
41 | ENERGYZER = 3, |
42 | BONUS = 4 |
43 | }; |
44 | |
45 | protected: |
46 | |
47 | /** The Element type */ |
48 | Type m_type; |
49 | |
50 | /** The Element initial x-coordinate */ |
51 | qreal m_xInit; |
52 | |
53 | /** The Element initial y-coordinate */ |
54 | qreal m_yInit; |
55 | |
56 | /** The Element current x-coordinate */ |
57 | qreal m_x; |
58 | |
59 | /** The Element current y-coordinate */ |
60 | qreal m_y; |
61 | |
62 | /** The Maze the Element is on */ |
63 | Maze* m_maze; |
64 | |
65 | /** The Id of the Element */ |
66 | QString m_imageId; |
67 | |
68 | /** Points won when the Element is eaten */ |
69 | int m_points; |
70 | |
71 | public: |
72 | |
73 | /** |
74 | * Creates a new Element instance. |
75 | * @param p_x the initial x-coordinate |
76 | * @param p_y the initial y-coordinate |
77 | * @param p_maze the Maze the Element is on |
78 | */ |
79 | Element(qreal p_x, qreal p_y, Maze* p_maze); |
80 | |
81 | /** |
82 | * Deletes the Element instance. |
83 | */ |
84 | ~Element(); |
85 | |
86 | /** |
87 | * Computes an action on a collision with the Kapman. |
88 | * @param p_kapman the instance of Kapman which collides with the Element |
89 | */ |
90 | virtual void doActionOnCollision(Kapman* p_kapman); |
91 | |
92 | /** |
93 | * Gets the path to the Element image. |
94 | * @return the path to the Element image |
95 | */ |
96 | QString getImageId() const; |
97 | |
98 | /** |
99 | * Gets the value of the Element. |
100 | * @return the points won when the Element is eaten |
101 | */ |
102 | int getPoints() const; |
103 | |
104 | /** |
105 | * Gets the type of the Element. |
106 | * @return the Element type |
107 | */ |
108 | Element::Type getType() const; |
109 | |
110 | /** |
111 | * Sets the Element image. |
112 | * @param p_imageId the image to set |
113 | */ |
114 | void setImageId(const QString & p_imageId); |
115 | |
116 | /** |
117 | * Gets the Element x-coordinate. |
118 | * @return the x-coordinate |
119 | */ |
120 | qreal getX() const; |
121 | |
122 | /** |
123 | * Gets the Element y-coordinate. |
124 | * @return the y-coordinate |
125 | */ |
126 | qreal getY() const; |
127 | |
128 | /** |
129 | * Sets the Element x-coordinate to the given value |
130 | * @param p_x the x-coordinate to set |
131 | */ |
132 | void setX(qreal p_x); |
133 | |
134 | /** |
135 | * Sets the Element y-coordinate to the given value |
136 | * @param p_y the y-coordinate to set |
137 | */ |
138 | void setY(qreal p_y); |
139 | |
140 | /** |
141 | * Initializes Element x-coordinate and y-coordinate with |
142 | * initial values |
143 | */ |
144 | void initCoordinate(); |
145 | |
146 | signals: |
147 | |
148 | /** |
149 | * Emitted on Element move. |
150 | * @param p_x the new x-coordinate |
151 | * @param p_y the new y-coordinate |
152 | */ |
153 | void moved(qreal p_x, qreal p_y); |
154 | }; |
155 | |
156 | #endif |
157 | |
158 | |