1 | /* |
2 | * Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr> |
3 | * Copyright 2007-2008 Pierre-BenoƮt Besse <besse.pb@gmail.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 MAZE_H |
20 | #define MAZE_H |
21 | |
22 | #include "cell.h" |
23 | |
24 | #include <QObject> |
25 | #include <QList> |
26 | #include <QPoint> |
27 | |
28 | /** |
29 | * @brief This class represents the Maze of the game. |
30 | */ |
31 | class Maze : public QObject { |
32 | |
33 | Q_OBJECT |
34 | |
35 | private: |
36 | |
37 | /** The Cell coordinates where the Ghosts go back when they have been eaten */ |
38 | QPoint m_resurrectionCell; |
39 | |
40 | /** The number of rows of the Maze */ |
41 | int m_nbRows; |
42 | |
43 | /** The number of columns of the Maze */ |
44 | int m_nbColumns; |
45 | |
46 | /** The Maze Cells */ |
47 | Cell** m_cells; |
48 | |
49 | /** The initial number of Elements in the Maze (when the game has not started) */ |
50 | int m_totalNbElem; |
51 | |
52 | /** The number of remaining Elements in the Maze (when the game is running) */ |
53 | int m_nbElem; |
54 | |
55 | public: |
56 | |
57 | /** |
58 | * Creates a new Maze instance. |
59 | */ |
60 | Maze(); |
61 | |
62 | /** |
63 | * Deletes the Maze instance. |
64 | */ |
65 | ~Maze(); |
66 | |
67 | /** |
68 | * Creates the Maze matrix. |
69 | * @param p_nbRows the number of rows |
70 | * @param p_nbColumns the number of columns |
71 | */ |
72 | void init(const int p_nbRows, const int p_nbColumns); |
73 | |
74 | /** |
75 | * Sets the CellType of the Cell whose coordinates are given in parameters. |
76 | * @param p_row the Cell row |
77 | * @param p_column the Cell column |
78 | * @param p_type the Cell type |
79 | */ |
80 | void setCellType(const int p_row, const int p_column, const Cell::Type p_type); |
81 | |
82 | /** |
83 | * Sets the Element that is on the Cell whose coordinates are given in parameters. |
84 | * @param p_row the Cell row |
85 | * @param p_column the Cell column |
86 | * @param p_element the Element that is on the Cell |
87 | */ |
88 | void setCellElement(const int p_row, const int p_column, Element* p_element); |
89 | |
90 | /** |
91 | * Sets the cell on witch the ghosts resurrect from prey state |
92 | * @param p_resurrectionCell the cell on witch the ghosts resurrect |
93 | */ |
94 | void setResurrectionCell(QPoint p_resurrectionCell); |
95 | |
96 | /** |
97 | * Decrements the number of remaining Elements. |
98 | */ |
99 | void decrementNbElem(); |
100 | |
101 | /** |
102 | * Resets the number of remaining Elements to the initial number. |
103 | */ |
104 | void resetNbElem(); |
105 | |
106 | /** |
107 | * Gets the path, as a list of Cell coordinates, to go to the Ghost camp from the Cell whose coordinates are given in parameters. |
108 | * This algorithm has been made from the A* algorithm. |
109 | * @param p_row the row index of the starting Cell |
110 | * @param p_column the column index of the starting Cell |
111 | * @return a list of Cell coordinates to go to the Ghost camp |
112 | */ |
113 | QList<QPoint> getPathToGhostCamp(const int p_row, const int p_column) const; |
114 | |
115 | /** |
116 | * Gets the Cell at the given coordinates. |
117 | * @param p_row the row index |
118 | * @param p_column the column index |
119 | * @return the Cell at the given row and column |
120 | */ |
121 | Cell getCell(const int p_row, const int p_column) const; |
122 | |
123 | /** |
124 | * Gets the coordinates of the given Cell as a QPoint. |
125 | * @param p_cell the searched Cell |
126 | * @return the row and column of the given Cell |
127 | */ |
128 | QPoint getCoords(Cell* p_cell) const; |
129 | |
130 | /** |
131 | * Gets the row index corresponding to the given y-coordinate. |
132 | * @param p_y the y-coordinate to convert into row index |
133 | * @return the row index corresponding to the given y-coordinate |
134 | */ |
135 | int getRowFromY(const qreal p_y) const; |
136 | |
137 | /** |
138 | * Gets the column index corresponding to the given x-coordinate. |
139 | * @param p_x the x-coordinate to convert into column index |
140 | * @return the column index corresponding to the given x-coordinate |
141 | */ |
142 | int getColFromX(const qreal p_x) const; |
143 | |
144 | /** |
145 | * Gets the number of columns of the Maze. |
146 | * @return the number of columns |
147 | */ |
148 | int getNbColumns() const; |
149 | |
150 | /** |
151 | * Gets the number of rows of the Maze. |
152 | * @return the number of rows |
153 | */ |
154 | int getNbRows() const; |
155 | |
156 | /** |
157 | * Gets the number of remaining Elements still on the Maze. |
158 | * @return the number of remaining Elements |
159 | */ |
160 | int getNbElem() const; |
161 | |
162 | /** |
163 | * Gets the number of Elements initially on the Maze. |
164 | * @return the initial number of Elements |
165 | */ |
166 | int getTotalNbElem() const; |
167 | |
168 | /** |
169 | * Gets the cell on witch the ghosts resurects |
170 | * @return the cell on witch the ghosts resurects |
171 | */ |
172 | QPoint getResurrectionCell() const; |
173 | |
174 | signals: |
175 | |
176 | /** |
177 | * Emitted when all the elements on the Maze have been eaten. |
178 | */ |
179 | void allElementsEaten(); |
180 | }; |
181 | |
182 | #endif |
183 | |
184 | |