⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ictankcanvas.java

📁 本j2me坦克游戏是在Nokia平台下开发的
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                passPos--;
              }
              else {
                passPos = 5;
              }
              break;
            case Canvas.RIGHT:
              if (passPos < 5) {
                passPos++;
              }
              else {
                passPos = 1;
              }
              break;
            case Canvas.UP:
              if (passPos < 5) {
                if (password[passPos - 1] == '0') {
                  password[passPos - 1] = 'z';
                }
                else if (password[passPos - 1] == 'a') {
                  password[passPos - 1] = 'Z';
                }
                else if (password[passPos - 1] == 'A') {
                  password[passPos - 1] = '9';
                }
                else {
                  password[passPos - 1]--;
                }
              }
              break;

            case Canvas.DOWN:
              if (passPos < 5) {
                if (password[passPos - 1] == 'z') {
                  password[passPos - 1] = '0';
                }
                else if (password[passPos - 1] == 'Z') {
                  password[passPos - 1] = 'a';
                }
                else if (password[passPos - 1] == '9') {
                  password[passPos - 1] = 'A';
                }
                else {
                  password[passPos - 1]++;
                }
              }
              break;

            case Canvas.FIRE:
              if (passPos == 5) {
                gameSubStatus = 7;
              }
              else {
                passPos = 5;

              }
            default:
              break;
          }
        }
        else if (gameSubStatus == 9) {
          switch (j) {
            case Canvas.LEFT:
              if (passPos > 1) {
                passPos--;
              }
              else {
                passPos = 2;
              }
              break;
            case Canvas.RIGHT:
              if (passPos < 2) {
                passPos++;
              }
              else {
                passPos = 1;
              }
              break;

            case Canvas.UP:
              if (passPos == 1) {
                if (level > 1) {
                  level--;
                }
                else {
                  level = pasLevel;
                }
              }
              break;
            case Canvas.DOWN:
              if (passPos == 1) {
                if (level < pasLevel) {
                  level++;
                }
                else {
                  level = 1;
                }
              }
              break;

            case Canvas.FIRE:
              if (passPos == 2) {
                gameSubStatus = 10;
              }
              else {
                passPos = 2;

              }
            default:
              break;
          }
        }

        break;
      case 3: //game
        if (!showLevel) {
          switch (keyCode) {
            case -7:
              if (paused1 == false) {
                paused1 = true;
                pauseStart = true;
              }
              else {
                paused1 = false;
                pauseStart = false;
                pauseBack = true;
              }
              break;
            case -6:
              try {
                parent.destroyApp(false);
                parent.notifyDestroyed();
              }
              catch (MIDletStateChangeException ex) {}
              default:
                break;
          }
          switch (j) {
            case Canvas.LEFT:
              if (canmove) {
                hero.direction = 0x11;
              }
              break;

            case Canvas.RIGHT:
              if (canmove) {
                hero.direction = 0x12;
              }
              break;

            case Canvas.UP:
              if (canmove) {
                hero.direction = 0x13;
              }
              break;

            case Canvas.DOWN:

              // paused1 = false;
              // System.out.println("paused1 = false;");
              if (canmove) {
                hero.direction = 0x14;
              }
              break;

            case Canvas.FIRE:

              // paused1 = true;
              // System.out.println("paused1 = true;");
              if ( (!hero.shootFlag) && (hero.status <= 1) && (canmove)) {
                hero.shootFlag = true;
                //           if(s.getState() == 1){
                sD[1].stop();
                sD[0].stop();
                sD[1].play(1);
                //           }
                hero.bulletNo = 0;
                fireBullet(0, hero.direction, hero.posX, hero.posY, 3);
              }
              break;
            default:
              break;
          }
        }

        break;

      case 4: //result
        if (gameSubStatus == 3) {
          gameSubStatus++;
        }
        else if (gameSubStatus == 5) {
          switch (j) {
            case Canvas.LEFT:
            case Canvas.UP:
              if (gameSelect > 1) {
                gameSelect--;
              }
              else {
                gameSelect = 3;
              }
              break;

            case Canvas.RIGHT:
            case Canvas.DOWN:
              if (gameSelect < 3) {
                gameSelect++;
              }
              else {
                gameSelect = 1;
              }
              break;

            case Canvas.FIRE:
              if (gameSelect == 1) {
                if (gameWin) {
                  level++;
                  if (level > 20) {
                    level = 1;
                  }
                  initLevel();
                  setLevel(level);
                  gameStatus = 3;
                  gameSubStatus = 1;
                }
                else {
                  life = 3;
                  initLevel();
                  setLevel(level);
                  gameStatus = 3;
                  gameSubStatus = 1;
                }
              }
              else if (gameSelect == 2) {
                gameStatus = 2;
                gameSubStatus = 1;
                gameSelect = 1;
              }
              else if (gameSelect == 3) {
                parent.exitRequested();

              }
            default:
              break;
          }

        }
        break;
      case 5: //game over
      default:
        break;
    }
  }

  public void keyReleased(int keyCode) {
    int j = getGameAction(keyCode);
    switch (j) {
      case Canvas.LEFT:
      case Canvas.RIGHT:
      case Canvas.UP:
      case Canvas.DOWN:
        hero.direction = hero.direction & 0x0f;
      default:
        return;
    }
  }

  protected void pointerPressed(int x, int y) {
  } //end pointerPressed()

  private void titlePaint(Graphics g) {
    title_y = (height - logo2.getHeight() - logo3.getHeight() - 8) / 2;
    switch (gameSubStatus) {
      case 1:
        g.setColor(0xffffff);
        g.fillRect(0, 0, width, height);

        title_x = -logo1.getWidth();

        gameSubStatus++;
        g.setColor(0);
        g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN,
                               Font.SIZE_MEDIUM));
        g.drawString("选项", width - fontWidth, height - fontHeight, 20);

        break;

      case 2:
        g.setColor(0xffffff);
        g.fillRect(0, title_y + (logo3.getHeight() - logo1.getHeight()), width,
                   logo1.getHeight());

        g.drawImage(logo1, title_x,
                    title_y + (logo3.getHeight() - logo1.getHeight()),
                    g.TOP | g.LEFT);

        if (title_x < (width - logo1.getWidth()) / 2) {
          title_x += 12;
        }
        else {
          g.drawImage(logo1, (width - logo1.getWidth()) / 2,
                      title_y + (logo3.getHeight() - logo1.getHeight()),
                      g.TOP | g.LEFT);
          gameSubStatus++;
          title_x = width;
        }

        g.setColor(0);
        g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN,
                               Font.SIZE_MEDIUM));
        g.drawString("选项", width - fontWidth, height - fontHeight, 20);

        break;

      case 3:
        g.setColor(0xffffff);
        g.fillRect(0, title_y + logo3.getHeight() + 8, width, logo2.getHeight());

        g.drawImage(logo2, title_x, title_y + logo3.getHeight() + 8,
                    g.TOP | g.LEFT);

        if (title_x > (width - logo2.getWidth()) / 2) {
          title_x -= 8;
        }
        else {
          gameSubStatus++;
          ictimer.timeCounter = 0;
          g.drawImage(logo3, (width - logo1.getWidth()) / 2 + 66, title_y,
                      g.TOP | g.LEFT);
          //g.drawImage(logo3, (width+logo1.getWidth())/2, height/2-(logo3.getHeight()-logo1.getHeight()), g.TOP|g.LEFT);
          //title_x = width;
        }

        g.setColor(0);
        g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN,
                               Font.SIZE_MEDIUM));
        g.drawString("选项", width - fontWidth, height - fontHeight, 20);

        break;

      case 4:
        if (ictimer.timeCounter > 3) {
          gameSubStatus++;
        }

        break;

        //add here to tell the story
      case 5:
        g.setColor(0x0);
        g.fillRect(0, 0, width, height);
        g.setColor(0xffffff);
        g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN,
                               Font.SIZE_MEDIUM));
        g.drawString("选项", width - fontWidth, height - fontHeight, 20);
        gameSubStatus += 2;
      case 6:

        /*           case 9:
                       ictimer.timeCounter = 0;
                       gameStatus = 2;
                       gameSubStatus = 1;
                   default:
                       break;
               }*/

        //switch(gameSubStatus) {
        /*   case 1:
             if ( ictimer.timeCounter < 2 ){

          try {
              t_logo = Image.createImage("/logo.png");

               g.setColor(0xffffff);
               g.fillRect(0, 0, width, height);
          } catch (IOException ioexception) { ioexception.printStackTrace();}

              g.drawImage(t_logo, (width-t_logo.getWidth())/2, (height-t_logo.getHeight())/2, g.TOP|g.LEFT);

             } else {

                if ( firstTime ){
                    g.setColor(0xffffff);
                    g.fillRect(0, 0, width, height);
                    t_logo = null;
                    firstTime = false;
                }
                g.translate((width-ic.getWidth())/2, ((height-ic.getHeight()-logo.getHeight())/2+logo.getHeight()) );

                g.setClip(0, 0, title_w, ic.getHeight());
                g.drawImage(ic, 0, 0, g.TOP|g.LEFT);
                if ( title_w < ic.getWidth() ){
              //	System.out.println("ic.getWidth()=" +ic.getWidth());
               title_w += 8;
              }else {
                    gameSubStatus ++;
                    ictimer.timeCounter = 0;
                    title_h = 0;
                }
            }
               break;*/

      case 7:

        //if ( ictimer.timeCounter < 2 )
        //    g.drawImage(logo, (width-logo.getWidth())/2, (height-ic.getHeight()-logo.getHeight())/2, g.TOP|g.LEFT);
        //else{
        g.setColor(0x0);
        g.fillRect(0, 0, width, height);
        g.setColor(0xffffff);
        g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN,
                               Font.SIZE_MEDIUM));
        g.drawString("选项", width - fontWidth, height - fontHeight, 20);
        //   g.fillRect(0, 0, width, title_h);

        //   g.fillRect(0, height-title_h, width, title_h);

        //   if ( title_h <= (height/2 ))
        //       title_h += 4;
        //   else {
        //ic = null;
        //logo = null;
        // Load the title image
        try {
          ic = Image.createImage("/tank_e.png");
        }
        catch (Exception exception) {
          System.out.println(exception);
        }
        gameSubStatus++;
        //    }
        fadeCol = 0x0;
        //}
        break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -