// Interface for the road component classes - Intersection and RoadSegment. // CSE143 Spring '01 // Homework 6 #ifndef _INTERSECTION_H #define _INTERSECTION_H #include "road_chunk.h" #include "position.h" const int Entry = 0; const int Exit = 1; int swapEntryExit(int entryOrExit); // Forward declaration to avoid circular #includes. class RoadSegment; // Intersection: models a simple road intersection. // Connects up to 8 road segments (objects of class RoadSegment), // two on each direction (N,S,E,W), one incoming traffic, one outgoing. // Controls traffic from each incoming road segment to outgoing segments. // This is a subclass of SimObject, so it supports basic simulation operations. class Intersection : public RoadChunk { public: // Construct an uninitialized intersection Intersection(); // Construct an intersection centered at the specified position Intersection(Position center); // Destructor: does NOT deallocate any of the segments, but does deallocate // the vehicle(s) currently in the intersection (if any). virtual ~Intersection(); // Draw the intersection on the screen. // Precondition: the intersection was initialized with a position. virtual void draw(GP142Display& gp); virtual void tick(); // Set the position of the intersection. // This must be done before any other operation (unless the position was // set using the constructor). // Precondition: the position was not set yet. virtual void setCenter(Position pos); // Connects the given road segment at the given direction, and updates the // intersection's dimensions accordingly. The argument entryOrExit should // be one of the constants ENTRY or EXIT, and specifies whether the segment // is an entry to the intersection or an exit from it. // Precondition: the intersection was positioned already. virtual void connectRoad(RoadSegment *roadSeg, Direction dir, int entryOrExit); // Returns the x or y coordinate at the intersection's border on the // specified direction. E.g. if dir = NORTH, returns the y value for the // northern border of the intersection; if dir = EAST, returns the x value // for the eastern border. virtual int Intersection::getBorder(Direction dir) const; // Returns the center of this intersection virtual Position getCenter() const; private: Position center; RoadSegment *segments[NumDirections][2]; // Road segments connected to this // intersection // Private copy constructor: prevents copying intersections. Intersection(const Intersection& other) {} // Private assinment operator: prevents assignment of Intersections. operator =(const Intersection& other) {} }; #endif // end of file