-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleObserver.h
More file actions
48 lines (40 loc) · 1.43 KB
/
SimpleObserver.h
File metadata and controls
48 lines (40 loc) · 1.43 KB
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
#ifndef SimpleObserver_h
#define SimpleObserver_h
#include "ECObserver.h"
#include "ECGraphicViewImp.h"
#include <vector>
struct PassengerRequest {
int time;
int startFloor;
int targetFloor;
};
struct Passenger {
int startFloor;
int targetFloor;
};
class ElevatorSimulatorObserver : public ECObserver {
public:
ElevatorSimulatorObserver(ECGraphicViewImp &viewIn, const std::string &filename);
virtual void Update();
private:
void Draw(); // Helper function to draw the elevator and floors
void MoveElevator(); // Handle elevator movement logic
void StopElevator(); // Handle stopping at floors
void CreateRandomPassenger(); // Create a random passenger
void InitializeRequests(const std::string &filename);
void AddPassengerRequest(int time, int startFloor, int targetFloor);
ECGraphicViewImp &view;
int elevatorY; // Elevator's current Y position
int direction; // Direction of elevator: 1 for up, -1 for down, 0 for stopped
bool isMoving; // Is the elevator currently moving?
int currentFloor;
int targetFloor;
int simulationTime;
bool paused;
int elapsedTime;
int FindNearestPassengerFloor(int direction) const;
std::vector<Passenger> passengers;
std::vector<Passenger> cabinPassengers;
std::vector<PassengerRequest> predefinedRequests;
};
#endif