示例#1
0
文件: Util.java 项目: zbolmb/MULE
  /**
   * generates random events to players
   *
   * @return String message of random event
   */
  public static String applyRandomEvent() {
    int rand = (int) (Math.random() * randomEvents.length);

    Player cp = Configurations.getCurPlayer();
    int money = randomEvents[rand].getMoney();
    int food = randomEvents[rand].getFood();
    int energy = randomEvents[rand].getEnergy();

    if (playerOrder.size() == 0) {
      while (money < 0 || food < 0 || energy < 0) {
        rand = (int) (Math.random() * randomEvents.length);
        money = randomEvents[rand].getMoney();
        food = randomEvents[rand].getFood();
        energy = randomEvents[rand].getEnergy();
      }
    }

    cp.setMoney(cp.getMoney() + money);
    cp.setFood(cp.getFood() + food);
    cp.setEnergy(cp.getEnergy() + energy);

    if (cp.getMoney() < 0) {
      cp.setMoney(0);
    } else if (cp.getFood() < 0) {
      cp.setFood(0);
    } else if (cp.getEnergy() < 0) {
      cp.setEnergy(0);
    }

    return randomEvents[rand].getMessage();
  }
示例#2
0
文件: Util.java 项目: zbolmb/MULE
  /**
   * claims tiles for players
   *
   * @param x double
   * @param y double
   * @param tile MapTiles
   * @throws IOException exception
   */
  public static void claimTile(double x, double y, MapTiles tile) throws IOException {
    if (Configurations.getRound() == 0 && Configurations.getCurPlayer().getMoney() < 300) {
      return;
    }
    if (!(tile instanceof TownTile) && tile.getOwner().equals("None")) {
      Player cp = Configurations.getCurPlayer();
      if (cp.getOwned().size() <= 0) {
        int rx = (int) (x / 100) * 100;
        int ry = (int) (y / 100) * 100;
        cp.setStartX(rx + 0.5 * MapTiles.getW());
        cp.setStartY(ry + 0.5 * MapTiles.getH());
        cp.setPlayerIcon(new Circle(cp.getStartX(), cp.getStartY(), 10, cp.getColor()));
        Configurations.getGameMapController().add(cp.getPlayerIcon());
      }
      cp.getOwned().add(tile);
      tile.setOwner(cp.getName());
      if (Configurations.getRound() == 0) {
        cp.setMoney(cp.getMoney() - 300);
      }
      Rectangle[] sq = Util.drawSelectionSq(x, y, cp.getColor());

      for (Rectangle r : sq) {
        Configurations.getGameMapController().add(r);
      }
      incrementTurn();
    }
  }