Exemplo n.º 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);
 }
Exemplo n.º 2
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.");
   }
 }
Exemplo n.º 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());
  }
Exemplo n.º 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());
  }
Exemplo n.º 5
0
 /**
  * Determines if the game is over
  *
  * @return <code>true</code>/<code>false</code>
  */
 public boolean isGameOver() {
   return world.getLastTurnState().isEnded();
 }
Exemplo n.º 6
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();
 }
Exemplo n.º 7
0
 /**
  * Gets the expanded name of the current phase.
  *
  * @return phase name
  */
 public String getCurrentPhaseTitle() {
   return world.getLastTurnState().getPhase().toString();
 }