File indexing completed on 2024-12-08 06:45:42
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr> 0003 SPDX-FileCopyrightText: 2007-2008 Pierre-BenoƮt Besse <besse.pb@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef MAZE_H 0009 #define MAZE_H 0010 0011 #include "cell.h" 0012 0013 #include <QList> 0014 #include <QObject> 0015 #include <QPoint> 0016 0017 /** 0018 * @brief This class represents the Maze of the game. 0019 */ 0020 class Maze : public QObject 0021 { 0022 Q_OBJECT 0023 0024 private: 0025 /** The Cell coordinates where the Ghosts go back when they have been eaten */ 0026 QPoint m_resurrectionCell; 0027 0028 /** The number of rows of the Maze */ 0029 int m_nbRows; 0030 0031 /** The number of columns of the Maze */ 0032 int m_nbColumns; 0033 0034 /** The Maze Cells */ 0035 Cell **m_cells; 0036 0037 /** The initial number of Elements in the Maze (when the game has not started) */ 0038 int m_totalNbElem; 0039 0040 /** The number of remaining Elements in the Maze (when the game is running) */ 0041 int m_nbElem; 0042 0043 public: 0044 /** 0045 * Creates a new Maze instance. 0046 */ 0047 Maze(); 0048 0049 /** 0050 * Deletes the Maze instance. 0051 */ 0052 ~Maze() override; 0053 0054 /** 0055 * Creates the Maze matrix. 0056 * @param p_nbRows the number of rows 0057 * @param p_nbColumns the number of columns 0058 */ 0059 void init(const int p_nbRows, const int p_nbColumns); 0060 0061 /** 0062 * Sets the CellType of the Cell whose coordinates are given in parameters. 0063 * @param p_row the Cell row 0064 * @param p_column the Cell column 0065 * @param p_type the Cell type 0066 */ 0067 void setCellType(const int p_row, const int p_column, const Cell::Type p_type); 0068 0069 /** 0070 * Sets the Element that is on the Cell whose coordinates are given in parameters. 0071 * @param p_row the Cell row 0072 * @param p_column the Cell column 0073 * @param p_element the Element that is on the Cell 0074 */ 0075 void setCellElement(const int p_row, const int p_column, Element *p_element); 0076 0077 /** 0078 * Sets the cell on witch the ghosts resurrect from prey state 0079 * @param p_resurrectionCell the cell on witch the ghosts resurrect 0080 */ 0081 void setResurrectionCell(QPoint p_resurrectionCell); 0082 0083 /** 0084 * Decrements the number of remaining Elements. 0085 */ 0086 void decrementNbElem(); 0087 0088 /** 0089 * Resets the number of remaining Elements to the initial number. 0090 */ 0091 void resetNbElem(); 0092 0093 /** 0094 * Gets the path, as a list of Cell coordinates, to go to the Ghost camp from the Cell whose coordinates are given in parameters. 0095 * This algorithm has been made from the A* algorithm. 0096 * @param p_row the row index of the starting Cell 0097 * @param p_column the column index of the starting Cell 0098 * @return a list of Cell coordinates to go to the Ghost camp 0099 */ 0100 QList<QPoint> getPathToGhostCamp(const int p_row, const int p_column) const; 0101 0102 /** 0103 * Gets the Cell at the given coordinates. 0104 * @param p_row the row index 0105 * @param p_column the column index 0106 * @return the Cell at the given row and column 0107 */ 0108 Cell getCell(const int p_row, const int p_column) const; 0109 0110 /** 0111 * Gets the coordinates of the given Cell as a QPoint. 0112 * @param p_cell the searched Cell 0113 * @return the row and column of the given Cell 0114 */ 0115 QPoint getCoords(Cell *p_cell) const; 0116 0117 /** 0118 * Gets the row index corresponding to the given y-coordinate. 0119 * @param p_y the y-coordinate to convert into row index 0120 * @return the row index corresponding to the given y-coordinate 0121 */ 0122 int getRowFromY(const qreal p_y) const; 0123 0124 /** 0125 * Gets the column index corresponding to the given x-coordinate. 0126 * @param p_x the x-coordinate to convert into column index 0127 * @return the column index corresponding to the given x-coordinate 0128 */ 0129 int getColFromX(const qreal p_x) const; 0130 0131 /** 0132 * Gets the number of columns of the Maze. 0133 * @return the number of columns 0134 */ 0135 int getNbColumns() const; 0136 0137 /** 0138 * Gets the number of rows of the Maze. 0139 * @return the number of rows 0140 */ 0141 int getNbRows() const; 0142 0143 /** 0144 * Gets the number of remaining Elements still on the Maze. 0145 * @return the number of remaining Elements 0146 */ 0147 int getNbElem() const; 0148 0149 /** 0150 * Gets the number of Elements initially on the Maze. 0151 * @return the initial number of Elements 0152 */ 0153 int getTotalNbElem() const; 0154 0155 /** 0156 * Gets the cell on witch the ghosts resurrects 0157 * @return the cell on witch the ghosts resurrects 0158 */ 0159 QPoint getResurrectionCell() const; 0160 0161 Q_SIGNALS: 0162 0163 /** 0164 * Emitted when all the elements on the Maze have been eaten. 0165 */ 0166 void allElementsEaten(); 0167 }; 0168 0169 #endif