This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Structure
Matthew Pohlmann edited this page Jan 1, 2014
·
1 revision
####Description Base class for every building in SimCity201. Has its own GUI, and a panel for setup purposes.
####Class Signature
public abstract class Structure {}
####Data
int ID; // The Structure's unique ID assigned when created
StructurePanel panel; // The Structure's own panel for displaying the GUI/internals of this Structure
Point guiLocation; // The Structure's location in the main animation panel (in SimCity201)
Point entranceLocation; // The Structure's entrance location
Point deliveryLocation; // The Structure's location for truck deliveries
Point parkingLocation; /* The Structure's location for "parking cars" assuming they go into some kind of
underground parking garage */
CityTime morningShiftStart; // Start of the morning shift
CityTime morningShiftEnd; // End of the morning shift
CityTime afternoonShiftStart; // Start of the afternoon shift
CityTime closingTime; // The Structure's closing time
boolean isOpen;
boolean forceClosed;
BufferedImage openSprite;
BufferedImage closedSprite;
Rectangle rect;
static int INSTANCES = 0;
####Constructors
public Structure(int x, int y, int width, int height, int id, StructurePanel p) {
this(new Rect(x, y, width, height), p);
}
public Structure(Rectangle r, StructurePanel p) {
id = ++INSTANCES;
panel = p;
rect = r;
closedSprite = ArtMananger.getImage("...");
openSprite = ArtMananger.getImage("...");
}
####Methods
// Returns this Structure's unique ID
public int getID() {
return ID;
}
// Used to get a unique ID for a Structure
public static int getNextInstance() {
return INSTANCES + 1;
}
// Given an Intentions enum (from PersonAgent) will return the correct Role for purposes of assigning a Role
public abstract Role getRole(PersonAgent.Intention role);
// When clicked, this Structure's panel will be shown in the card layout of the main program
public void displayStructure() {
panel.displayBuildingPanel();
}
// Updates the time at this Structure. Used to tell people working there that it's time to close up
public abstract void updateTime(CityTime time);
// Sets this Structure's panel so it can be viewed when clicked
public void setStructurePanel(StructurePanel sp) {
panel = sp;
}
// Returns the location of this Structure in SimCity201
public Point getGuiLocation() {
return guiLocation;
}
// Returns the location of this Structure's entrance
public Point getEntranceLocation() {
return entranceLocation;
}
// Returns the location of this Structure's delivery ramp
public Point getDeliveryLocation() {
return deliveryLocation;
}
// Returns the location of this Structure's "Parking garage"
public Point getParkingLocation() {
return parkingLocation;
}
// Returns the time at which this Structure closes (if at all)
public CityTime getClosingTime() {
return closingTime;
}
// General-purpose function for printing to the terminal. Format: "Restaurant 2: Gained $100"
@Deprecated
protected void Do(String msg) {
StringBuffer output = new StringBuffer();
output.append("[");
output.append(this.getClass().getSimpleName());
output.append("] ");
output.append(this.id);
output.append(": ");
output.append(msg);
System.out.println(output.toString());
}
// A String representation of this Structure (i.e. Bank 1)
public String toString() {
StringBuffer output = new StringBuffer();
output.append(this.getClass().getSimpleName());
output.append(" ");
output.append(this.id);
return output.toString();
}
// Get the sprite to draw
public BufferedImage getSprite() {
return isOpen ? openSprite : closedSprite;
}
// Get the rect describing where and how big this building is
public Rectangle getRect() {
return rect;
}
// Force close this Structure
public void setForceClosed(boolean closed) {
forceClosed = closed;
}