Example #1
0
  public PlanetMap(String s, ChildForm parent, GameProxy gameProxy) {
    // super(false);
    this.parent = parent;
    this.gameProxy = gameProxy;
    // System.out.println("my p " + myPlanet);
    this.addCommand(cmdBack);
    // this.addCommand(cmdBuild);
    this.setCommandListener(this);
    setFullScreenMode(true);
    System.out.println("11111");
    en = Ground.getEnvironment(gameProxy.getMap(), gameProxy.getSaveName());
    System.out.println("21111");
    System.out.println(en);
    ENV = en;
    cm = new CurserManager(en, getHeight(), getWidth(), gameProxy);
    um = new UnitManager(en, getHeight(), getWidth());
    System.out.println("##1");
    cm.setUm(um);
    exec = true;
    myThread = new Thread(this);
    System.out.println("##2");

    try {
      JCageConfigurator.scoreTable = new Hashtable();
      System.out.println("Starting...");
      myThread.start();
      System.out.println("started...");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #2
0
  private boolean handleInhabitantUnitCreation(int timer) {
    // handle building creation

    // if (timer % 1000 != 0) return;

    System.out.println("%%%%%%%%%%%%%%% creatin IH U");
    int k = Math.abs(Ground.rand.nextInt()) % 3;
    System.out.println("k " + k);
    Unit setU = null;
    String type = "";
    if (k == 0) {
      type = JCageConfigurator.UNIT_GROUND_HUMAN_A;
    } else if (k == 1) {
      type = JCageConfigurator.UNIT_GROUND_HUMAN_B;
    } else {
      type = JCageConfigurator.UNIT_GROUND_HUMAN_C;
    }
    Enumeration e = JCageConfigurator.units.keys();
    while (e.hasMoreElements()) {
      String key = String.valueOf(e.nextElement());
      Unit bu = (Unit) JCageConfigurator.units.get(key);
      System.out.println(bu.getType());
      if (bu.getType().equals(type)) {
        setU = bu;
        break;
      }
    }
    // Point[] pts = en.getUnitInsetionPoints();
    // Point point = pts[Math.abs(Ground.rand.nextInt()) % pts.length];
    DynamicUnit bx =
        new DynamicUnit(
            en, gameProxy.getSaveName(), setU, MainMid.getClientConfigurator().user + "ene");

    long x = Math.abs(Ground.rand.nextInt()) % (GroundCell.W * Ground.width);
    long y = Math.abs(Ground.rand.nextInt()) % (GroundCell.H * Ground.height);
    int x1 = (int) x;
    int y1 = (int) y;
    if (bx.isAllowedCell(x1, y1)) {
      // possitioning the newly created unit
      bx.setX(x1);
      bx.setY(y1);

      System.out.println("Saving iH unit");
      try {
        BaseUnitService.getInstance().insert(bx);
        // System.out.println("Building saved");
        //            synchronized (Environment.unitHtLock) {
        en.units.put(bx.getUnitId(), bx);
        //            }
      } catch (Exception ex) {
        ex.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      }
      return true;
    }
    return false;
  }
Example #3
0
 private void handleBuildingCreation() {
   // handle building creation
   if (JCageConfigurator.currentSelectedBuilding != null && um.getBuildingToBuild() == null) {
     um.setBuildingToBuild(
         new BaseBuilding(
             en,
             gameProxy.getSaveName(),
             JCageConfigurator.currentSelectedBuilding,
             MainMid.getClientConfigurator().user));
     um.getBuildingToBuild().setEnvironment(en);
   }
 }
Example #4
0
  private void handleUnitCreation() {
    // handle building creation
    if (JCageConfigurator.currentSelectedUnit != null
        && JCageConfigurator.currentSelectedBaseBuilding != null) {
      DynamicUnit bu =
          new DynamicUnit(
              en,
              gameProxy.getSaveName(),
              JCageConfigurator.currentSelectedUnit,
              MainMid.getClientConfigurator().user);

      // possitioning the newly created unit

      int tempX =
          JCageConfigurator.currentSelectedBaseBuilding.getX()
              + bu.getSizeX() / 2
              + JCageConfigurator.currentSelectedBaseBuilding.getSizeX() / 2;
      int tempY =
          JCageConfigurator.currentSelectedBaseBuilding.getY()
              + bu.getSizeY() / 2
              + JCageConfigurator.currentSelectedBaseBuilding.getSizeY() / 2;

      if (bu.isAllowedCell(tempX, tempY)) {
        bu.setX(tempX);
        bu.setY(tempY);
      } else {
        bu.setX(tempX + 10);
        bu.setY(tempY + 10);
      }

      int ra1 = Ground.rand.nextInt() % 2;
      int ra2 = Ground.rand.nextInt() % 2;

      if (ra1 == 0 && ra2 == 0) {
        ra1 = 1;
        ra2 = 1;
      }

      bu.registerMove(
          JCageConfigurator.currentSelectedBaseBuilding.getX()
              + bu.getSizeX() / 2
              + ra1 * JCageConfigurator.currentSelectedBaseBuilding.getSizeX() / 2,
          JCageConfigurator.currentSelectedBaseBuilding.getY()
              + bu.getSizeY() / 2
              + ra2 * JCageConfigurator.currentSelectedBaseBuilding.getSizeY() / 2);
      // save building
      try {
        BaseUnitService.getInstance().insert(bu);
        // System.out.println("Building saved");
        //                synchronized (Environment.unitHtLock) {
        en.units.put(bu.getUnitId(), bu);
        //                }
      } catch (Exception e) {
        e.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      }

      JCageConfigurator.currentSelectedBaseBuilding = null;
      JCageConfigurator.currentSelectedUnit = null;
    }
  }