File: element.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 (158 lines) | stat: -rw-r--r-- 3,516 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
/*
 * Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
 *
 * 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 ELEMENT_H
#define ELEMENT_H

#include <QObject>

#include "maze.h"

class Kapman;

/**
 * @brief This class describes the common characteristics and behaviour of any game Element (character or item).
 */
class Element : public QObject
{

    Q_OBJECT

public:

    /** The Element possible types */
    enum Type {
        KAPMAN = 0,
        GHOST = 1,
        PILL = 2,
        ENERGYZER = 3,
        BONUS = 4
    };

protected:

    /** The Element type */
    Type m_type;

    /** The Element initial x-coordinate */
    qreal m_xInit;

    /** The Element initial y-coordinate */
    qreal m_yInit;

    /** The Element current x-coordinate */
    qreal m_x;

    /** The Element current y-coordinate */
    qreal m_y;

    /** The Maze the Element is on */
    Maze *m_maze;

    /** The Id of the Element */
    QString m_imageId;

    /** Points won when the Element is eaten */
    int m_points;

public:

    /**
     * Creates a new Element instance.
     * @param p_x the initial x-coordinate
     * @param p_y the initial y-coordinate
     * @param p_maze the Maze the Element is on
     */
    Element(qreal p_x, qreal p_y, Maze *p_maze);

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

    /**
     * Computes an action on a collision with the Kapman.
     * @param p_kapman the instance of Kapman which collides with the Element
     */
    virtual void doActionOnCollision(Kapman *p_kapman);

    /**
     * Gets the path to the Element image.
     * @return the path to the Element image
     */
    QString getImageId() const;

    /**
     * Gets the value of the Element.
     * @return the points won when the Element is eaten
     */
    int getPoints() const;

    /**
     * Gets the type of the Element.
     * @return the Element type
     */
    Element::Type getType() const;

    /**
     * Sets the Element image.
     * @param p_imageId the image to set
     */
    void setImageId(const QString &p_imageId);

    /**
     * Gets the Element x-coordinate.
     * @return the x-coordinate
     */
    qreal getX() const;

    /**
     * Gets the Element y-coordinate.
     * @return the y-coordinate
     */
    qreal getY() const;

    /**
     * Sets the Element x-coordinate to the given value
     * @param p_x the x-coordinate to set
     */
    void setX(qreal p_x);

    /**
     * Sets the Element y-coordinate to the given value
     * @param p_y the y-coordinate to set
     */
    void setY(qreal p_y);

    /**
    * Initializes Element x-coordinate and y-coordinate with
    * initial values
    */
    void initCoordinate();

Q_SIGNALS:

    /**
     * Emitted on Element move.
     * @param p_x the new x-coordinate
     * @param p_y the new y-coordinate
     */
    void moved(qreal p_x, qreal p_y);
};

#endif