/** * Where to insert <CODE>n</CODE>, based only on degree, in the current tower. In <CODE> * addField()</CODE> we further test to see if the floors above, and/or at, and/or below are * sub-/superfields. * * @param n The NumberField whose insertion index we are intersted in * @return The index where <CODE>n</CODE> should be inserted into <CODE>floors</CODE> * @see #floors */ private int findInsertionIndex(NumberField n) { int i = 0; for (i = 0; i < floors.size(); i++) { Floor f = (Floor) floors.get(i); if (f.getDegree() <= n.getDegree()) break; } return i; }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_building, container, false); getActivity().setTitle(mBuilding.getName()); mNameTextView = (TextView) v.findViewById(R.id.building_name); mNameTextView.setText(mBuilding.getName()); mOccupancyTextView = (TextView) v.findViewById(R.id.occupancy); mOccupancyTextView.setText("" + mBuilding.getOccupancy()); /* Draw Line Graph */ // int average = mBuilding.getCapacityAverage(); int averageCrowdValues = (int) (100 * (Math.random() * 10)); // List<Integer> todaysCrowdValues = mBuilding.getTodaysCrowdValues(); // List<Integer> rodCrowdValues = mBuilding.getRodCrowdValues(); // temporarily using random numbers List<Integer> todaysCrowdValues = new ArrayList<>(); List<Integer> rodCrowdValues = new ArrayList<>(); for (int i = 0; i < 12; i++) todaysCrowdValues.add((int) (100 * (Math.random() * 10))); for (int i = 0; i < 12; i++) rodCrowdValues.add((int) (100 * (Math.random() * 10))); drawLineChart(v, averageCrowdValues, todaysCrowdValues, rodCrowdValues); // Temporarily use fake numbers for best times mFirstBestTimeTextView = (TextView) v.findViewById(R.id.first_best_time_text_view); mFirstBestTimeTextView.setText("8am"); mSecondBestTimeTextView = (TextView) v.findViewById(R.id.second_best_time_text_view); mSecondBestTimeTextView.setText("1pm"); mThirdBestTimeTextView = (TextView) v.findViewById(R.id.third_best_time_text_view); mThirdBestTimeTextView.setText("7pm"); mFloorsLinearLayout = (LinearLayout) v.findViewById(R.id.floors_linear_layout); for (Floor f : mBuilding.getFloors()) { View listItemFloor = inflater.inflate(R.layout.list_item_floor, null, false); TextView floorNumberTextView = (TextView) listItemFloor.findViewById(R.id.floor_number_text_view); floorNumberTextView.setText("Floor " + f.getFloorNumber()); TextView floorOccupancyTextView = (TextView) listItemFloor.findViewById(R.id.floor_occupancy_text_view); floorOccupancyTextView.setText("" + f.getOccupancy()); mFloorsLinearLayout.addView(listItemFloor); } return v; }
/** * Add a field to this tower at the specified index * * @param i the index where to add <CODE>n</CODE> * @param n the field to add to this tower * @param eql if <CODE>true</CODE> specifies that <CODE>n</CODE> should be added to the * <I>floor</I> at index <CODE>i</CODE>; otherwise creates a new floor for <CODE>n</CODE> * and inserts it into the tower at <CODE>i</CODE>, bumping any subsequent floors up by 1 */ private void add(int i, boolean eql, NumberField n) { Floor f; if (eql) { f = (Floor) floors.get(i); f.add(n); } else { f = new Floor(n); f.add(n); floors.add(i, f); } }
public String callElevator(int currentFloor, String opt) { floor.selectOption(opt); String option = floor.getFloorOption(); if (option.equalsIgnoreCase("up")) { elevStatus = elevMove(currentFloor); } else if (option.equalsIgnoreCase("down")) { elevStatus = elevMove(currentFloor); } return elevStatus; }
private void initFloors() throws Exception { double y = 0; int numGroundFloors = 10; for (int i = numGroundFloors; i >= -1; --i) { if (i != 0) { Floor floor = new Floor(i); floor.setPosition(y); floors.put(FloorType.valueOf(i), floor); y += Floor.REAL_HEIGHT; } } }
public void updateCabin(Cabin cabin, double deltaTime) { if (deltaTime > 0.2) return; if (cabin.isOn()) { switch (cabin.getState()) { case MOVE: double vector = cabin.getVector(); int vectorUnit = (int) (vector / Math.abs(vector)); double motor = motorOutput * earthGravity * deltaTime; // Nm/s (weight) -> kgfm if (motor <= gravity) { logger.debug("motor is too weak or gravity is too strong."); motor = gravity; } Floor target = cabin.getTarget(); double leftVector = target.getPosition() - cabin.getPosition(); int leftVectorUnit = (int) (leftVector / Math.abs(leftVector)); double accel = motor / mass(cabin) * leftVectorUnit; if (Math.abs(cabin.getVelocity()) > 1) accel *= Math.abs(vector * 0.5) < Math.abs(leftVector) ? 1 : -1; // brake on half point if (Double.isNaN(accel)) { accel = vectorUnit; } // logger.debug(String.format("%f -> %f (%f) : %f",cabin.getPosition(), // target.getPosition(),vector,accel)); // logger.debug(String.format("%s->%d, %f, %f, // %f",cabin.getName(),target.getNum(),accel,leftVector,vector*0.5)); updateCabin(cabin, accel, deltaTime); if (Math.abs(leftVector) < CABIN_MOVE_THRESHOLD) { // arrive cabin.setPosition(target.getPosition()); cabin.stop(); // cabin.getQueue().remove(target); logger.debug(String.format("%s->%d done", cabin.getName(), target.getNum())); } break; case STOP: logger.info("cabin({}) arrived", cabin.getName()); for (Floor floor : floors.values()) { if (cabin.getPosition() == floor.getPosition()) { logger.debug("on {}", floor); Iterator<Passenger> it = cabin.getPassengers().iterator(); while (it.hasNext()) { Passenger p = it.next(); if (p.getDest().equals(floor.getNum())) { p.setState(Passenger.State.NO_WAIT); it.remove(); floor.getPassengers().add(p); } } cabin.getQueue().remove(floor); } } if (cabin.getQueue().size() > 0) cabin.move(); // to next queued floor break; } } }
public String elevMove(int currentFloor) { if (floor.getCurrentFloorNumber() > currentFloor) { elevStatus = "down"; } else if (floor.getCurrentFloorNumber() < currentFloor) { elevStatus = "up"; } floor.setCurrentFloorNumber(currentFloor); floor.openFloorDoor(); // opening floor door door.opendoor(); // opening elevator door floor.closeFloorDoor(); door.closedoor(); return elevStatus; }
// method to change floor public String changeFloor(int floorno) { panel.setSelectedFloor(floorno); if (getElevatorFloor() > panel.getSelectedFloor()) { elevStatus = "down"; } else if (getElevatorFloor() < panel.getSelectedFloor()) { elevStatus = "up"; } floor.setCurrentFloorNumber(panel.getSelectedFloor()); floor.openFloorDoor(); // opening floor door door.opendoor(); // opening elevator door floor.closeFloorDoor(); door.closedoor(); return elevStatus; }
public void draw(Canvas canvas) { mPaint.setColor(Color.rgb(0x0F, 0x4D, 0x8F)); canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint); for (Star s : mStars) { s.draw(canvas); } mFloor.draw(canvas); mCat.draw(canvas); mPaint.setTextSize(32); mPaint.setTextAlign(Paint.Align.LEFT); mPaint.setColor(Color.WHITE); canvas.drawText("" + mFloor.getDistance() + " nyans", 0, 32, mPaint); if (mSadTicks > 0) { mPaint.setTextSize(124); mPaint.setTextAlign(Paint.Align.CENTER); canvas.drawText(":(", mWidth / 2, mHeight / 2, mPaint); } }
public void update() { mFloor.update(); mCat.update(); mSadTicks--; if ((int) (Math.random() * 10) == 0) { mStars.add(new Star(this, (int) (Math.random() * mWidth), (int) (Math.random() * mHeight))); } for (int i = mStars.size() - 1; i >= 0; --i) { Star s = mStars.get(i); s.update(); if (s.getX() < -35) { mStars.remove(i); } } }
public void goingUp() { System.out.println("elevator going up" + floor.getNumber()); }
private void draw() { Renderer renderer = ui.getRenderer(); Graphics g = renderer.getGraphics(); int fsize = g.getFont().getSize(); JPanel target = ui.getDrawTarget(); g.setColor(Color.GRAY); g.fillRect(0, 0, target.getWidth(), target.getHeight()); Map<CabinType, Integer> xmap = new HashMap<CabinType, Integer>() { { this.put(CabinType.LEFT, Floor.PIXEL_WIDTH + 10); this.put(CabinType.RIGHT, Floor.PIXEL_WIDTH + 10 + Cabin.PIXEL_WIDTH + 30); } }; for (CabinType type : cabins.keySet()) { Integer x = xmap.get(type); Cabin cabin = cabins.get(type); int passengers = cabin.getPassengers().size(); double cabinY = cabin.getPosition() * REAL_TO_PIXEL_RATIO, cabinH = (double) cabin.PIXEL_HEIGHT, cabinW = (double) cabin.PIXEL_WIDTH; g.setColor(Color.WHITE); g.fillRect(x, (int) cabinY, (int) cabinW, (int) cabinH); g.setColor(Color.BLACK); g.drawRect(x, (int) cabinY, (int) cabinW, (int) cabinH); // cabin fullness g.drawString( passengers >= cabinLimitPeople ? passengers > cabinLimitPeople ? "초과" : "만원" : "", (int) (x + cabinW / 2.0 - fsize), (int) (cabinY + cabinH / 2.0 - fsize)); // passengers on cabin g.drawString( String.format("%d명", passengers), (int) (x + cabinW / 2.0 - fsize * 2.0 / 2.0), (int) (cabinY + cabinH / 2.0)); // cabin weight g.drawString(String.format("%.0fkg", mass(cabin)), x, (int) (cabinY + cabinH / 2.0 + fsize)); // cabin speed g.drawString( String.format("%.1fm/s", Math.abs(cabin.getVelocity())), x, (int) (cabinY + cabinH / 2.0 + fsize * 2.0)); } for (Floor floor : floors.values()) { int passengers = floor.getPassengers().size(); double floorY = floor.getPosition() * REAL_TO_PIXEL_RATIO; g.setFont(Font.getFont(Font.SANS_SERIF)); g.setColor(Color.WHITE); g.fillRect(1, (int) floorY, Floor.PIXEL_WIDTH, Floor.PIXEL_HEIGHT); g.setColor(Color.BLACK); g.drawRect(1, (int) floorY, Floor.PIXEL_WIDTH, Floor.PIXEL_HEIGHT); g.drawString(floor.getNum() + "층", 1, (int) floorY + 15); g.drawString( Integer.toString(passengers), (int) (1 + (double) (Floor.PIXEL_WIDTH) / 2.0 - (double) fsize / 2.0), (int) (floorY + (double) Floor.PIXEL_HEIGHT / 2.0)); } if (state >> 1 == CircumstanceType.FIRE.state()) { Floor firedFloor = (Floor) Circumstance.get(CircumstanceType.FIRE).getParameter("floor"); if (null != firedFloor) g.drawString( "화재", Floor.PIXEL_WIDTH / 2 - fsize, (int) (firedFloor.getPosition() * REAL_TO_PIXEL_RATIO + (double) Floor.PIXEL_HEIGHT / 2.0 + fsize * 2.0)); } renderer.flush(); }
public int getElevatorFloor() { return floor.getCurrentFloorNumber(); }
public void setFloor(int floorno) { floor.setCurrentFloorNumber(floorno); }