bonus.java

来自「JAVAME Core technology and best practice」· Java 代码 · 共 126 行

JAVA
126
字号
package com.j2medev.chapter5;
import javax.microedition.lcdui.*;

public class Bonus implements MyGameInterface {

  private byte bonusType = BONUS_SHOE;
  private Image imgBonus;
  private int bonusX = 0, bonusY = 0;
  private int tmpBonusX = 0;
  private byte isCatched = 0;


  /**
   * 构造函数
   */
  public Bonus(Image imgBonus, byte bonusType, int bonusX, int bonusY) {
    this.imgBonus = imgBonus;
    this.bonusType = bonusType;
    this.tmpBonusX = bonusX * 16;
    this.bonusX = this.tmpBonusX;
    this.bonusY = bonusY * 16;
  }


  /**
   * 得到X值
   * @return int
   */
  public int getBonusX() {
    return bonusX;
  }

  public int getTmpBonusX() {
    return tmpBonusX;
  }


  /**
   * 设置X值
   * @param bonusX int
   */
  public void setBonusX(int bonusX) {
    this.bonusX = bonusX;
  }

  public void setTmpBonusX(int tmpBonusX) {
    this.tmpBonusX = tmpBonusX;
  }


  /**
   * 得到Y值
   * @return int
   */
  public int getBonusY() {
    return bonusY;
  }


  /**
   * 设置Y值
   * @param bonusY int
   */
  public void setBonusY(int bonusY) {
    this.bonusY = bonusY;
  }


  /**
   * 得到宽度
   * @return int
   */
  public int getBonusWidth() {
    return imgBonus.getWidth();
  }


  /**
   * 得到高度
   * @return int
   */
  public int getBonusHeight() {
    return imgBonus.getHeight();
  }


  /**
   * 得到奖品的类型
   * @return int
   */
  public byte getBonusType() {
    return bonusType;
  }


  /**
   * 得到是否被拿到的状态
   * @return boolean
   */
  public byte getIsCatched() {
    return isCatched;
  }

  public void setIsCatched(byte isCatched) {
    this.isCatched = isCatched;
  }


  /**
   * paint函数
   * @param g Graphics
   * @param offsetX int
   */
  int i;
  public void paint(Graphics g, int offsetX) {
    if (i == 0) {
      i = 1;
    } else {
      i = 0;
    }
    g.drawImage(imgBonus, tmpBonusX + offsetX, bonusY + i,
                Graphics.TOP | Graphics.LEFT);
    bonusX = tmpBonusX + offsetX;
  }
}

⌨️ 快捷键说明

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