Example #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);
 }
Example #2
0
  /** Handle OK/Cancel selections */
  @Override
  public void close(String actionCommand) {
    super.close(actionCommand);

    if (isOKorAccept(actionCommand)) {
      World world = clientFrame.getWorld();

      // this isn't really the way to do it
      GamePanel gp = (GamePanel) tabPane.getComponentAt(0);
      GameMetadata gmd = new GameMetadata();
      gp.write(gmd);
      world.setGameMetadata(gmd);

      // assume panels 1-n are all player panels
      for (int i = 1; i < tabPane.getTabCount(); i++) {
        PlayerPanel pp = (PlayerPanel) tabPane.getComponentAt(i);
        PlayerMetadata pmd = new PlayerMetadata();
        pp.write(pmd);
        world.setPlayerMetadata(pp.getPower(), pmd);
      }

      // set data-changed flag
      clientFrame.fireStateModified();
    }

    if (propertyListener != null) {
      clientFrame.removePropertyChangeListener(propertyListener);
    }
  } // close()
Example #3
0
 /** Sets the tab icons for each power. */
 private void setTabIcons() {
   if (mmd != null) {
     final World world = clientFrame.getWorld();
     final int tabCount = tabPane.getTabCount();
     for (int i = 1; i < tabCount; i++) // no icon for 'game' info
     {
       Power power = world.getMap().getPower(tabPane.getTitleAt(i));
       assert (power != null);
       String colorName = mmd.getPowerColor(power);
       Color color = SVGColorParser.parseColor(colorName);
       tabPane.setIconAt(i, new ColorRectIcon(12, 12, color));
     }
   }
 } // setTabIcons()
Example #4
0
  /** Make the tab panel */
  private void makeTabPanel() {
    // create tabbed pane
    tabPane = new JTabbedPane();

    // first tab is Game info
    World world = clientFrame.getWorld();
    tabPane.add(Utils.getLocalString(TAB_GAME_PANEL), makeGamePanel(world.getGameMetadata()));

    // all other tabs are by Power name
    Power[] powers = world.getMap().getPowers();
    for (int i = 0; i < powers.length; i++) {
      tabPane.add(
          powers[i].getName(), makePlayerPanel(powers[i], world.getPlayerMetadata(powers[i])));
    }
  } // makeTabPanel()
Example #5
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;
 }
Example #6
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());
  }
Example #7
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());
  }
Example #8
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.");
   }
 }
Example #9
0
 /**
  * Determines if the game is over
  *
  * @return <code>true</code>/<code>false</code>
  */
 public boolean isGameOver() {
   return world.getLastTurnState().isEnded();
 }
Example #10
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();
 }
Example #11
0
 /**
  * Gets the expanded name of the current phase.
  *
  * @return phase name
  */
 public String getCurrentPhaseTitle() {
   return world.getLastTurnState().getPhase().toString();
 }