Beispiel #1
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();
    }
  }
Beispiel #2
0
 public GameMenu(GameMain midlet_ /*,ConnectionServer conn_,RoleDataValue roleData_*/) {
   // true->使用GameAction(boolean suppressKeyEvents) , false->不使用GameAction(boolean
   // suppressKeyEvents)
   super(false);
   // 使用全螢幕
   setFullScreenMode(true);
   midlet = midlet_;
   // music = music_;
   // roleData = roleData_;
   display = midlet.getDisplay();
   layMa = new LayerManager();
   spInterface = new Sprite(createImage("/image/gameInterface/inface.png"), bgWidth, bgHeight);
   spName = new Sprite(createImage("/image/gameInterface/Title.png"), 84, 15);
   menustate = 0;
   menuNum = 3;
   // setFullScreenMode(true);
   g = getGraphics();
   /*if(!(getWidth()<176) || !(getHeight()<208)){
   	disWidth = (getWidth()-176)/2;//抓取螢幕的中心點
   	disHeight = (getHeight()-208)/2;//抓取螢幕的中心點
   }*/
   // 設定Sprite位置
   spName.setPosition(80, 20);
   spInterface.setPosition(0, 0);
   // 加入到LayerManager
   layMa.append(spName);
   spName.setVisible(false);
   layMa.append(spInterface);
   spInterface.setFrame(0);
   System.out.println("start");
   start();
 }
Beispiel #3
0
  /**
   * Metoda wczytujaca obrazki z zasobow i tworzaca tlo oraz ikony
   *
   * @throws IOException
   */
  public void loadResources() throws IOException {
    int i, j;

    Image image = Image.createImage("/res/layer.png"); // wczytanie obrazku tla
    Image iconsImage =
        Image.createImage("/res/icons.png"); // wczytanie obrazu przechowujacego ikony przyciskow
    Image logoImage =
        Image.createImage(
            "/res/blue_logo_small.png"); // wczytanie obrazku przechowujacego male logo Bluetooth
    int rows = getHeight() / 16;
    int cols = getWidth() / 16;

    backgroundLayer = new TiledLayer(cols, rows, image, 16, 16);
    backgroundLayer.setCell(0, 0, 3);

    for (i = 0; i < cols - 2; i++) backgroundLayer.setCell(i + 1, 0, 2);
    backgroundLayer.setCell(cols - 1, 0, 1);
    for (i = 1; i < rows - 1; i++) {
      backgroundLayer.setCell(0, i, 4);
      backgroundLayer.setCell(cols - 1, i, 8);
    }
    backgroundLayer.setCell(0, rows - 1, 5);
    for (i = 0; i < cols - 2; i++) backgroundLayer.setCell(i + 1, rows - 1, 6);
    backgroundLayer.setCell(cols - 1, rows - 1, 7);

    for (i = 1; i < cols - 1; i++) for (j = 1; j < rows - 1; j++) backgroundLayer.setCell(i, j, 9);

    backgroundLayer.setPosition(
        (getWidth() % 16) / 2,
        (getHeight() % 16) / 2); // przesuniecie utworzonej warstwy na srodek wyswietlacza

    playPauseSprite = new Sprite(iconsImage, 32, 32);
    playPauseSprite.setFrame(PLAY_ICON);
    nextSprite = new Sprite(iconsImage, 32, 32);
    nextSprite.setFrame(NEXT_ICON); // ustawienie sprite'a tak, aby wyswietlal ikone 'Next'
    previousSprite = new Sprite(iconsImage, 32, 32);
    previousSprite.setFrame(
        PREVIOUS_ICON); // ustawienie sprite'a tak, aby wyswietlal ikone 'Previous'
    bluetoothLogoSmallSprite = new Sprite(logoImage, 8, 14);
  }
Beispiel #4
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();
   }
 }
  public void drawButton(GuiButton selectedButton) {
    if (!drawButton) {
      if (!Touch.isInputHandled() && Touch.isPressed() && checkPoint(Touch.getX(), Touch.getY())) {
        Touch.setInputHandled();
      }
      return;
    }

    if (getButtonImage() != buttonImage) {
      initButtonSprite();
    }

    boolean flag = false;

    if ((!Touch.isInputHandled() || cc.currentScreen == null)
        && Touch.isPressed()
        && checkPoint(Touch.getX(), Touch.getY())) {
      flag = true;
    } else if (selectedButton == this) {
      flag = true;
    }

    int i = getHooverState(flag);

    int y = yPos;

    if (selectedButton != null
        && selectedButton.yPos + selectedButton.getHeight() > Comcraft.screenHeight) {
      y -= selectedButton.yPos + selectedButton.getHeight() - Comcraft.screenHeight + 10;
    }

    buttonSprite.setPosition(xPos, y);
    buttonSprite.setFrame(i);
    buttonSprite.paint(cc.g);

    drawButtonString(flag, y);
  }
Beispiel #6
0
  /** Metoda sprawdzajaca stan klawiszy i aktualizujaca zmienne odpowiedzialne za stan gry */
  public void updateState() {
    int keys = getKeyStates();

    if (bluetoothPlayer.getIsConnectedToServer() == true) {
      if (displayedScreen == PLAYER_SCREEN) { // jesli wyswietlany jest ekran odtwarzacza
        // jesli przycisk 'Play / Pause' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & FIRE_PRESSED) != 0) && (nextPressed == false) && (previousPressed == false)) {
          if (playPauseSprite.getFrame() == PLAY_ICON) {
            playPauseSprite.setFrame(PLAY_ICON_PRESSED);
          } else if (playPauseSprite.getFrame() == PAUSE_ICON) {
            playPauseSprite.setFrame(PAUSE_ICON_PRESSED);
          }

          if (firePressed == false) soundPlayer.play(SoundPlayer.CLICK_SOUND);

          firePressed = true;
        }
        // przycisk zostal zwolniony
        else if (((keys & FIRE_PRESSED) == 0) && (firePressed == true)) {
          if (playPauseSprite.getFrame() == PLAY_ICON_PRESSED) { // zmiana stanu przycisku
            bluetoothPlayer.play();
            playPauseSprite.setFrame(PAUSE_ICON);

          } else if (playPauseSprite.getFrame() == PAUSE_ICON_PRESSED) {
            bluetoothPlayer.pause();
            playPauseSprite.setFrame(PLAY_ICON);
          }

          firePressed = false;
        }
        // jesli przycisk 'Next' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & RIGHT_PRESSED) != 0) && (firePressed == false) && (previousPressed == false)) {
          if (nextSprite.getFrame() == NEXT_ICON) nextSprite.setFrame(NEXT_ICON_PRESSED);

          if (nextPressed == false) {
            soundPlayer.play(SoundPlayer.CLICK_SOUND);
          }

          nextPressed = true;
        }
        // przycisk zostal zwolniony
        else if (((keys & RIGHT_PRESSED) == 0) && (nextPressed == true)) {
          if (nextSprite.getFrame() == NEXT_ICON_PRESSED) nextSprite.setFrame(NEXT_ICON);

          bluetoothPlayer.addCommandToProcess(BluetoothPlayer.COMMAND_NEXT);
          nextPressed = false;

          if (bluetoothPlayer.getTotalTime() != 0) // jesli utwor jest odtwarzany lub zapauzowany
          playPauseSprite.setFrame(PAUSE_ICON);
        }
        // jesli przycisk 'Previous' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & LEFT_PRESSED) != 0) && (nextPressed == false) && (firePressed == false)) {
          if (previousSprite.getFrame() == PREVIOUS_ICON)
            previousSprite.setFrame(PREVIOUS_ICON_PRESSED);

          if (previousPressed == false) {
            soundPlayer.play(SoundPlayer.CLICK_SOUND);
          }

          previousPressed = true;
        }
        // przycisk zostal zwolniony
        else if (((keys & LEFT_PRESSED) == 0) && (previousPressed == true)) {
          if (previousSprite.getFrame() == PREVIOUS_ICON_PRESSED)
            previousSprite.setFrame(PREVIOUS_ICON);

          bluetoothPlayer.addCommandToProcess(BluetoothPlayer.COMMAND_PREV);
          previousPressed = false;

          if (bluetoothPlayer.getTotalTime() != 0) // jesli utwor jest odtwarzany lub zapauzowany
          playPauseSprite.setFrame(PAUSE_ICON);
        }
        // jesli przycisk 'Up' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & UP_PRESSED) != 0)
            && (previousPressed == false)
            && (nextPressed == false)
            && (firePressed == false)) {
          if (previousPressed == false) {
            soundPlayer.play(SoundPlayer.CLICK_SOUND);
          }

          bluetoothPlayer.volumeUp();
        }
        // jesli przycisk 'Down' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & DOWN_PRESSED) != 0)
            && (previousPressed == false)
            && (nextPressed == false)
            && (firePressed == false)) {
          if (previousPressed == false) {
            soundPlayer.play(SoundPlayer.CLICK_SOUND);
          }

          bluetoothPlayer.volumeDown();
        }
      }
    }
    // jesli wyswietlany jest ekran biblioteki muzycznej
    if (displayedScreen == MEDIA_LIBRARY_SCREEN) {
      // jesli przycisk akcji jest wcisniety, a pozostale nie sa wcisniete
      if (((keys & FIRE_PRESSED) != 0) && (nextPressed == false) && (previousPressed == false)) {
        buttonPressedInARowCount = 0;
        if (firePressed == false) soundPlayer.play(SoundPlayer.CLICK_SOUND);
        firePressed = true;
      }
      // przycisk zostal zwolniony
      else if (((keys & FIRE_PRESSED) == 0) && (firePressed == true)) {
        buttonPressedInARowCount = 0;
        firePressed = false;
      }
      // jesli przycisk 'Down' jest wcisniety, a pozostale nie sa wcisniete
      if (((keys & DOWN_PRESSED) != 0) && (firePressed == false) && (previousPressed == false)) {
        if (nextPressed == true) buttonPressedInARowCount++;
        else buttonPressedInARowCount = 0;
        nextPressed = true;
      }
      // button was released or hold down for more than MAX_BUTTON_PRESSED_IN_A_ROW_COUNT clicks
      if ((((keys & DOWN_PRESSED) == 0) && (nextPressed == true))
          || (((keys & DOWN_PRESSED) != 0)
              && (buttonPressedInARowCount >= MAX_BUTTON_PRESSED_IN_A_ROW_COUNT))) {
        // jesli wybrany utwor nie byl ostatni na liscie
        if (bluetoothPlayer.getMediaLibrary().selectItemInMediaLibrary(NEXT_ITEM) == true) {
          if (mediaLibrarySelectedItemOnScreen < mediaLibraryItemsNumberOnScreen - 1)
            mediaLibrarySelectedItemOnScreen++;
        }

        // nextPressed is set to false only if button was released
        if ((((keys & DOWN_PRESSED) != 0)
                && (buttonPressedInARowCount >= MAX_BUTTON_PRESSED_IN_A_ROW_COUNT))
            == false) nextPressed = false;
      }

      // jesli przycisk 'Previous' jest wcisniety, a pozostale nie sa wcisniete
      if (((keys & UP_PRESSED) != 0) && (nextPressed == false) && (firePressed == false)) {
        if (previousPressed == true) buttonPressedInARowCount++;
        else buttonPressedInARowCount = 0;
        previousPressed = true;
      }

      // button was released or hold down for more than MAX_BUTTON_PRESSED_IN_A_ROW_COUNT clicks
      if ((((keys & UP_PRESSED) == 0) && (previousPressed == true))
          || (((keys & UP_PRESSED) != 0)
              && (buttonPressedInARowCount >= MAX_BUTTON_PRESSED_IN_A_ROW_COUNT))) {

        // jesli wybrany utwor nie byl pierwszy na liscie
        if (bluetoothPlayer.getMediaLibrary().selectItemInMediaLibrary(PREVIOUS_ITEM) == true) {
          if (mediaLibrarySelectedItemOnScreen > 0) mediaLibrarySelectedItemOnScreen--;
        }

        // previousPressed is set to false only if button was released
        if ((((keys & UP_PRESSED) != 0)
                && (buttonPressedInARowCount >= MAX_BUTTON_PRESSED_IN_A_ROW_COUNT))
            == false) previousPressed = false;
      }
    }
    // if volume level has changed
    if (volumeLevel != bluetoothPlayer.getVolumeLevel()) {
      showVolume = 15;
      volumeLevel = bluetoothPlayer.getVolumeLevel();
    }

    if (bluetoothPlayer.getIsConnectedToServer() == false) {
      if (buttonsLocation < 70) buttonsLocation += 5;
    }

    if ((bluetoothPlayer.getIsConnectedToServer() == true) && (buttonsLocation > 0)) {
      buttonsLocation -= 5;
    }

    if (bluetoothPlayer.getStateChanged()) {
      String state = bluetoothPlayer.getPlayingState();

      if (state != null) {
        if (state.equals("PLAY") || state.equals("OTHER")) {
          playPauseSprite.setFrame(PAUSE_ICON);
        } else if (state.equals("PAUSE") || state.equals("STOP"))
          playPauseSprite.setFrame(PLAY_ICON);
      }

      soundPlayer.play(SoundPlayer.POPUP_SOUND);
    }
  }
Beispiel #7
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) {
   }
 }