-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathball.h
140 lines (118 loc) · 2.78 KB
/
ball.h
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
#ifndef BALL_H
#define BALL_H
// File must include
#include <QVector>
#include <QPointF>
// Forward declaration
class CoreController;
/**
* @brief A class of a ball.
*/
class Ball
{
friend class CoreController;
public:
/**
* @brief Color of the ball.
*
* Currently there are 8 colors.
* @warning Orange and Brown don't have the correct pixmap.
*/
enum Color{Red = 0, Blue, Green, Yellow, Purple, White,
Orange, Brown, BadColor};
/**
* @brief State of the ball.
*
* Currently there are 6 states.
* Stable:
* Item is on a stable position.
* AlmostStable:
* Item will be on a stable position soon.
* UserMoving:
* Item is moved by the user.
* UserReleased:
* Item is released by the user.
* SystemMoving:
* Item is moved by the system.
* JustCreated:
* Item has just been created wating for additional operations.
*/
enum State{Stable, AlmostStable, UserMoving,
UserReleased, SystemMoving, JustCreated};
/**
* @brief Constructor with the color.
*/
Ball(Ball::Color theColor = Ball::Red);
/**
*@brief Set the color of the ball.
*/
inline void setColor(Ball::Color theColor)
{color = theColor;}
/**
*@brief Get the color of the ball.
*/
inline Ball::Color getColor()
{return color;}
/**
*@brief Set the state of the ball.
*/
inline void setState(Ball::State theState)
{state = theState;}
/**
*@brief Get the state of the ball.
*/
inline Ball::State getState()
{return state;}
/**
*@brief Set whether the ball is locked.
*/
inline void setLocked(bool isLocked)
{locked = isLocked;}
/**
*@brief Get whether the ball is locked.
*/
inline bool getLocked()
{return locked;}
/**
*@brief Set the position of the ball.
*/
inline void setPos(QPointF pos)
{position = pos;}
/**
*@brief Get the position of the ball.
*/
inline QPointF pos()
{return position;}
/**
*@brief Advance the ball, may change the position and state.
*
*@return Whether the state is changed.
*/
bool advance();
/**
*@brief Move the ball to the last position and change the state to stable.
*/
void moveToStablePos();
/**
*@brief Whether two balls have the same color.
*
*@param anotherBall Pointer of another ball.
*@return Whether two balls have the same color.
*/
bool sameColor(Ball* anotherBall)
{return color != BadColor &&
anotherBall &&
color == anotherBall->color;}
private:
// Color of the ball
Color color;
// State of the ball
State state;
// Whether the ball is locked
bool locked;
// Current position of the ball
QPointF position;
// Positions the ball should be later
QVector<QPointF> stopPositions;
};
#endif // BALL_H