@Override public void mouseMoved(MouseEvent e) { List<GuiControl> controlList = new ArrayList<GuiControl>(); controlList.addAll(this.controlList); for (GuiControl c : controlList) c.mouseMoved(e); if (mapCache == null) return; int mapWidth = mapCache.length; int mapHeight = mapCache[0].length; int x = (int) (((e.getX() + scrollX) / zoom) / tileSize); int y = (int) (((e.getY() + scrollY) / zoom) / tileSize); if (x < 0 || x >= fieldHover.length || y < 0 || y >= fieldHover[x].length) return; Building[][] buildings = Client.instance.buildings; fieldHover = new boolean[mapWidth][mapHeight]; for (int x1 = x; x1 > x1 - 6 && x1 >= 0; x1--) { for (int y1 = y; y1 > y1 - 6 && y1 >= 0; y1--) { Building b = buildings[x1][y1]; if (b != null && b.getSizeX() + x1 > x && b.getSizeY() + y1 > y) { fieldHover[x1][y1] = true; return; } } } }
@Override protected String doInBackground(String... params) { String url = params[0]; ArrayList<Building> lcs = new ArrayList<Building>(); try { String webJSON = getJSONfromURL(url); Log.d("JSON", webJSON); Gson gson = new Gson(); JsonParser parser = new JsonParser(); JsonArray Jarray = parser.parse(webJSON).getAsJsonArray(); for (JsonElement obj : Jarray) { Building cse = gson.fromJson(obj, Building.class); Log.d("COURSE", cse.toString()); lcs.add(cse); } } catch (Exception e) { Log.e("nearestBuilding", "JSONPARSE:" + e.toString()); } values.clear(); values.addAll(lcs); return "Done!"; }
public void endTurn() { for (Building building : buildings) building.endTurn(); for (Army army : armies) army.endTurn(); if (king.getHitPoints() <= 0) { kingDead = true; if (lives-- <= 0) lose(); } }
public boolean canLevel(Building building) { Ressources cost = building.getLevelUpCost(); if (!canPay(cost)) return false; for (Research research : researchs) if (research.getType().getId() == ResearchType.BUILDINGSLEVEL) { return research.getLevel() > building.getLevel() + 1; } return false; }
private Geofence buildFenceFromBuilding(Building building) { return new Geofence.Builder() .setRequestId(building.getObjectId()) .setCircularRegion( building.getLocation().getLatitude(), building.getLocation().getLongitude(), 100) .setExpirationDuration(Geofence.NEVER_EXPIRE) .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT) .build(); }
// ----------------------------------------------------------------- // Draws this panel by requesting that each Building draw itself. // ----------------------------------------------------------------- public void paintComponent(Graphics page) { super.paintComponent(page); building1.draw(page); building2.draw(page); building3.draw(page); building4.draw(page); building5.draw(page); }
public BuildingConstructionStrategy(Building building, BuildingStateContext context) { GameApplicationFactory applicationFactory; applicationFactory = GameApplicationFactory.getInstance(); info = applicationFactory.getResourceInfo(); this.building = building; building.setImageName("underconstruction"); String type = building.getType(); requiredResources = info.getResourcesForThing(type); }
static final void fillActiveCallsWithEmpties( Building building) { // makes a call with default values for (int i = 0; i <= building.getCallLength() - 1; i++) { // populates the buildings call for the day Calls person = new Calls(); // creates call to build person.PopulateCalls(-1, -1, -1, -1, -1); // default values building.setActiveCallPosition(i, person); } }
@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; }
protected void goToRestaurant() { int restNumber; if (!goToWork || jobBuilding == null) { while (true) { restNumber = (int) (Math.random() * 7); if (restNumber >= 6) { bigState = BigState.goHome; return; } else if ((cityData.restaurants.get(restNumber)).isOpen()) break; } destinationBuilding = cityData.restaurants.get(restNumber); } else { destinationBuilding = jobBuilding; } if (destinationBuilding != currentBuilding) { System.out.println("Going to restaurant as " + desiredRole); GoToDestination(); personGui.DoGoToBuilding(destinationBuilding.buildingNumber); try { atBuilding.acquire(); } catch (InterruptedException e) { // Auto-generated catch block e.printStackTrace(); } currentBuilding = destinationBuilding; } Building restaurant = destinationBuilding; if (goToWork && !desiredRole.equals("Customer")) { if (desiredRole.equals("Host") && !restaurant.hasHost()) { personGui.DoGoIntoBuilding(); currentBuilding.EnterBuilding(this, desiredRole); return; } else if (restaurant.openToEmployee()) { if (desiredRole.equals("Waiter") || desiredRole.equals("Cook")) { personGui.DoGoIntoBuilding(); currentBuilding.EnterBuilding(this, desiredRole); return; } else if (desiredRole.equals("Cashier") && !restaurant.hasCashier()) { personGui.DoGoIntoBuilding(); currentBuilding.EnterBuilding(this, desiredRole); return; } } } // This is only reached if the person is unemployed if (desiredRole.equals("Customer") && restaurant.isOpen()) { personGui.DoGoIntoBuilding(); currentBuilding.EnterBuilding(this, desiredRole); bigState = BigState.waiting; return; } bigState = BigState.goHome; homeState = HomeState.onCouch; }
/** * Calculates whether certain Location is suitable for spawning a new Building (out of bounds, * overlapping) * * @param loc Location that should be checked * @return Boolean indicating elgibility to spawn new Building * @see Building */ public Boolean checkPositionElgibility(Location loc) { for (Building b : WorldManager.getInstance().getBuildings()) { if (loc.X() >= b.getPosition().X() - SimulationConfig.getBuildingSpriteWidth() && loc.X() <= b.getPosition().X() + SimulationConfig.getBuildingSpriteWidth() && loc.Y() >= b.getPosition().Y() - SimulationConfig.getBuildingSpriteHeight() && loc.Y() <= b.getPosition().Y() + SimulationConfig.getBuildingSpriteHeight()) return false; } return true; }
public Garage( int numberOfWindows, int length, int width, int numberOfCars, Flooring floorCovering) { super.setNumberOfFloors(1); super.setNumberOfWindows(numberOfWindows); this.length = length; this.width = width; this.numberOfCars = numberOfCars; this.floorCovering = floorCovering.name(); }
private static float getBuildingSelectionHeight(Building building) { int render_level = building.getRenderLevel(); switch (render_level) { case Building.RENDER_START: return building.getBuildingTemplate().getStartSelectionHeight(); case Building.RENDER_HALFBUILT: return building.getBuildingTemplate().getHalfbuiltSelectionHeight(); case Building.RENDER_BUILT: return building.getBuildingTemplate().getBuiltSelectionHeight(); default: throw new RuntimeException(); } }
public void newTurn() { if (kingDead) newKing(); for (Building building : buildings) building.newTurn(); for (Army army : armies) army.newTurn(); finished = false; try { player.newTurn(); } catch (Exception ex) { ex.printStackTrace(); System.out.println(name + " loses because he threw an exception."); lose(); } }
// TODO: fix this non-OO nastiness private int getAmount(Location location, GoodsType goodsType) { if (goodsType != null) { if (location instanceof Building) { Building building = (Building) location; ProductionInfo info = building.getProductionInfo(); return (info == null || info.getProduction() == null || info.getProduction().size() == 0) ? 0 : info.getProduction().get(0).getAmount(); } else if (location instanceof ColonyTile) { return ((ColonyTile) location).getTotalProductionOf(goodsType); } } return 0; }
protected void runSimulation(SimulationValues sim) { // method for running simulation System.out.println( "**********************************************************"); // separates elevators for (int i = 1; i <= getNumDays(); i++) { // number of days to be looped getTotalTime().clear(); // clears the total time on the elevator to start the day getResults().clear(); // clears the time on the elevator to start the day Building.fillActiveCallsWithEmpties( getBuilding()); // fills building with empty active calls that might be from the day // before CreateCalls.createCases( getNumCallsInDay(), getBuilding(), getDayCount()); // Creates the call from the text file in main intializeArrayElevators(); // intitalizes elevators Traffic.simulation( getMaxTime(), getTimeConstant(), getBuilding(), getArrayElevators(), sim); // runs simulation System.out.println("Advanced Elevator Day " + i + ":"); Outputs.printStandardOutput( sim.getResults(), sim, sim.getTotalTime()); // Outputs Advanced results setTimeConstant(0); // sets time constant at zero for next day setDayCount(getDayCount() + 1); // increases day count } }
public void onDrawFrame(GL10 gl) { // 清除深度缓冲与颜色缓冲 GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); double angradElevation = Math.toRadians(angdegElevation); // 仰角(弧度) double angradAzimuth = Math.toRadians(angdegAzimuth); // 方位角 cameraX = (float) (targetX + sightDis * Math.cos(angradElevation) * Math.cos(angradAzimuth)); cameraY = (float) (targetY + sightDis * Math.sin(angradElevation)); cameraZ = (float) (targetZ + sightDis * Math.cos(angradElevation) * Math.sin(angradAzimuth)); MatrixState.setCamera( // 设置camera位置 cameraX, // 人眼位置的X cameraY, // 人眼位置的Y cameraZ, // 人眼位置的Z targetX, // 人眼球看的点X targetY, // 人眼球看的点Y targetZ, // 人眼球看的点Z 0, // 头的朝向 1, 0); // 保护现场 MatrixState.pushMatrix(); MatrixState.translate(0, 0, -15); building.drawSelf(textureId); MatrixState.popMatrix(); }
@Override public void hurt(Entity source, int damage) { super.hurt(source, damage); // if (health <= 0) { // freezeTime = 30; // } }
/** * Method which adds a new Building to this City.buildings, with the specified BuildingType and * Resource production. * * @param buildingType * @param productionValue * @throws InvalidBuildingProductionTypeException * @throws DataSourceParseException */ private void addBuilding(int buildingType, int productionValue) throws InvalidBuildingProductionTypeException, DataSourceParseException { ArrayList<Building> buildings = this.getBuildings(); if (buildings == null) { buildings = new ArrayList<Building>(); } Building newBuilding = new Building(buildingType); Integer i = Integer.valueOf(productionValue); if (i == null || i.equals(null) || i.intValue() == 0) { // do nothing } else { newBuilding.setProductionType(productionValue); } buildings.add(newBuilding); this.setBuildings(buildings); }
@Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { Building current = buildings.get(i); Intent intent = new Intent( android.content.Intent.ACTION_VIEW, Uri.parse( "http://maps.google.com/maps?daddr=" + current.getLatitude() + "," + current.getLongitude())); startActivity(intent); return true; }
/** * Constructs the entity Room and initializes only the required attributes (i.e. the fields which * are neither nullable nor have a default value) * * @param _number The Roomnumber has not to be unique. It is an alternative name for the Room. * @param _building The Buildingname is unique and represents a location where the Room is. * @since Iteration2 */ Room(RelationManager manager, String _number, Building _building) { this.manager = manager; this._number = _number; this.fetched_number = true; this._building = _building; this.ref_building = _building.id(); this.fetched_building = true; }
public void render(Screen screen) { if (justDroppedTicks-- > 0 && localTeam == team) { screen.blit(areaBitmap, pos.x - radius, pos.y - radius - yOffs); } super.render(screen); }
public final void visitBuilding(final Building building) { visitSelectable( building_visitor, building, building.getPositionZ(), getBuildingSelectionRadius(building), getBuildingSelectionHeight(building)); }
public void removeBuilding(int i, int j) { if (tiles[i][j].getValue().equals("")) { JOptionPane.showMessageDialog(null, "There is no building here"); return; } if (tiles[i][j].value.contains("-")) { String tText = tiles[i][j].value; i = Integer.parseInt(tText.split("-")[0]); j = Integer.parseInt(tText.split("-")[1]); } int index; for (index = 0; index < bb.size(); index++) { if (bb.get(index).getText().split("-")[0].equals(tiles[i][j].value)) { break; } } String temp = bb.get(index).getText(); String[] parts = temp.split("-"); int newQ = Integer.parseInt(parts[1]) + 1; Building tB = bList.get(0); for (int b = 0; b < bList.size(); b++) { if (bList.get(b).getName().equals(tiles[i][j].value)) { tB = bList.get(b); break; } } for (int c = 0; c < tB.getQWidth(); c++) { for (int r = 0; r < tB.getQHeight(); r++) { if ((i + c + j + r) % 2 == 0) tiles[i + c][j + r].setBackground(new Color(102, 255, 51)); else tiles[i + c][j + r].setBackground(new Color(51, 204, 51)); tiles[i + c][j + r].setIcon(null); tiles[i + c][j + r].value = ""; bb.get(index).setText(parts[0] + "-" + newQ); } } }
@Override public void doAction(BuildingStateContext context) { // are there enough resources to finish construction ? boolean test = building.hasResourcesAvailable(requiredResources); if (test) { context.switchState(BuildingState.IDLE); } else { // //update the required resources int[] requirement = new int[requiredResources.length]; for (int key = 0; key < requiredResources.length; key++) { int required = requiredResources[key] - building.getAvailableResources(key); if (required > 0) { requiredResources[key] = required; } } // building.setRequiredResources(requiredResources); } }
public void use(Entity user) { if (money > 0) { isEmptying = true; if (user instanceof Player) { emptyingPlayer = (Player) user; } } else { super.use(user); } }
@Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { Building current = buildings.get(i); Intent intent = new Intent(HousingActivity.this, DialogActivity.class); intent.putExtra("name", current.getName()); intent.putExtra("monday", current.getMondayDate()); intent.putExtra("tuesday", current.getTuesdayDate()); intent.putExtra("wednesday", current.getWednesdayDate()); intent.putExtra("thursday", current.getThursdayDate()); intent.putExtra("friday", current.getFridayDate()); intent.putExtra("saturday", current.getSaturdayDate()); intent.putExtra("sunday", current.getSundayDate()); startActivity(intent); }
public void levelUp() { try { int lastLevel = level; super.levelUp(); if (lastLevel != level) { helth = (int) ((Math.pow(2.5, level - 1)) - Math.pow(2.0, level - 1) + (40 * level) + 40) - (maxHelth - helth); maxHelth = (int) ((Math.pow(2.5, level - 1)) - Math.pow(2.0, level - 1) + (40 * level) + 40); buildImages.clear(); costs.clear(); if (level >= 1) { MagicSpirit m = new MagicSpirit(null, null); m.level = level - 2; m.levelUp(); buildImages.add(GameRunner.getMagicSpirit()); costs.add(50); buildNames.add("Train " + m.firstName); Mage ma = new Mage(null, null); ma.level = level - 2; ma.levelUp(); buildImages.add(GameRunner.getMage()); costs.add(100); buildNames.add("Train " + ma.firstName); buildImages.add(ImageIO.read(new File("src/+1.png"))); costs.add((int) (Math.pow(3.4, level) + (300 * level) + 196.6)); buildNames.add("Level Up to gain better units"); buildImages.add(GameRunner.getAutoMine()); costs.add(0); buildNames.add("Automatically mine gold with any units that can this turn"); } if (level >= 2) { Summoner s = new Summoner(null, null); buildImages.add(GameRunner.getSummoner()); costs.add(100); buildNames.add("Train " + s.name + " to summon units into battle"); } if (level >= 3) { ArchMage am = new ArchMage(null, null); am.level = level - 4; am.levelUp(); buildImages.add(GameRunner.getArchMage()); costs.add(300); buildNames.add("Train " + am.firstName); } } } catch (Exception e) { LogHandling.logError("Can't add image " + e); } }
/* Place all motionless objects (fire stations, police offices, ambulance teams and refuges) @param fire An array to be filled with fire stations @param police An array to be filled with police offices @param ambulance An array to be filled with ambulance centres @param refuge An array to be filled with refuges @param allBuildings All buildings in the map @return All ordinary buildings */ public static Building[] placeMotionlessObjects( FireStation[] fire, PoliceOffice[] police, AmbulanceCenter[] ambulance, Refuge[] refuge, Building[] allBuildings) { List remaining = new ArrayList(); for (int i = 0; i < allBuildings.length; ++i) remaining.add(allBuildings[i]); Collections.shuffle(remaining); System.out.println("Placing " + ambulance.length + " ambulance centers"); Iterator it = remaining.iterator(); for (int i = 0; i < ambulance.length; ++i) { Building location = (Building) it.next(); it.remove(); AmbulanceCenter a = new AmbulanceCenter(location); a.setID(location.getID()); ambulance[i] = a; // writeFixedObjectData(out,TYPE_AMBULANCE_CENTER,i,location); } System.out.println("Placing " + fire.length + " fire stations"); for (int i = 0; i < fire.length; ++i) { Building location = (Building) it.next(); it.remove(); FireStation a = new FireStation(location); a.setID(location.getID()); fire[i] = a; // writeFixedObjectData(out,TYPE_FIRE_STATION,i,location); // System.out.print("."); } System.out.println("Placing " + police.length + " police stations"); for (int i = 0; i < police.length; ++i) { Building location = (Building) it.next(); it.remove(); PoliceOffice a = new PoliceOffice(location); a.setID(location.getID()); police[i] = a; // writeFixedObjectData(out,TYPE_POLICE_OFFICE,i,location); // System.out.print("."); } System.out.println("Placing " + refuge.length + " refuges"); for (int i = 0; i < refuge.length; ++i) { Building location = (Building) it.next(); it.remove(); Refuge a = new Refuge(location); a.setID(location.getID()); refuge[i] = a; // writeFixedObjectData(out,TYPE_REFUGE,i,location); // System.out.print("."); } // System.out.println(); return (Building[]) remaining.toArray(new Building[0]); }
public void tick() { super.tick(); if (--freezeTime > 0) return; if (--delayTicks > 0) return; if (!isCarried()) { // find target Set<Entity> entities = level.getEntities(pos.x - radius, pos.y - radius, pos.x + radius, pos.y + radius); Entity closest = null; double closestDist = 99999999.0f; for (Entity e : entities) { if (!(e instanceof Mob) || (e instanceof RailDroid && e.team == this.team) || e instanceof Bomb) continue; if (!((Mob) e).isNotFriendOf(this)) continue; final double dist = e.pos.distSqr(pos); Bullet bullet = new Bullet(this, pos.x, pos.y, 0); if (dist < radiusSqr && dist < closestDist && !isTargetBehindWall(e.pos.x, e.pos.y, bullet)) { closestDist = dist; closest = e; } } if (closest != null) { // shoot double invDist = 1.0 / Math.sqrt(closestDist); double yd = closest.pos.y - pos.y; double xd = closest.pos.x - pos.x; double angle = (Math.atan2(yd, xd) + Math.PI * 1.625); facing = (8 + (int) (angle / Math.PI * 4)) & 7; Bullet bullet = new Bullet( this, xd * invDist, yd * invDist, BULLET_DAMAGE * ((upgradeLevel + 1) / 2.f)); bullet.pos.y -= 10; level.addEntity(bullet); if (upgradeLevel > 0) { Bullet second_bullet = new Bullet( this, xd * invDist, yd * invDist, BULLET_DAMAGE * ((upgradeLevel + 1) / 2.f)); level.addEntity(second_bullet); if (facing == 0 || facing == 4) { bullet.pos.x -= 5; second_bullet.pos.x += 5; } } delayTicks = delay; } } }