コード例 #1
0
ファイル: JdipWorld.java プロジェクト: js-duke/kdip
 /**
  * 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
ファイル: JdipWorld.java プロジェクト: js-duke/kdip
  /**
   * 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());
  }
コード例 #3
0
ファイル: JdipWorld.java プロジェクト: js-duke/kdip
  /**
   * 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());
  }