Esempio n. 1
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();
   }
 }
Esempio 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();
    }
  }
Esempio n. 3
0
 public void runGame() {
   try {
     GameMain.music.stop();
     display.setCurrent(new mapCanvars(display, roleData, midlet));
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 4
0
 // 建立圖片
 public Image createImage(String pathImg) {
   img = null;
   try {
     img = Image.createImage(pathImg);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return img;
 }
Esempio n. 5
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();
   }
 }
Esempio n. 6
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();
   }
 }
Esempio n. 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) {
   }
 }