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

📄 qianting.java

📁 一个不错的学习游戏,很适合初学者! 希望大家喜欢!
💻 JAVA
字号:
package qian;

import javax.microedition.lcdui.*;
import java.util.*;

/**
 *
 */

public class QianTing {
  Vector booms = new Vector();
  static Image pic1; //灰潜艇右
  static Image pic2; //红潜艇左
  static Image pic3; // 灰潜艇左
  static Image pic4; //红潜艇右
  //static Image imgf;
  int x = 0; //x轴的位置
  int y = 0;
  int type; //type=-100 隐形
  int direct; //0:向右,1:向左
  private Graphics g; //画布
  static Image[] fires=new Image[3];
  int fireCount;

  Timer btimer;
  boolean isBoomed;
  private GameCanvas canvas = null;

  static {
    try {

      pic1 = Image.createImage("/res/q1.png");
      pic2 = Image.createImage("/res/q2.png");
      pic3 = Image.createImage("/res/h2.png");
      pic4 = Image.createImage("/res/r1.png");

      for(int i=0;i<fires.length;i++){
        fires[i]=Image.createImage("/res/f"+i+".png");
      }

    }
    catch (Exception e) {
    }

  }

  public QianTing(GameCanvas gc) {
    this.canvas = gc;
    Random r = new Random();
    type = Math.abs(r.nextInt()) % 2;
    direct = Math.abs(r.nextInt()) % 2;
    if (direct == 0) {
      x = -pic1.getWidth();
    }
    else {
      x = canvas.getWidth();
    }
    y = 78 + Math.abs(r.nextInt()) % (99 - pic1.getHeight());

  }

  public void paint(Graphics g) {
    //to do:
    if (type != -100) {
      if (isBoomed == false) {
        if (type == 0 && direct == 0) {
          g.drawImage(pic1, x, y, Graphics.TOP | Graphics.LEFT);
        }
        else if (type == 0 && direct == 1) {
          g.drawImage(pic3, x, y, Graphics.TOP | Graphics.LEFT);
        }
        else if (type == 1 && direct == 1) {
          g.drawImage(pic2, x, y, Graphics.TOP | Graphics.LEFT);
        }
        else if (type == 1 && direct == 0) {
          g.drawImage(pic4, x, y, Graphics.TOP | Graphics.LEFT);
        }

      }
      else {
        int index=new Random().nextInt() % 3;
        index=Math.abs(index);
        g.drawImage(fires[index], x, y, Graphics.TOP | Graphics.LEFT);
      }
    }
    //画boom
    for (int i = 0; i < booms.size(); i++) {
      Boom2 b2 = (Boom2) booms.elementAt(i);
      b2.paint(g);
    }

  }

  public int Qxputter() {
    return x;
  }

  public int Qyputter() {
    return y;
  }

  public void addBoom(QianTing qt) {
    if (booms.size() == 0) {
      Boom2 b = new Boom2(qt.x + 5, qt.y);
      booms.addElement(b);
    }

  }

}

⌨️ 快捷键说明

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