File: maze.h

package info (click to toggle)
kapman 4:20.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 3,588 kB
  • sloc: cpp: 2,793; xml: 208; makefile: 8; sh: 2
file content (184 lines) | stat: -rw-r--r-- 5,190 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
 * Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
 * Copyright 2007-2008 Pierre-BenoƮt Besse <besse.pb@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef MAZE_H
#define MAZE_H

#include "cell.h"

#include <QObject>
#include <QList>
#include <QPoint>

/**
 * @brief This class represents the Maze of the game.
 */
class Maze : public QObject
{

    Q_OBJECT

private:

    /** The Cell coordinates where the Ghosts go back when they have been eaten */
    QPoint m_resurrectionCell;

    /** The number of rows of the Maze */
    int m_nbRows;

    /** The number of columns of the Maze */
    int m_nbColumns;

    /** The Maze Cells */
    Cell **m_cells;

    /** The initial number of Elements in the Maze (when the game has not started) */
    int m_totalNbElem;

    /** The number of remaining Elements in the Maze (when the game is running) */
    int m_nbElem;

public:

    /**
     * Creates a new Maze instance.
     */
    Maze();

    /**
     * Deletes the Maze instance.
     */
    ~Maze() override;

    /**
     * Creates the Maze matrix.
     * @param p_nbRows the number of rows
     * @param p_nbColumns the number of columns
     */
    void init(const int p_nbRows, const int p_nbColumns);

    /**
     * Sets the CellType of the Cell whose coordinates are given in parameters.
     * @param p_row the Cell row
     * @param p_column the Cell column
     * @param p_type the Cell type
     */
    void setCellType(const int p_row, const int p_column, const Cell::Type p_type);

    /**
     * Sets the Element that is on the Cell whose coordinates are given in parameters.
     * @param p_row the Cell row
     * @param p_column the Cell column
     * @param p_element the Element that is on the Cell
     */
    void setCellElement(const int p_row, const int p_column, Element *p_element);

    /**
     * Sets the cell on witch the ghosts resurrect from prey state
     * @param p_resurrectionCell the cell on witch the ghosts resurrect
     */
    void setResurrectionCell(QPoint p_resurrectionCell);

    /**
     * Decrements the number of remaining Elements.
     */
    void decrementNbElem();

    /**
     * Resets the number of remaining Elements to the initial number.
     */
    void resetNbElem();

    /**
     * Gets the path, as a list of Cell coordinates, to go to the Ghost camp from the Cell whose coordinates are given in parameters.
     * This algorithm has been made from the A* algorithm.
     * @param p_row the row index of the starting Cell
     * @param p_column the column index of the starting Cell
     * @return a list of Cell coordinates to go to the Ghost camp
     */
    QList<QPoint> getPathToGhostCamp(const int p_row, const int p_column) const;

    /**
     * Gets the Cell at the given coordinates.
     * @param p_row the row index
     * @param p_column the column index
     * @return the Cell at the given row and column
     */
    Cell getCell(const int p_row, const int p_column) const;

    /**
     * Gets the coordinates of the given Cell as a QPoint.
     * @param p_cell the searched Cell
     * @return the row and column of the given Cell
     */
    QPoint getCoords(Cell *p_cell) const;

    /**
     * Gets the row index corresponding to the given y-coordinate.
     * @param p_y the y-coordinate to convert into row index
     * @return the row index corresponding to the given y-coordinate
     */
    int getRowFromY(const qreal p_y) const;

    /**
     * Gets the column index corresponding to the given x-coordinate.
     * @param p_x the x-coordinate to convert into column index
     * @return the column index corresponding to the given x-coordinate
     */
    int getColFromX(const qreal p_x) const;

    /**
     * Gets the number of columns of the Maze.
     * @return the number of columns
     */
    int getNbColumns() const;

    /**
     * Gets the number of rows of the Maze.
     * @return the number of rows
     */
    int getNbRows() const;

    /**
     * Gets the number of remaining Elements still on the Maze.
     * @return the number of remaining Elements
     */
    int getNbElem() const;

    /**
     * Gets the number of Elements initially on the Maze.
     * @return the initial number of Elements
     */
    int getTotalNbElem() const;

    /**
     * Gets the cell on witch the ghosts resurrects
     * @return the cell on witch the ghosts resurrects
     */
    QPoint getResurrectionCell() const;

Q_SIGNALS:

    /**
     * Emitted when all the elements on the Maze have been eaten.
     */
    void allElementsEaten();
};

#endif