Ejemplo n.º 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();
    }
  }
Ejemplo n.º 2
0
  public void run() {
    try {
      if (init) {
        Thread.sleep(500);
        disWidth = (getWidth() - 176) / 2; // 抓取螢幕的中心點
        disHeight = (getHeight() - 208) / 2; // 抓取螢幕的中心點
        drawDisplay();

        systemShowInf("建立資料庫...");
        new DataBaseWrite();
        systemShowInf("設定音樂...");
        GameMain.music = new BackupMusic();
        music = GameMain.music;
        systemShowInf("設定遊戲環境...");
        GameMain.roleData = new RoleDataValue();
        roleData = GameMain.roleData;
        GameMain.gaminf = new GameInfString();
        GameMain.music.musicStart("1");
        spInterface.setFrame(1);
        drawDisplay();
        changeMeun();
        init = false;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public void commandAction(Command c, Displayable d) {
    if (c == cmdCancel) {
      destroyView();
      return;
    }
    if (c == cmdOk) {
      try {
        int type = choiseType.getSelectedIndex();
        String value = textValue.getString();
        if (type == 2) value = PrivacyItem.subscrs[choiceSubscr.getSelectedIndex()];
        if (type != PrivacyItem.ITEM_ANY) if (value.length() == 0) return;
        // int order=Integer.parseInt(textOrder.getString());

        item.action = choiceAction.getSelectedIndex();
        item.type = type;
        item.value = value;
        // item.order=order;
        choiseStanzas.getSelectedFlags(item.stanzasSet);

        if (targetList != null)
          if (!targetList.rules.contains(item)) {
            targetList.addRule(item);
            item.order = targetList.rules.indexOf(item) * 10;
          }
        destroyView();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Ejemplo n.º 4
0
 public void drawMenu() {
   try {
     if (page == 3) {
       setFont(16);
       g.drawString(nickname, disWidth + 80, disHeight + 15, 0);
     }
     // 判斷在遊戲說明時,防止文字超出螢幕,當超出螢幕時放到下一頁面
     if (page == 1) {
       setFont(0);
       g.setColor(255, 255, 255);
       for (int i = 0; gameUserInfCount < gameUserInf.length; gameUserInfCount++, i += 17) {
         if (gameUserInfCount % 5 != 4) // 遊戲說明
         g.drawString(gameUserInf[gameUserInfCount], disWidth + 10, disHeight + 70 + i, 0);
         else { // 顯示還有下一頁的文字
           g.drawString(gameUserInf[gameUserInfCount], disWidth + 135, disHeight + 70 + i, 0);
           gameUserInfCount++;
           break;
         }
       }
       flushGraphics();
     }
     changeMeun();
     flushGraphics();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  private void showCamera() {

    try {

      releaseResources();
      player = Manager.createPlayer("capture://video");
      player.addPlayerListener(this);
      player.realize();

      videoControl = (VideoControl) player.getControl("VideoControl");
      aVideoCanvas = new VideoCanvas();
      aVideoCanvas.initControls(videoControl, player);

      aVideoCanvas.addCommand(CMD_RECORD);
      aVideoCanvas.addCommand(CMD_EXIT);
      aVideoCanvas.setCommandListener(this);
      parentMidlet.getDisplay().setCurrent(aVideoCanvas);

      player.start();
      contentType = player.getContentType();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public void commandAction(Command c, Displayable d) {
    if (c == cmdCancel) {
      destroyView();
    }
    // if (c==cmdBookmarks) { new Bookmarks(display, null); }
    if (c == cmdJoin || c == cmdAdd) {
      String nick = nickField.getString().trim();
      String host = hostField.getString().trim();
      String room = roomField.getString().trim();
      String pass = passField.getString();
      int msgLimit = msgLimitField.getValue();

      if (nick.length() == 0) return;
      if (room.length() == 0) return;
      if (host.length() == 0) return;
      StringBuffer gchat = new StringBuffer(room.trim());
      gchat.append('@');
      gchat.append(host.trim());
      // sd.roster.mucContact(gchat.toString(), Contact.ORIGIN_GROUPCHAT);
      if (c == cmdAdd) new Bookmarks(display, new BookmarkItem(gchat.toString(), nick, pass));
      else {
        try {
          gchat.append('/');
          gchat.append(nick);
          join(gchat.toString(), pass, msgLimit);

          display.setCurrent(sd.roster);
        } catch (Exception e) {
          e.printStackTrace();
          // display.setCurrent(new Alert("Exception", e.toString(), null, AlertType.ERROR),
          // sd.roster);
        }
      }
    }
  }
Ejemplo n.º 7
0
 public void runGame() {
   try {
     GameMain.music.stop();
     display.setCurrent(new mapCanvars(display, roleData, midlet));
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 8
0
 // 建立圖片
 public Image createImage(String pathImg) {
   img = null;
   try {
     img = Image.createImage(pathImg);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return img;
 }
Ejemplo n.º 9
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;
  }
Ejemplo n.º 10
0
 public void run() {
   while (true) {
     checkTimestamps();
     repaint();
     try {
       synchronized (this) {
         wait(50L);
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Ejemplo n.º 11
0
 // 鍵盤事件
 protected void keyPressed(int keyCode) {
   if (!init & page != -2) {
     switch (keyCode) {
       case -5: // 按下FIRE
         GameMain.music.msuicSound(0);
         try {
           changeMeunStart();
         } catch (Exception e) {
           e.printStackTrace();
         }
         break;
       case -1: // 按下UP
         GameMain.music.msuicSound(1);
         if (page == 0 || page == -1) {
           if (menustate <= 0) menustate = menuNum;
           menustate--;
         } else if (page == 2) {
           if (menustate <= 1) menustate = menuNum;
           menustate--;
         } else {
           if (menustate <= 2) menustate = menuNum;
           menustate--;
         }
         break;
       case -2: // 按下DOWN
         GameMain.music.msuicSound(1);
         if (page == 0 || page == -1) {
           if (menustate >= menuNum - 1) menustate = -1;
           menustate++;
         } else if (page == 2) {
           if (menustate >= 3) menustate = 0;
           menustate++;
         } else {
           if (menustate >= 3) menustate = 1;
           menustate++;
         }
         break;
       case -4: // 按下RIGHT
         GameMain.music.msuicSound(1);
         if (menustate == 2) menustate = 3;
         else if (menustate == 3) menustate = 2;
         break;
       case -3: // 按下LEFT
         GameMain.music.msuicSound(1);
         if (menustate == 2) menustate = 3;
         else if (menustate == 3) menustate = 2;
         break;
     }
     changeMeun();
   }
 }
Ejemplo n.º 12
0
 public void run() {
   if (playSnd) {
     try {
       for (int i = 0; i < tone.length(); ) {
         int note = (tone.charAt(i++) - 'A') + 12 * (tone.charAt(i++) - '0');
         int duration = 150;
         Manager.playTone(note, duration, 100);
         Thread.sleep(duration);
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Ejemplo n.º 13
0
 // 畫面選單改變
 public void changePage() {
   try {
     switch (page) {
       case -1:
         spName.setVisible(false);
         spInterface.setFrame(1);
         drawDisplay();
         break;
       case 0: // 遊戲帳號輸入選單
         menustate = 0;
         spName.setVisible(true);
         spInterface.setFrame(2);
         spName.setFrame(0);
         drawDisplay();
         for (int i = 0; i < loginStr.length; i++) nowString[i] = loginStr[i];
         menuNum = loginStr.length; // MENU 數量
         // System.out.println(page);
         break;
       case 1: // 遊戲說明選單
         spInterface.setFrame(2);
         spName.setFrame(1);
         drawDisplay();
         for (int i = 2; i < nowString.length; i++) nowString[i] = gameInfo[i - 2];
         menuNum = loginStr.length;
         menustate = 2;
         break;
       case 2: // 遊戲姓名輸入選單
         spInterface.setFrame(2);
         spName.setFrame(2);
         spName.setVisible(true);
         drawDisplay();
         for (int i = 1; i < nowString.length; i++) nowString[i] = gameNameInp[i - 1];
         menuNum = loginStr.length;
         menustate = 1;
         break;
       case 3: // 遊戲角色建立成功選單
         spName.setVisible(false);
         spInterface.setFrame(3);
         drawDisplay();
         for (int i = 2; i < nowString.length; i++) nowString[i] = showGameUser[i - 2];
         menuNum = loginStr.length;
         menustate = 2;
         break;
     }
     drawMenu();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 14
0
  public void commandAction(Command command, Displayable displayable) {
    if (command == cmdBack) {
      exec = false;
      try {
        BaseUnitService.getInstance().insertOrUpdate(en.units);
        BaseBuildingService.getInstance().insertOrUpdate(en.buildings);
        Thread.sleep(1000);
      } catch (Exception e) {
        e.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      }
      while (finished) {}

      ENV = null;
      MainMid.getClientConfigurator().displayParent();
    }
  }
Ejemplo n.º 15
0
  /**
   * Called by a system to indicated that a command has been invoked on a particular displayable.
   *
   * @param command the Command that was invoked
   * @param displayable the Displayable where the command was invoked
   */
  public void commandAction(Command command, Displayable displayable) {
    // GEN-END:|7-commandAction|0|7-preCommandAction
    // write pre-action user code here
    if (displayable == inputForm) { // GEN-BEGIN:|7-commandAction|1|37-preAction
      if (command == exitCommand) { // GEN-END:|7-commandAction|1|37-preAction
        // write pre-action user code here
        exitMIDlet(); // GEN-LINE:|7-commandAction|2|37-postAction
        // write post-action user code here
      } else if (command == okCommand) { // GEN-LINE:|7-commandAction|3|25-preAction
        // write pre-action user code here
        int numInput = Integer.parseInt(getInputNumber().getString());
        if (numInput > this.randomNum) {
          this.tip = "oh, looks like the number you chose is bigger than the one I have";
        } else if (numInput < this.randomNum) {
          this.tip = "oh, looks like the number you chose is smaller than the one I have";
        } else {
          this.tip =
              "Congratulations, you've got the right number ("
                  + Integer.toString(this.randomNum)
                  + ")! :D";
        }

        this.attempts++;

        switchDisplayable(null, getResultForm()); // GEN-LINE:|7-commandAction|4|25-postAction
        // write post-action user code here
        try {
          resultText.setText(this.tip);
          attemptsText.setText("Number of attempts: " + Integer.toString(this.attempts));
        } catch (Exception e) {
          e.printStackTrace();
        }
      } // GEN-BEGIN:|7-commandAction|5|40-preAction
    } else if (displayable == resultForm) {
      if (command == backCommand) { // GEN-END:|7-commandAction|5|40-preAction
        // write pre-action user code here
        switchDisplayable(null, getInputForm()); // GEN-LINE:|7-commandAction|6|40-postAction
        // write post-action user code here
      } else if (command == exitCommand1) { // GEN-LINE:|7-commandAction|7|42-preAction
        // write pre-action user code here
        exitMIDlet(); // GEN-LINE:|7-commandAction|8|42-postAction
        // write post-action user code here
      } // GEN-BEGIN:|7-commandAction|9|7-postCommandAction
    } // GEN-END:|7-commandAction|9|7-postCommandAction
    // write post-action user code here
  } // GEN-BEGIN:|7-commandAction|10|
Ejemplo n.º 16
0
  /**
   * Called by a system to indicated that a command has been invoked on a particular displayable.
   *
   * @param command the Command that was invoked
   * @param displayable the Displayable where the command was invoked
   */
  public void commandAction(
      Command command, Displayable displayable) { // GEN-END:|7-commandAction|0|7-preCommandAction
    // write pre-action user code here
    if (displayable == LoginForm) { // GEN-BEGIN:|7-commandAction|1|65-preAction
      if (command == CreateAgentandJoin) { // GEN-END:|7-commandAction|1|65-preAction
        // write pre-action user code here
        String name = UserAgentNameTF.getString();
        String strAgentClassName = "au.edu.latrobe.placecomm.agents.MobileUserAgent";
        try {
          MicroRuntime.startAgent(name, strAgentClassName, null);
          // write post-action user code here
        } catch (Exception ex) {
          ex.printStackTrace();
        }
        // GEN-LINE:|7-commandAction|2|65-postAction
        // write post-action user code here
      } else if (command == CreateContainer) { // GEN-LINE:|7-commandAction|3|63-preAction
        // write pre-action user code here

        Thread t =
            new Thread() {
              public void run() {
                myStartGoOnline();
              }
            };
        t.start();

        // GEN-LINE:|7-commandAction|4|63-postAction
        // write post-action user code here
      } else if (command == OfflineMode) { // GEN-LINE:|7-commandAction|5|28-preAction
        // write pre-action user code here
        // GEN-LINE:|7-commandAction|6|28-postAction
        // write post-action user code here
      } else if (command == exitCommand) { // GEN-LINE:|7-commandAction|7|17-preAction
        // write pre-action user code here
        exitMIDlet(); // GEN-LINE:|7-commandAction|8|17-postAction
        // write post-action user code here
      } else if (command == okCommand) { // GEN-LINE:|7-commandAction|9|20-preAction
        // write pre-action user code here
        // GEN-LINE:|7-commandAction|10|20-postAction
        // write post-action user code here
      } // GEN-BEGIN:|7-commandAction|11|7-postCommandAction
    } // GEN-END:|7-commandAction|11|7-postCommandAction
    // write post-action user code here
  } // GEN-BEGIN:|7-commandAction|12|
Ejemplo n.º 17
0
  public void run() {
    long k = 0;
    long paintTimer = 0;
    boolean setTime = true;
    boolean setTimePaint = true;
    finished = false;

    while (exec) {
      try {
        timer++;
        if (timer >= 20000) {
          timer = 0;
        }
        //                if ((timer) % ucTimer == 0) {
        //                    boolean created = false;
        //                    int ir = Math.abs(Ground.rand.nextInt()) % 2 + 1;
        //                    for (int i = 0; i < ir; i++) {
        //                        created = created || handleInhabitantUnitCreation(timer);
        //                    }
        //                    if (!created) {
        //                        System.out.println("No units created");
        //                        timer = ucTimer - 100;
        //                    }
        //                }

        handleBuildingCreation();
        handleUnitCreation();
        um.moveAndFireUnits(timer);
        repaint();
        setTime = true;
        // }

        Thread.sleep(refreshPeriod);
      } catch (InterruptedException ex1) {
        ex1.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      } catch (Exception ex2) {
        ex2.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      }
    }
    finished = true;
  }
Ejemplo n.º 18
0
 private void startSession() {
   SipClientConnection scc = null;
   try {
     // <i><b>start a listener for incoming requests</b></i>
     startListener();
     // <i><b>open SIP connection with remote user</b></i>
     scc = (SipClientConnection) Connector.open(address.getString());
     scc.setListener(this);
     // <i><b>initialize INVITE request</b></i>
     scc.initRequest("INVITE", scn);
     scc.setHeader("Content-Length", "" + sdp.length());
     scc.setHeader("Content-Type", "application/sdp");
     OutputStream os = scc.openContentOutputStream();
     os.write(sdp.getBytes());
     os.close(); // <i><b>close and send</b></i>
     str = new StringItem("Inviting... ", scc.getHeader("To"));
     form.append(str);
   } catch (Exception ex) {
     ex.printStackTrace();
     // <i><b>handle IOException</b></i>
   }
 }
Ejemplo n.º 19
0
  /** Metoda odpowiedzialna za wyswietlenie i animacje trojwymiarowego logo */
  public void displayLogo() {
    try {
      int keys;
      int frames = 0;
      float angle = 10.0f; // kat o jaki obraca sie logo w animacji

      Graphics3D g3d = Graphics3D.getInstance();
      Graphics g = getGraphics();

      // setFullScreenMode(true);

      Thread.sleep(100);

      // zaladowanie obiektu zapisanego w pliku m3g
      Object3D[] objects = Loader.load("/res/blue_logo.m3g");

      scene = (World) objects[0];

      Camera camera = new Camera();
      camera.setPerspective(30.0f, (float) getWidth() / (float) getHeight(), 1.0f, 1000.0f);
      camera.setTranslation(0.0f, 0.0f, 24.0f);
      scene.addChild(camera);
      scene.setActiveCamera(camera);

      scene.getChild(0).preRotate(180.0f, 1.0f, 0.0f, 0.0f);

      keys = getKeyStates();

      while (((keys & FIRE_PRESSED) == 0) && (frames < 36)) { // oczekiwanie na nacisniecie klawisza
        g3d.bindTarget(g);

        scene.getChild(0).preRotate(angle, 0.0f, 0.7f, 1.0f);
        // wyrenderowanie sceny
        g3d.render(scene);
        // zwolnienie kontekstu graficznego
        g3d.releaseTarget();

        flushGraphics();

        Thread.sleep(30); // uspienie watku na 30ms

        keys = getKeyStates();

        frames++;
      }

      while (((getKeyStates() & FIRE_PRESSED) != 0)
          && (frames < 36)) {} // oczekiwanie na zwolnienie przycisku fire

      if ((keys & FIRE_PRESSED)
          == 0) // jesli przycisk nie zostal wcisniety, tylko animacja dobiegla konca
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      soundPlayer.play(SoundPlayer.ERROR_SOUND);
      System.out.println("Praca watku przerysowujacego zawartosc ekranu zostala przerwana!");
      e.printStackTrace();
    } catch (IOException e) {
      soundPlayer.play(SoundPlayer.ERROR_SOUND);
      System.out.println("Blad podczas wczytywania pliku z zasobow!");
      e.printStackTrace();
    } catch (Exception e) {
      soundPlayer.play(SoundPlayer.ERROR_SOUND);
      System.out.println("Nieznany wyjatek");
      e.printStackTrace();
    }
  }
Ejemplo n.º 20
0
  // for initilization purpose and call in the Game() constructor
  public void init() {
    try {
      this.userWins = 0;
      this.compWins = 0;

      this.colSelected = 0;
      this.rowSelected = 0;
      // repaint() ;

      // Getting the maximum width and height of the Canvas
      this.maxX = this.getWidth();
      this.maxY = this.getHeight();

      this.alert =
          new Alert(
              "Score",
              "User  "
                  + String.valueOf(this.userWins)
                  + "\nDevice  "
                  + String.valueOf(this.compWins),
              null,
              AlertType.INFO);

      this.animated = this.parent.getAnimate();

      // Initilizing the Command
      this.score = new Command("Score", Command.ITEM, 2);
      this.addCommand(this.score);
      // this.setCommandListener( this ) ;

      this.newG = new Command("New", Command.ITEM, 1);
      this.addCommand(this.newG);

      this.addCommand(this.back);

      this.setCommandListener(this);

      this.random = new Random();

      // Settings the framem variable
      this.frame = 0;

      this.sq = new int[3][4];

      // Initializing the sq[][] array to -1
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
          this.sq[i][j] = -1;
        }
      }

      // Setting the userSymbol
      if (this.userSymbol == -1) {
        this.userSymbol = 0;
      } else if (this.userSymbol == 0) {
        this.userSymbol = 1;
      } else if (this.userSymbol == 1) {
        this.userSymbol = 0;
      }

      // Setting the compSymbol
      if (this.compSymbol == -1) {
        this.compSymbol = 1;
      } else if (this.compSymbol == 0) {
        this.compSymbol = 1;
      } else if (this.compSymbol == 1) {
        this.compSymbol = 0;
      }

      // Declaring timer and timertask
      TimerTask task =
          new TimerTask() {
            public void run() {
              if (frame == 0) {
                if (animated == true) {
                  frame = 1;
                }
              } else if (frame == 1) {
                if (animated == true) {
                  frame = 0;
                }
              }

              // Checking whether all chances are finished
              int c = 0;
              for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                  if (sq[i][j] == -1) {
                    c++;
                  }
                }
              }

              if (c == 0) {
                alert =
                    new Alert(
                        "Draw !",
                        "User  "
                            + String.valueOf(userWins)
                            + "\nDevice  "
                            + String.valueOf(compWins),
                        null,
                        AlertType.INFO);
                parent.setDisplayable(alert);
                newGame();
              }

              repaint();
            }
          };

      timer = new Timer();
      timer.scheduleAtFixedRate(task, 400, 400);

      // Initialising images

      if (this.maxX < 150 && this.maxY < 150) {
        this.imgWidth = 16;
        this.imgHeight = 16;
        this.crossImage = Image.createImage("/cross16.png");
        this.zeroImage = Image.createImage("/naught16.png");
      } else {
        this.imgWidth = 32;
        this.imgHeight = 32;
        this.crossImage = Image.createImage("/cross32.png");
        this.zeroImage = Image.createImage("/naught32.png");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 21
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;
    }
  }
Ejemplo n.º 22
0
 // 判斷選取的選單選項
 public void changeMeunStart() {
   try {
     if (page == -1) {
       switch (menustate) {
         case 0:
           page = 0;
           spName.setVisible(true);
           changePage();
           break;
         case 1:
           page = 0;
           spName.setVisible(true);
           changePage();
           break;
         case 2:
           // spWelcome.setVisible(false);
           spName.setVisible(false);
           spInterface.setFrame(4);
           drawDisplay();
           GameMain.music.stop();
           exit();
           break;
       }
     } else {
       switch (menustate) {
         case 0:
           try {
             new InputText(nowString[0]);
           } catch (Exception e) {
             e.printStackTrace();
           }
           break;
         case 1:
           new InputText(nowString[1]);
           break;
         case 2: // 登入
           if (page == 0) { // 當在輸入帳號畫面時
             // 未輸入帳號
             if (username.equals("") || pass.equals("")) {
               g.drawString("「請 輸入帳號密碼」", disWidth + 75, disHeight + 140, 0);
               flushGraphics();
             } else if (username.equals("xlinx") && pass.equals("x")) {
               runGame();
               g.drawString("進入遊戲...", disWidth + 15, disHeight + 129, 0);
               flushGraphics();
             } else { // 連到Server
               try {
                 GameMain.conn.setLoginAccess(username, pass); // 送出帳號密碼
               } catch (Exception e) {
                 e.printStackTrace();
               }
               g.setColor(255, 255, 255);
               g.drawString("「登入中」", disWidth + 95, disHeight + 140, 0);
               flushGraphics();
               while (!ConnectionServer.connFin) ; // Server是否回傳完資訊
               page = 0;
               drawDisplay();
               g.setColor(255, 255, 255);
               gameUserInfCount = 0;
               // 成功登入將繼續到下一頁面(第一次進入遊戲)
               if (GameMain.conn.getConnSucess() == 1) {
                 g.drawString("「登入成功」", disWidth + 95, disHeight + 140, 0);
                 flushGraphics();
                 RoleDataValue.userpass = pass;
                 page = 1;
                 changePage();
               } else if (GameMain.conn.getConnSucess() == 0) { // 登入,不是第一次遊戲
                 try {
                   page = -2;
                   g.drawString("「登入成功」", disWidth + 95, disHeight + 140, 0);
                   flushGraphics();
                   RoleDataValue.userpass = pass;
                   g.drawString("讀取使用者資料....", disWidth + 15, disHeight + 69, 0);
                   flushGraphics();
                   GameMain.conn.setGameName("");
                   while (!ConnectionServer.connFin) ; // Server是否回傳完資訊
                   g.drawString("人物狀態初始化.....", disWidth + 15, disHeight + 89, 0);
                   flushGraphics();
                   roleData.getFirstRoleStateForInternet(GameMain.conn.getRequestState());
                   roleData.loginSuccessStart();
                   g.drawString("地圖初始化..........", disWidth + 15, disHeight + 109, 0);
                   flushGraphics();
                 } catch (Exception e) {
                   e.printStackTrace();
                 }
                 runGame();
                 g.drawString("進入遊戲...", disWidth + 15, disHeight + 129, 0);
                 flushGraphics();
               } else {
                 g.drawString("「登入失敗」", disWidth + 95, disHeight + 140, 0);
                 flushGraphics();
               }
             }
           } else if (page == 1) { // 當畫面在遊戲說明時
             if (gameUserInfCount < gameUserInf.length) // 如果遊戲說明未結速時
             changePage();
             else { // 遊戲說明完成,畫面改變為輸入遊戲名稱
               page = 2;
               gameUserInfCount = 20;
               changePage();
             }
           } else if (page == 2) { // 輸入名稱完成,畫面改變為角色建立完成
             if (nickname.equals("")) g.drawString("「請輸入名稱」", disWidth + 90, disHeight + 140, 0);
             else {
               page = 3;
               changePage();
             }
           } else if (page == 3) { // 第一進入遊戲,完成輸入名稱
             page = -2;
             GameMain.conn.setGameName(nickname);
             while (!ConnectionServer.connFin) ; // Server是否回傳完資訊
             try {
               roleData.getFirstRoleStateForInternet(GameMain.conn.getRequestState());
               roleData.loginSuccessStart();
             } catch (Exception e) {
               e.printStackTrace();
             }
             runGame();
           }
           break;
         case 3: // 回主選單,上一頁
           if (page == 0) {
             page = -1;
             menustate = 0;
             menuNum = 3;
           }
           // 判斷當為GameInformation時,要回輸入帳號密碼
           if (page == 1 && gameUserInfCount == 5) page--;
           else if (page == 2 || page == 3) // 判斷當不是GameInformation時
           page--;
           // 切換GameInformaion的頁面
           if (page == 1) {
             gameUserInfCount -= 5 * gameUserInfPage;
             gameUserInfPage++;
             if (gameUserInfPage >= 3) gameUserInfPage = 2;
             changePage();
           } // 回到輸入姓名部份
           else if (page == 2) {
             // rolesprite=true;
             Thread.sleep(300);
             gameUserInfPage = 2;
             changePage();
           } else changePage();
           break;
       }
       showBufferString();
     }
   } catch (Exception e) {
   }
 }
Ejemplo n.º 23
0
  public GuiSetupGui(ShareNavDisplayable parent, boolean initialSetup) {
    super(Locale.get("guisetupgui.GUIOptions") /*GUI Options*/);
    this.parent = parent;
    this.initialSetup = initialSetup;
    try {
      long mem = Configuration.getPhoneAllTimeMaxMemory();
      if (mem == 0) {
        mem = Runtime.getRuntime().totalMemory();
      }
      mem = mem / 1024;
      memField =
          new TextField(
              Locale.get("guisetupgui.DefineMaxMem") /*Define maxMem (kbyte)*/,
              Long.toString(mem),
              8,
              TextField.DECIMAL);
      append(memField);
      String[] imenu = new String[7];
      imenu[0] = Locale.get("guisetupgui.UseIconMenu") /*Use icon menu*/;
      imenu[1] = Locale.get("guisetupgui.UseSetupIconMenu") /*Use icon menu for settings*/;
      imenu[2] = Locale.get("guisetupgui.FullscreenIconMenu") /*Fullscreen icon menu*/;
      imenu[3] = Locale.get("guisetupgui.SplitscreenIconMenu") /*Split screen icon menu*/;
      imenu[4] = Locale.get("guisetupgui.LargeTabButtons") /*Large tab buttons*/;
      imenu[5] = Locale.get("guisetupgui.IconsMappedOnKeys") /*Icons mapped on keys*/;
      // imenu[5] = Locale.get("guisetupgui.OptimiseForRouting")/*Optimise for routing*/;
      imenu[6] =
          Locale.get("guisetupgui.FavoritesInRouteIconMenu") /*Favorites in route icon menu*/;
      imenuOpts =
          new ChoiceGroup(
              Locale.get("guisetupgui.IconMenu") /*Icon Menu:*/, Choice.MULTIPLE, imenu, null);
      imenuOpts.setSelectedIndex(
          0, Configuration.getCfgBitSavedState(Configuration.CFGBIT_ICONMENUS));
      imenuOpts.setSelectedIndex(
          1, Configuration.getCfgBitSavedState(Configuration.CFGBIT_ICONMENUS_SETUP));
      imenuOpts.setSelectedIndex(
          2, Configuration.getCfgBitSavedState(Configuration.CFGBIT_ICONMENUS_FULLSCREEN));
      imenuOpts.setSelectedIndex(
          3, Configuration.getCfgBitSavedState(Configuration.CFGBIT_ICONMENUS_SPLITSCREEN));
      imenuOpts.setSelectedIndex(
          4, Configuration.getCfgBitSavedState(Configuration.CFGBIT_ICONMENUS_BIG_TAB_BUTTONS));
      imenuOpts.setSelectedIndex(
          5, Configuration.getCfgBitState(Configuration.CFGBIT_ICONMENUS_MAPPED_ICONS));
      // imenuOpts.setSelectedIndex(5,
      //		Configuration.getCfgBitSavedState(Configuration.CFGBIT_ICONMENUS_ROUTING_OPTIMIZED));
      imenuOpts.setSelectedIndex(
          6, Configuration.getCfgBitSavedState(Configuration.CFGBIT_FAVORITES_IN_ROUTE_ICON_MENU));
      append(imenuOpts);

      if (Configuration.getHasPointerEvents()) {
        String[] touch = new String[4];
        int i = 0;
        touch[i++] = Locale.get("guisetupgui.longMapTap");
        touch[i++] = Locale.get("guisetupgui.doubleMapTap");
        touch[i++] = Locale.get("guisetupgui.singleMapTap");
        touch[i++] = Locale.get("guisetupgui.clickableMarkers");
        mapTapFeatures =
            new ChoiceGroup(
                Locale.get("guisetupgui.MapTapFeatures") /*Map Touch Features*/,
                Choice.MULTIPLE,
                touch,
                null);
        i = 0;
        mapTapFeatures.setSelectedIndex(
            i++, Configuration.getCfgBitState(Configuration.CFGBIT_MAPTAP_LONG));
        mapTapFeatures.setSelectedIndex(
            i++, Configuration.getCfgBitState(Configuration.CFGBIT_MAPTAP_DOUBLE));
        mapTapFeatures.setSelectedIndex(
            i++, Configuration.getCfgBitState(Configuration.CFGBIT_MAPTAP_SINGLE));
        mapTapFeatures.setSelectedIndex(
            i++, Configuration.getCfgBitState(Configuration.CFGBIT_CLICKABLE_MAPOBJECTS));
        append(mapTapFeatures);
      }

      // search options
      int iMax = 3;
      if (Configuration.getHasPointerEvents()) {
        iMax++;
      }
      // #if polish.android
      iMax++;
      // #endif
      String[] search = null;
      search = new String[iMax];
      int searchnum = 0;
      search[searchnum++] = Locale.get("guisetupgui.scroll") /*Scroll result under cursor*/;
      search[searchnum++] = Locale.get("guisetupgui.scrollall") /*Scroll all results*/;
      if (Configuration.getHasPointerEvents()) {
        search[searchnum++] = Locale.get("guisetupgui.numberkeypad") /*Enable virtual keypad*/;
      }
      search[searchnum++] =
          Locale.get(
              "guisetupgui.SuppressSearchWarning") /*Suppress warning about exceeding max results*/;
      // #if polish.android
      search[searchnum++] =
          Locale.get("guisetupgui.ShowNativeKeyboard") /*Show native keyboard in search*/;
      // #endif
      searchSettings =
          new ChoiceGroup(
              Locale.get("guisetupgui.searchopts") /*Search options:*/,
              Choice.MULTIPLE,
              search,
              null);
      /* only display search settings available on the device */
      // maximum search option entries
      searchnum = 0;
      searchSettings.setSelectedIndex(
          searchnum++, Configuration.getCfgBitSavedState(Configuration.CFGBIT_TICKER_ISEARCH));
      searchSettings.setSelectedIndex(
          searchnum++, Configuration.getCfgBitSavedState(Configuration.CFGBIT_TICKER_ISEARCH_ALL));
      if (Configuration.getHasPointerEvents()) {
        searchSettings.setSelectedIndex(
            searchnum++,
            Configuration.getCfgBitSavedState(Configuration.CFGBIT_SEARCH_TOUCH_NUMBERKEYPAD));
      }
      searchSettings.setSelectedIndex(
          searchnum++,
          Configuration.getCfgBitSavedState(Configuration.CFGBIT_SUPPRESS_SEARCH_WARNING));
      // #if polish.android
      searchSettings.setSelectedIndex(
          searchnum++,
          Configuration.getCfgBitSavedState(Configuration.CFGBIT_SEARCH_SHOW_NATIVE_KEYBOARD));
      // #endif
      append(searchSettings);
      String[] searchLayout = new String[2];
      searchLayout[0] = Locale.get("guidiscover.SearchWholeNames") /*Search for whole names*/;
      searchLayout[1] = Locale.get("guidiscover.SearchWords") /*Search for words*/;
      searchLayoutGroup =
          new ChoiceGroup(
              Locale.get("guidiscover.SearchStyle") /*Search style*/,
              Choice.EXCLUSIVE,
              searchLayout,
              null);
      searchLayoutGroup.setSelectedIndex(
          Configuration.getCfgBitSavedState(Configuration.CFGBIT_WORD_ISEARCH) ? 1 : 0, true);
      append(searchLayoutGroup);

      int searchMax = Configuration.getSearchMax();
      searchField =
          new TextField(
              Locale.get("guisetupgui.DefineMaxSearch") /*Max # of search results*/,
              Integer.toString(searchMax),
              8,
              TextField.DECIMAL);
      append(searchField);

      float dist = Configuration.getPoiSearchDistance();
      poiSearchDistance =
          new TextField(
              Locale.get("guisetupgui.PoiDistance") /*POI Distance: */,
              Float.toString(dist),
              8,
              TextField.ANY);
      append(poiSearchDistance);

      String[] otherSettings = new String[1];
      otherSettings[0] =
          Locale.get("guisetupgui.ExitWithBackButton") /* Back button exits application*/;
      otherGroup =
          new ChoiceGroup(
              Locale.get("guisetupgui.otherOptions") /* Other options */,
              Choice.MULTIPLE,
              otherSettings,
              null);
      otherGroup.setSelectedIndex(
          0,
          Configuration.getCfgBitSavedState(
              Configuration.CFGBIT_EXIT_APPLICATION_WITH_BACK_BUTTON));
      append(otherGroup);

      addCommand(CMD_SAVE);
      addCommand(CMD_CANCEL);

      // Set up this Displayable to listen to command events
      setCommandListener(this);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }