コード例 #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
ファイル: Product.java プロジェクト: LVCPCAS/CASJava
 public static Product quotient(Expr numerator, Expr denominator) {
   return new Product(numerator, Power.unaryMultInv(denominator));
 }
コード例 #3
0
ファイル: ClientGame.java プロジェクト: Hikari9/SpaceShooter
  void turnOnPowerReceiver() throws IOException {
    Global.log("Turning on power receiver...");
    while (true) {

      if (isDisposed()) throw new IOException("Client game disposed");
      Global.log("Connecting to port " + (Global.powerPort()) + "...");
      try {
        powerStream = new ClientByteStream(ip, Global.powerPort(), Power.bufferSize());
        break;
      } catch (IOException ex) {
      }
    }
    Global.log("Connected!");
    timers.add(
        new FixedTimer(
            new FixedTask() {
              public boolean fixedRate() {
                return false;
              }

              public float FPS() {
                return Global.ReceiveFPS;
              }

              public void run() {
                byte[] data = null;
                try {
                  data = powerStream.read();
                } catch (IOException ex) {
                  Global.onException();
                  stop();
                  return;
                }
                if (data == null) return;
                addPower(Power.fromBytes(data));
              }
            }));
    Global.log("Turning on power remover...");
    while (true) {
      if (isDisposed()) throw new IOException("Client game disposed");
      Global.log("Connecting to port " + Global.powerRemoverPort() + "...");
      try {
        powerRemover = new ClientByteStream(ip, Global.powerRemoverPort(), 2);
        break;
      } catch (IOException ex) {
      }
    }
    Global.log("Connected!");
    timers.add(
        new FixedTimer(
            new FixedTask() {
              public boolean fixedRate() {
                return false;
              }

              public float FPS() {
                return Global.ReceiveFPS;
              }

              public void run() {
                byte[] data = null;
                try {
                  data = powerRemover.read();
                } catch (IOException ex) {
                  System.err.println("Cannot read info from power remover");
                  Global.onException();
                  stop();
                  return;
                }
                if (data == null) return;
                ByteBuffer bb = ByteBuffer.wrap(data);
                short id = bb.getShort();
                for (Power power : powers) {
                  if (power.ID == id) {
                    removePower(power);
                    break;
                  }
                }
              }
            }));
  }