Example #1
0
 /**
  * moves / increments turn based off of players priority queue
  *
  * @throws IOException exception
  */
 private static void movePhaseTurnIncre() throws IOException {
   if (playerOrder.isEmpty()) {
     for (Player p : Configurations.getPlayers()) {
       playerOrder.add(p);
     }
     Configurations.setRound(Configurations.getRound() + 1);
     if (Configurations.getPhase() == 1) {
       produce();
     }
   }
   Configurations.setCurPlayer(playerOrder.remove());
   if (Configurations.getPhase() != 0) {
     if (Math.random() < .27) {
       Configurations.getCurPlayer().setMessage(applyRandomEvent());
       Configurations.getGameScreenController()
           .updateText(Configurations.getCurPlayer().getMessage());
     } else {
       Configurations.getCurPlayer().setMessage("");
       Configurations.getGameScreenController()
           .updateText(Configurations.getCurPlayer().getMessage());
     }
   } else {
     Configurations.getGameScreenController().updateText();
   }
 }
Example #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();
    }
  }
Example #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();
  }
Example #4
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();
  }
Example #5
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());
 }