コード例 #1
0
ファイル: GameEngine.java プロジェクト: kw701/Anchovy
 /**
  * Goes through the list of components one by one calling its simulate method This should be
  * called in a loop to get a continuous simulation.
  */
 public void runSimulation() {
   Iterator<Component> ci = powrPlntComponents.iterator();
   Component comp = null;
   while (ci.hasNext()) {
     comp = ci.next();
     comp.calucalte();
   }
 }
コード例 #2
0
ファイル: GameEngine.java プロジェクト: kw701/Anchovy
 /**
  * Connect two components together.
  *
  * @param comp1 the component that we are working with
  * @param comp2 the component that will be added to comp1
  * @param input_output denoted whether it is an input or an output; in = true, out = false
  */
 public void connectComponentTo(Component comp1, Component comp2, boolean input_ouput) {
   if (input_ouput) {
     comp1.connectToInput(comp2);
     comp2.connectToOutput(comp1);
   } else {
     comp1.connectToOutput(comp2);
     comp2.connectToInput(comp1);
   }
 }
コード例 #3
0
ファイル: GameEngine.java プロジェクト: kw701/Anchovy
 /**
  * Get all the info from all the components within the power plant. Used for saving and displaying
  * info to UI.
  *
  * @return List of InfoPackets for ALL components in the power plant.
  */
 public ArrayList<InfoPacket> getAllComponentInfo() {
   ArrayList<InfoPacket> allInfo = new ArrayList<InfoPacket>();
   Iterator<Component> ci = powrPlntComponents.iterator();
   Component comp = null;
   while (ci.hasNext()) {
     comp = ci.next();
     allInfo.add(comp.getInfo());
   }
   return allInfo;
 }
コード例 #4
0
ファイル: GameEngine.java プロジェクト: kw701/Anchovy
 /**
  * Using the name of a component in the format of a string returns the actual Component found in
  * the list of components of the Power Plant
  *
  * @param The name of a component.
  * @return The component specified by the given name.
  */
 private Component getPowerPlantComponent(String currentCompName) {
   Component currentComponent = null;
   Iterator<Component> compIt;
   compIt = powrPlntComponents.iterator();
   Component c = null;
   String cName = null;
   while (compIt.hasNext()) {
     c = compIt.next();
     cName = c.getName();
     if (cName.equals(currentCompName)) {
       currentComponent = c;
     }
   }
   return currentComponent;
 }
コード例 #5
0
ファイル: GameEngine.java プロジェクト: kw701/Anchovy
  /**
   * Sends an info packet to a component the components is specified by the name of the component in
   * the info packet.
   *
   * @param info Info Packet to be sent to a component
   */
  public void assignInfoToComponent(InfoPacket info) throws Exception {
    String compToSendTo = null;

    //		Pair<?> pair = null;
    //		Iterator<Pair<?>> pi = info.namedValues.iterator();
    //		Label label = null;
    //		while(pi.hasNext() && compToSendTo == null){
    //			pair = pi.next();
    //			label = pair.getLabel();
    //			switch (label){
    //			case cNme:
    //				compToSendTo = (String) pair.second();
    //			default:
    //				break;
    //			}
    //		}

    compToSendTo = getComponentNameFromInfo(info);

    //		Iterator<Component> ci = powrPlntComponents.iterator();
    //		boolean comNotFound = true;
    Component com = null;
    //		while(ci.hasNext() && comNotFound){
    //			comNotFound = true;
    //			com = ci.next();
    //			if(com.getName() == compToSendTo){
    //				comNotFound = false;
    //
    //			}
    //		}

    com = getPowerPlantComponent(compToSendTo);
    /*
     * if the component wasn't found throw an exception stating this
     */
    if (com == null) {
      throw new Exception("The component you were trying to send info to doesn't exit");
    } else {
      com.takeInfo(info);
    }
  }