public void addPipe() { int r = config.random(0, 7); float dy = r * 10; r = config.random(0, 1); if (r == 0) { dy = -dy; } Pipe pipe1 = new Pipe(Atlas.findRegion("pipe1"), bird, true); pipe1.setZIndex(1); float x = Flappybird.VIEWPORT.x; float y = (Flappybird.VIEWPORT.y - config.KlandHeight) / 2 + config.KlandHeight + config.KholeBetwenPipe / 2; pipe1.setPosition(x, y + dy); Pipe pipe2 = new Pipe(Atlas.findRegion("pipe2"), bird, false); pipe2.setZIndex(1); y = (Flappybird.VIEWPORT.y - config.KlandHeight) / 2 + config.KlandHeight - pipe2.getHeight() - config.KholeBetwenPipe / 2; pipe2.setPosition(x, y + dy); stage.addActor(pipe1); stage.addActor(pipe2); labelScore.setZIndex(pipe1.getZIndex()); land.setZIndex(pipe2.getZIndex()); bird.setZIndex(pipe2.getZIndex()); }
public boolean runScript() throws Exception { int fuel = 0; int org = 0; int equip = 0; int holds = Swath.ship.holds(); // Set product amounts switch (m_type.getCurrentChoice()) { case Swath.FUEL_ORE: fuel = holds; break; case Swath.ORGANICS: org = holds; break; case Swath.EQUIPMENT: equip = holds; break; } // Loop while (true) { Land.exec(m_planet.getInteger()); TakeLeaveProducts.exec(fuel, org, equip); LiftOff.exec(); Trade.exec(-fuel, -org, -equip); } }
public void checkDrag() { Land land = (Land) getWorld(); if (Greenfoot.mouseDragged(this)) { MouseInfo mouse = Greenfoot.getMouseInfo(); if (cost <= land.getMoneyAmount()) { if (hasTurret == false) { land.removeObjects(land.getObjects(Radius.class)); machineGun = new MachineGun_Turret(); getWorld().addObject(machineGun, mouse.getX(), mouse.getY()); hasTurret = true; land.setMoneyCounter(-cost); } } if (hasTurret == true) machineGun.setLocation(mouse.getX(), mouse.getY()); } if ((Greenfoot.mouseDragEnded(null)) && (machineGun != null)) { grid(); if (machineGun.checkLocation()) { machineGun.placed = true; hasTurret = false; machineGun = null; } else { land.removeObject(machineGun); machineGun = null; land.setMoneyCounter(cost); hasTurret = false; } } }
private void drawLand() { // Das aktuell ausgewaehlte Land laden. Land land = countries[this.countrySelector.getSelectedIndex()]; label[1].setText(land.getName()); label[3].setText(land.getHauptstadt()); if (exactly) { label[5].setText(Long.toString(land.getEinwohner())); label[7].setText(Long.toString(land.getFlaeche())); } else { label[5].setText(this.formatieren(land.getEinwohner())); label[7].setText(this.formatieren(land.getFlaeche())); } label[9].setText( new String(Math.round((double) land.getEinwohner() / (double) land.getFlaeche()) + "")); }
public void grid() { Land land = (Land) getWorld(); int maxWidthNum = land.getWidth() / 50; int maxHeightNum = land.getHeight() / 50; int x = 0; int y = 0; int x1 = 0; int x2 = 0; int y1 = 0; int y2 = 0; int xAdd = 0; int yAdd = 0; if (land.map == 1) { x1 = 25; x2 = -25; y1 = 0; y2 = -50; xAdd = 0; yAdd = 25; } else if (land.map == 2 || land.map == 3) { x1 = 0; x2 = -50; y1 = 25; y2 = -25; xAdd = 25; yAdd = 0; } for (int i = 1; i < maxWidthNum; i++) { if ((((i * 50) - (machineGun.getX())) <= x1) && (((i * 50) - (machineGun.getX())) >= x2)) x = (i * 50); } for (int i = 1; i < maxHeightNum; i++) { if ((((i * 50) - (machineGun.getY())) <= y1) && (((i * 50) - (machineGun.getY())) >= y2)) y = (i * 50); } machineGun.setLocation(x + xAdd, y + yAdd); }
public void onEntityDamage(EntityDamageEvent event) { DamageCause cause = event.getCause(); ArrayList<Integer> ids = iCoLand.landMgr.getLandIds(event.getEntity().getLocation()); if (cause.equals(DamageCause.FIRE) || cause.equals(DamageCause.FIRE_TICK)) { for (Integer id : ids) { Land land = iCoLand.landMgr.getLandById(id); if (land.hasAddon("nofire")) { event.setCancelled(true); } } if (ids.size() == 0 && !Config.unclaimedLandCanBurn) { event.setCancelled(true); } } else if (cause.equals(DamageCause.BLOCK_EXPLOSION) || cause.equals(DamageCause.ENTITY_EXPLOSION)) { for (Integer id : ids) { Land land = iCoLand.landMgr.getLandById(id); if (land.hasAddon("noboom")) { event.setCancelled(true); } } if (ids.size() == 0 && !Config.unclaimedLandCanBoom) { event.setCancelled(true); } } else if (event instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent castEvent = (EntityDamageByEntityEvent) event; if ((castEvent.getDamager() instanceof Player) && (castEvent.getEntity() instanceof Player)) { for (Integer id : ids) { if (iCoLand.landMgr.getLandById(id).hasAddon("nopvp")) event.setCancelled(true); } } } }
@FXML public void loadGame(ActionEvent event) { Stage newStage = new Stage(); if (event.getSource() == loadButton) { loadData = LoadSaveGame.load(); if (loadData != null) { Controller.loaded = true; GameController.numPasses = (int) Controller.loadData.get(4); // GameController.landButton.setDisable(true); try { gameRoot = FXMLLoader.load(getClass().getResource("UIFiles/MainMap.fxml")); gameScene = new Scene(gameRoot); Parent startWindow = FXMLLoader.load(getClass().getResource("UIFiles/playerStart.fxml")); startScene = new Scene(startWindow); } catch (IOException e) { e.printStackTrace(); } newStage.setScene(gameScene); newStage.setTitle("Game Screen"); newStage.show(); GridPane grid = (GridPane) gameRoot; landPlots = (Land[][]) loadData.get(0); level = (String) loadData.get(1); players = (Player[]) loadData.get(3); for (Player player : players) { for (Land land : player.getLandOwned()) { landPlots[land.getCol()][land.getRow()].setOwner(player); } } if (grid != null) { for (Land[] landArray : landPlots) { for (Land land : landArray) { if (land.isOwned()) { Player owner = land.getOwner(); Rectangle color = new Rectangle(); color.setFill(Color.valueOf(owner.getColor())); color.setHeight(25); color.setWidth(25); color.setOpacity(1); GridPane.setHalignment(color, HPos.LEFT); GridPane.setValignment(color, VPos.TOP); grid.add(color, land.getCol(), land.getRow()); if (land.hasMule()) { Image mulePic = new Image("gameConfig/UIFiles/Media/aMule.png"); ImageView muleView = new ImageView(); muleView.setImage(mulePic); muleView.setFitWidth(50); muleView.setPreserveRatio(true); GridPane.setHalignment(muleView, HPos.LEFT); GridPane.setValignment(muleView, VPos.CENTER); muleView.setId(String.valueOf(land.getCol()) + String.valueOf(land.getRow())); grid.add(muleView, land.getCol(), land.getRow()); } } } } } numPlayer = players.length; Turns turns = new Turns(players); turns.setRounds((int) loadData.get(5)); GameController.beginTurn(); } else { Controller.loaded = false; } } }
@FXML private void playerSetup(ActionEvent e) throws NullPointerException { Stage newStage = new Stage(); // try { if (e.getSource() == nextButton2) { String name = playerName.getText(); String race = raceChoice.getSelectionModel().getSelectedItem().toString(); if (race.length() > 8) { race = race.toUpperCase().substring(0, race.indexOf(" ")); } else { race = race.toUpperCase(); } Player.Race r = Player.Race.valueOf(race); Color color = colorPick.getValue(); // creating Player Player p = new Player(name, r, color.toString()); players[count - 1] = p; if (players[players.length - 1] != null) { // when players array is full, begins game turns Turns gameTurns = new Turns(players); } if (name.equals("")) { // check if player entered a name Launcher.primaryStage.setScene(Launcher.errorMessage); Launcher.primaryStage.setTitle("Enter name!"); } else if (playerColors.contains(color)) { Launcher.primaryStage.setScene(Launcher.errorMessage); Launcher.primaryStage.setTitle("Choose new color!"); } else { playerColors.add(color); if (count == 1) { // if only one player config screen has been shown go to player 2 Launcher.primaryStage.setTitle("Player 2 Configuration"); Launcher.primaryStage.toFront(); playerName.clear(); raceChoice.getSelectionModel().clearSelection(); colorPick.setValue(Color.WHITE); count += 1; } else if (count == 2) { if (count == numPlayer) { // if user selected only 2 players then show game screen Launcher.primaryStage.hide(); try { gameRoot = FXMLLoader.load(getClass().getResource("UIFiles/MainMap.fxml")); gameScene = new Scene(gameRoot); Parent startWindow = FXMLLoader.load(getClass().getResource("UIFiles/playerStart.fxml")); startScene = new Scene(startWindow); } catch (Exception e1) { e1.printStackTrace(); } newStage.setScene(gameScene); newStage.setTitle("Game Screen"); newStage.show(); GameController.beginTurn(); // creates land array landPlots = new Land[9][5]; // 5 rows, 9 columns, col = i, row = j int count = 0; for (int i = 0; i < landPlots.length; i++) { for (int j = 0; j < landPlots[0].length; j++) { Land newLand = new Land(i, j); newLand.setType(landTypes[count]); landPlots[i][j] = newLand; count++; } } } else { // if user selected more than 2 players, go on to player 3 config Launcher.primaryStage.setTitle("Player 3 Configuration"); Launcher.primaryStage.toFront(); playerName.clear(); raceChoice.getSelectionModel().clearSelection(); colorPick.setValue(Color.WHITE); count += 1; } } else if (count == 3) { if (count == numPlayer) { Launcher.primaryStage.hide(); try { gameRoot = FXMLLoader.load(getClass().getResource("UIFiles/MainMap.fxml")); gameScene = new Scene(gameRoot); Parent startWindow = FXMLLoader.load(getClass().getResource("UIFiles/playerStart.fxml")); startScene = new Scene(startWindow); } catch (Exception e1) { e1.printStackTrace(); } newStage.setScene(gameScene); newStage.setTitle("Game Screen"); newStage.show(); GameController.beginTurn(); // creates land array landPlots = new Land[9][5]; // 5 rows, 9 columns, col = i, row = j int count = 0; for (int i = 0; i < landPlots.length; i++) { for (int j = 0; j < landPlots[0].length; j++) { Land newLand = new Land(i, j); newLand.setType(landTypes[count]); landPlots[i][j] = newLand; count++; } } } else { Launcher.primaryStage.setTitle("Player 4 Configuration"); Launcher.primaryStage.toFront(); playerName.clear(); raceChoice.getSelectionModel().clearSelection(); colorPick.setValue(Color.WHITE); count += 1; } } else if (count == 4) { Launcher.primaryStage.hide(); try { gameRoot = FXMLLoader.load(getClass().getResource("UIFiles/MainMap.fxml")); gameScene = new Scene(gameRoot); Parent startWindow = FXMLLoader.load(getClass().getResource("UIFiles/playerStart.fxml")); startScene = new Scene(startWindow); } catch (Exception e1) { e1.printStackTrace(); } newStage.setScene(gameScene); newStage.setTitle("Game Screen"); newStage.show(); GameController.beginTurn(); // creates land array landPlots = new Land[9][5]; // 5 rows, 9 columns, col = i, row = j int count = 0; for (int i = 0; i < landPlots.length; i++) { for (int j = 0; j < landPlots[0].length; j++) { Land newLand = new Land(i, j); newLand.setType(landTypes[count]); landPlots[i][j] = newLand; count++; } } } } } else if (e.getSource() == backButton) { playerName.clear(); raceChoice.getSelectionModel().clearSelection(); colorPick.setValue(Color.WHITE); Launcher.primaryStage.setScene(Launcher.rootScene); Launcher.primaryStage.setTitle("M.U.L.E. Game Setup"); } /*} catch (NullPointerException error) { Launcher.primaryStage.setScene(Launcher.errorMessage); Launcher.primaryStage.setTitle("Error!"); }*/ }