Пример #1
0
  /**
   * 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
  /**
   * 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();
    }
  }
Пример #3
0
  /**
   * gives turns for buying to players
   *
   * @throws IOException exception
   */
  private static void buyTurnIncre() throws IOException {
    if (playerOrder.isEmpty()) {
      for (Player p : Configurations.getPlayers()) {
        if (p.getMoney() > 300 && !p.isPassed()) {
          playerOrder.add(p);
        }
      }
      if (playerOrder.isEmpty()) {
        Configurations.setRound(Configurations.getRound() + 1);

        // Applying random event to player 1 during initial game start
        Configurations.getCurPlayer().setMessage(applyRandomEvent());
        Configurations.getGameScreenController()
            .updateText(Configurations.getCurPlayer().getMessage());
        Configurations.getLoopService().start();
        movePhaseTurnIncre();
        return;
      }
    }
    Configurations.setCurPlayer(playerOrder.remove());
    if (Configurations.getCurPlayer().isPassed()) {
      buyTurnIncre();
    }
    Configurations.getGameScreenController().updateText();
  }