Exemplo n.º 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();
  }
Exemplo n.º 2
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();
 }