Пример #1
0
 /**
  * Loads orders for a particular power into the most recent turn state. Overwrites any existing
  * orders for the given power.
  *
  * @param orderStrings the orders to load
  * @param powerToSet the power to load against
  * @throws PowerNotFoundException
  * @throws JdipException
  */
 public void setOrders(String[] orderStrings, JdipPower powerToSet)
     throws PowerNotFoundException, JdipException {
   // fetch the power
   Power power = powerToSet.getPower();
   if (power == null) {
     throw new PowerNotFoundException();
   }
   // parse the orders
   ArrayList orders = new ArrayList();
   OrderParser parser = OrderParser.getInstance();
   OrderFactory of = strategy.getOrderFactory();
   try {
     for (int i = 0; i < orderStrings.length; i++) {
       Order o =
           parser.parse(
               of,
               power.getName() + " " + orderStrings[i],
               power,
               world.getLastTurnState(),
               true,
               false);
       orders.add(o);
     }
   } catch (OrderException e) {
     throw new JdipException(e.getMessage() + " <" + e.getOrder() + ">", e);
   }
   // set the orders
   world.getLastTurnState().setOrders(power, orders);
 }
Пример #2
0
 /**
  * Fetches a list of all valid power names.
  *
  * @return an array containing the name of each power
  */
 public String[] getPowerNames() {
   Power[] powers = world.getMap().getPowers();
   String[] powerNames = new String[powers.length];
   for (int i = 0; i < powers.length; i++) {
     powerNames[i] = powers[i].getName();
   }
   return powerNames;
 }
Пример #3
0
  /**
   * Returns an array of all general messages from the last adjudicated turn state.
   *
   * @param power the power to get results for
   * @param format one of the format constants
   * @return an array of <code>JdipResultAdapter</code>s
   */
  public JdipResult[] getAllResultsForPower(JdipPower power, int format) {
    OrderFormatOptions ofo = this.ceateOrderFormat(format);

    TurnState state = world.getPreviousTurnState(world.getLastTurnState());
    List allResults = state.getResultList();
    ArrayList generalResults = new ArrayList();
    Iterator it = allResults.iterator();

    while (it.hasNext()) {
      JdipResult r = new JdipResult((Result) it.next(), ofo);
      // find all resluts for given power
      if (!r.isGeneralResult() && r.getPower().equals(power.getPowerName())) {
        generalResults.add(r);
      }
    }

    return toJdipResultArray(generalResults.toArray());
  }
Пример #4
0
  /**
   * Returns an array of all general messages from the last adjudicated turn state.
   *
   * @param format one of the format constants
   * @return an array of <code>JdipResultAdapter</code>s
   */
  public JdipResult[] getAllGeneralResults(int format) {
    OrderFormatOptions ofo = this.ceateOrderFormat(format);

    TurnState state = world.getPreviousTurnState(world.getLastTurnState());
    List allResults = state.getResultList();
    ArrayList generalResults = new ArrayList();
    Iterator it = allResults.iterator();

    while (it.hasNext()) {
      JdipResult r = new JdipResult((Result) it.next(), ofo);
      // find all general resluts
      if (r.isGeneralResult()) {
        generalResults.add(r);
      }
    }

    return toJdipResultArray(generalResults.toArray());
  }
Пример #5
0
 /**
  * Gets the current type (Adjustment, Movement, Retreat) of the current phase.
  *
  * @return one of the phase type constants.
  */
 public int getCurrentPhaseType() {
   PhaseType current = world.getLastTurnState().getPhase().getPhaseType();
   if (current == PhaseType.ADJUSTMENT) {
     return PHASE_TYPE_ADJUSTMENT;
   } else if (current == PhaseType.MOVEMENT) {
     return PHASE_TYPE_MOVEMENT;
   } else if (current == PhaseType.RETREAT) {
     return PHASE_TYPE_RETREAT;
   } else {
     throw new StateError("TurnState phase is not valid! Something is wrong with JDip.");
   }
 }
Пример #6
0
 /**
  * Determines if the game is over
  *
  * @return <code>true</code>/<code>false</code>
  */
 public boolean isGameOver() {
   return world.getLastTurnState().isEnded();
 }
Пример #7
0
 /**
  * Gets the expanded name of the previous phase. This is the name of the phase associated with the
  * currently available results.
  *
  * @return phase name
  */
 public String getLastPhaseTitle() {
   return world.getPreviousTurnState(world.getLastTurnState()).getPhase().toString();
 }
Пример #8
0
 /**
  * Gets the expanded name of the current phase.
  *
  * @return phase name
  */
 public String getCurrentPhaseTitle() {
   return world.getLastTurnState().getPhase().toString();
 }