Esempio n. 1
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();
  }
Esempio n. 2
0
 /**
  * Goes to next players turn more robust than incrementTurn
  *
  * @throws IOException exception
  */
 public static void next() throws IOException {
   Util.incrementTurn();
   Player cp = Configurations.getCurPlayer();
   cp.moveTo(cp.getStartX(), cp.getStartY());
   if (cp.getPhase() != 0) {
     Configurations.getGameScreenController().removePlayerFromTown(cp);
     cp.setPhase(0);
   }
   Configurations.getGuiController().setScene(Configurations.getGameScreenController().getView());
 }
Esempio n. 3
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();
  }
Esempio n. 4
0
 /**
  * produces game values
  *
  * @throws IOException exception
  */
 public static void produce() throws IOException {
   for (Player p : Configurations.getPlayers()) {
     for (MapTiles tile : p.getOwned()) {
       for (int i = 0; i < tile.getMules().length && p.getEnergy() > 0; i++) {
         if (tile.getMules()[i]) {
           if (i == 0) {
             p.setFood(p.getFood() + tile.getFood());
             p.setEnergy(p.getEnergy() - 1);
           } else if (i == 1) {
             p.setEnergy(p.getEnergy() + tile.getEnergy());
             p.setEnergy(p.getEnergy() - 1);
           } else {
             p.setSmithore(p.getSmithore() + tile.getOre());
             p.setEnergy(p.getEnergy() - 1);
           }
         }
       }
     }
   }
   // Save.save();
 }
Esempio n. 5
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();
    }
  }