-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrain.h
81 lines (68 loc) · 2.16 KB
/
Train.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
#pragma once
#include "Object.h"
#include "Utils.h"
#include <QPainter>
class Train : public Object {
enum Direction{FORWARD, BACKWARD};
enum State{STOPPED, MOVING};
private:
// Graphic elements
QRect* _trainRect;
QColor _color;
QPainterPath _path;
QPainterPath _oldPath;
int _rotationAngle;
float _speedMultiplier;
// Logic elements
Direction _direction;
State _state;
float _increment;
float _length;
int _passengers;
int _lineIndex;
int _currentStation;
int _nextStation;
bool _circular;
bool _deleting;
int _index;
float _distanceFromStation;
bool _seats[6]; // false = occupied, true = available
QPoint _oldPos;
public:
Train(int lineIndex, int index, QPoint centerPoint, QPainterPath linePath, int stationIndex);
// Metodi virtuali reimplementati
void paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget);
QRectF boundingRect() const;
virtual void advance();
// Setters
void setPath(QPainterPath linePath) { _path = linePath; }
void setCircular(bool flag) { _circular = flag; }
void setState(int state) { _state = State(state); }
void setCurrentStation(int index) { _currentStation = index; }
void setNextStation(int index) { _nextStation = index; }
void setDistanceFromStation(float distance) { _distanceFromStation = distance; }
void setOldPos(QPoint p) { _oldPos = p; }
void setTrainPosition(QPoint p);
void setDeleting(bool flag) { _deleting = flag; }
// Getter
int lineIndex() { return _lineIndex; }
int index() { return _index; }
QPoint position() { return _trainRect->center(); }
int rotationAngle() { return _rotationAngle; }
int passengers() { return _passengers; }
int state() { return int(_state); }
int currentStation() { return _currentStation; }
int nextStation() { return _nextStation; }
int direction() { return int(_direction); }
float distanceFromStation() { return _distanceFromStation; }
bool circular() { return _circular; }
bool deleting() { return _deleting; }
// Utility
QPoint passengerPos(int ticket);
void incrementPassengers(int passengerTicket);
void decrementPassengers(int passengerTicket);
int firstSeatAvailable();
void resetPos() { setTrainPosition(_oldPos); }
};