File indexing completed on 2024-02-18 04:03:23

0001 /*
0002     SPDX-FileCopyrightText: 2009 Mathias Kraus <k.hias@gmx.de>
0003     SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
0004     SPDX-FileCopyrightText: 2007-2008 Pierre-BenoƮt Besse <besse.pb@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef ARENA_H
0010 #define ARENA_H
0011 
0012 #include <QObject>
0013 
0014 #include "cell.h"
0015 
0016 #include <QList>
0017 
0018 class QPoint;
0019 class QPointF;
0020 class QString;
0021 
0022 /**
0023  * @brief This class represents the Arena of the game.
0024  */
0025 class Arena : public QObject
0026 {
0027     Q_OBJECT
0028 
0029 private:
0030     /** The number of rows of the Arena */
0031     QString m_strArenaName;
0032 
0033     /** The number of rows of the Arena */
0034     int m_nbRows;
0035 
0036     /** The number of columns of the Arena */
0037     int m_nbColumns;
0038 
0039     /** The Arena Cells */
0040     Cell** m_cells;
0041 
0042     /** The Arena Cells */
0043     Cell m_emptyCell;
0044 
0045     /** The Player position on the Arena */
0046     QList <QPointF> m_playerPosition;
0047 
0048 public:
0049 
0050     /**
0051       * Creates a new Arena instance.
0052       */
0053     Arena();
0054 
0055     /**
0056       * Deletes the Arena instance.
0057       */
0058     ~Arena() override;
0059 
0060     /**
0061       * Creates the Arena matrix.
0062       * @param p_nbRows the number of rows
0063       * @param p_nbColumns the number of columns
0064       */
0065     void init(const int p_nbRows, const int p_nbColumns);
0066 
0067     /**
0068       * Returns the Arean name.
0069       * @return the Arena name
0070       */
0071     QString getName () const;
0072 
0073     /**
0074       * Sets the Arena name
0075       * @param p_strArenaName the Arena name
0076       */
0077     void setName (const QString &p_strArenaName);
0078 
0079     /**
0080       * Sets the CellType of the Cell whose coordinates are given in parameters.
0081       * @param p_row the Cell row
0082       * @param p_column the Cell column
0083       * @param p_type the Cell type
0084       */
0085     void setCellType(const int p_row, const int p_column, const Granatier::Cell::Type p_type);
0086 
0087     /**
0088       * Sets the Element that is on the Cell whose coordinates are given in parameters.
0089       * @param p_row the Cell row
0090       * @param p_column the Cell column
0091       * @param p_element the Element that is on the Cell
0092       */
0093     void setCellElement(const int p_row, const int p_column, Element* p_element);
0094 
0095     /**
0096       * Removes the Element that is on the Cell whose coordinates are given in parameters.
0097       * @param p_row the Cell row
0098       * @param p_column the Cell column
0099       * @param p_element the Element that is on the Cell
0100       */
0101     void removeCellElement(const int p_row, const int p_column, Element* p_element);
0102 
0103     /**
0104       * Sets a player position on the arena.
0105       * @param p_position the player position
0106       */
0107     void addPlayerPosition(const QPointF &p_position);
0108 
0109     /**
0110       * Gets the player position on the arena.
0111       * @param p_player the player number
0112       * @return p_position the player position
0113       */
0114     QPointF getPlayerPosition(int p_player) const;
0115 
0116     /**
0117       * Gets the Cell at the given coordinates.
0118       * @param p_row the row index
0119       * @param p_column the column index
0120       * @return the Cell at the given row and column
0121       */
0122     Cell getCell(const int p_row, const int p_column) const;
0123 
0124     /**
0125       * Gets the coordinates of the given Cell as a QPoint.
0126       * @param p_cell the searched Cell
0127       * @return the row and column of the given Cell
0128       */
0129     QPoint getCoords(Cell* p_cell) const;
0130 
0131     /**
0132       * Gets the row index corresponding to the given y-coordinate.
0133       * @param p_y the y-coordinate to convert into row index
0134       * @return the row index corresponding to the given y-coordinate
0135       */
0136     int getRowFromY(const qreal p_y) const;
0137 
0138     /**
0139       * Gets the column index corresponding to the given x-coordinate.
0140       * @param p_x the x-coordinate to convert into column index
0141       * @return the column index corresponding to the given x-coordinate
0142       */
0143     int getColFromX(const qreal p_x) const;
0144 
0145     /**
0146       * Gets the number of columns of the Arena.
0147       * @return the number of columns
0148       */
0149     int getNbColumns() const;
0150 
0151     /**
0152       * Gets the number of rows of the Arena.
0153       * @return the number of rows
0154       */
0155     int getNbRows() const;
0156 };
0157 
0158 #endif