-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassenger.cpp
105 lines (75 loc) · 2.23 KB
/
Passenger.cpp
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
#include "Passenger.h"
#include "AI.h"
class Train;
Passenger::Passenger(int stationIndex, QPoint pos, int shape) {
_shape = Shape(shape);
_trainIndex = -1;
_ticket = -1;
_stationIndex = stationIndex;
_position = pos;
AI::instance()->findFinalStations(stationIndex, shape, _finalStations);
setZValue(3);
}
void Passenger::paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget){
QPen pen;
pen.setColor(QColor(0, 0, 0));
pen.setWidth(1);
painter->setBrush(QBrush(QColor(0, 0, 0)));
pen.setJoinStyle(Qt::MiterJoin);
painter->setOpacity(1);
if (_trainIndex != -1) {
pen.setColor(QColor(255, 255, 255));
painter->setBrush(QBrush(QColor(255, 255, 255)));
painter->setOpacity(0.65);
}
painter->setPen(pen);
painter->setRenderHint(QPainter::Antialiasing);
if (_shape == SQUARE) {
painter->drawRect(_position.x(), _position.y(), PASSENGER_SIZE, PASSENGER_SIZE);
}
else if (_shape == TRIANGLE) {
QPolygonF _triangle = triangle(_position, PASSENGER_SIZE);
painter->drawPolygon(_triangle);
}
else if (_shape == CIRCLE) {
painter->drawEllipse(_position.x(), _position.y(), PASSENGER_SIZE, PASSENGER_SIZE);
}
else if (_shape == STAR) {
QPolygonF _star = star(_position, PASSENGER_SIZE);
painter->drawPolygon(_star);
}
else if (_shape == PENTAGON) {
QPolygonF _pentagon = pentagon(_position, PASSENGER_SIZE);
painter->drawPolygon(_pentagon);
}
else if (_shape == RHOMBUS) {
QPolygonF _rhombus = rhombus(_position, PASSENGER_SIZE);
painter->drawPolygon(_rhombus);
}
else if (_shape == CROSS) {
QPolygonF _cross = cross(_position, PASSENGER_SIZE);
painter->drawPolygon(_cross);
}
else if (_shape == DIAMOND) {
QPolygonF _diamond = diamond(_position, PASSENGER_SIZE);
painter->drawPolygon(_diamond);
}
}
QRectF Passenger::boundingRect() const{
return QRectF(_position.x(), _position.y(), PASSENGER_SIZE, PASSENGER_SIZE);
}
void Passenger::getOnTrain(int trainIndex){
_trainIndex = trainIndex;
_stationIndex = -1;
}
void Passenger::getOffTrain(int stationIndex){
_trainIndex = -1;
_stationIndex = stationIndex;
}
void Passenger::updateFinalStations(){
AI::instance()->findFinalStations(_stationIndex, _shape, _finalStations);
}
void Passenger::advance() {
}