human.java

来自「以传奇中的人物和怪物作为角色」· Java 代码 · 共 117 行

JAVA
117
字号
package com.liuwan.j2me.monster;

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

/**
 * <p>Title: Develop game research</p>
 *
 * <p>Description: Develop game research</p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: Liuwan studio</p>
 *
 * @author Liuwan
 * @version 1.0
 */
public class Human extends Sprite implements Runnable{
    private int x;
    private int y;
    private int life = 30;
    private boolean onBeat = false;
    private Graphics graphics;
    private MonsterCanvas gameCanvas;


    public Human(Image image) {
        super(image);
    }

    public Human(Image image, int frameWidth, int frameHeight) {
        super(image, frameWidth, frameHeight);
    }

    public Human(Sprite s) {
        super(s);
    }
    public void start(){
        Thread t = new Thread(this);
        t.start();
    }
    public void run(){
        while(true){
            if(onBeat){
                beat();
            }
        }
    }

    public void beat() {
        int currentFrame = 0;
        while (currentFrame < 6) {
            this.setFrame(currentFrame++);
            this.setPosition(this.getX(), this.getY());
            try {
                Thread.sleep(100);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            this.paint(graphics);
            gameCanvas.draw(graphics);
        }
        try {
            Thread.sleep(500);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        Monster monster = gameCanvas.getMonster();
        monster.setLife(monster.getLife() - 2);
        this.setFrame(0);
        this.setPosition(this.getX(), this.getY());
        this.paint(graphics);
        gameCanvas.draw(graphics);
    }
    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void setLife(int life) {
        this.life = life;
    }

    public void setOnBeat(boolean onBeat) {
        this.onBeat = onBeat;
    }

    public void setGraphics(Graphics graphics) {
        this.graphics = graphics;
    }

    public void setGameCanvas(MonsterCanvas gameCanvas) {
        this.gameCanvas = gameCanvas;
    }

    public int getLife() {
        return life;
    }

    public boolean isOnBeat() {
        return onBeat;
    }

    public Graphics getGraphics() {
        return graphics;
    }

    public MonsterCanvas getGameCanvas() {
        return gameCanvas;
    }


}

⌨️ 快捷键说明

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