layer.java

来自「一款直版动作过关游戏」· Java 代码 · 共 89 行

JAVA
89
字号


import javax.microedition.lcdui.Graphics;

public abstract class layer
{

    int x;
    int y;
    int width;
    int height;
    boolean visible; //可见

    layer(int width, int height)
    {
        visible = true;
        setWidth(width);
        setHeight(height);
    }

    public void setPosition(int x, int y)
    {
        this.x = x;
        this.y = y;
    }

    public void move(int dx, int dy)
    {
        x += dx;
        y += dy;
    }

    public final int getX()
    {
        return x;
    }

    public final int getY()
    {
        return y;
    }

    public final int getWidth()
    {
        return width;
    }

    public final int getHeight()
    {
        return height;
    }

    public void setVisible(boolean visible)
    {
        this.visible = visible;
    }

    public final boolean isVisible()
    {
        return visible;
    }

    public abstract void paint(Graphics g);

    void setWidth(int width)
    {
        if(width < 0)
        {
            throw new IllegalArgumentException();
        } else
        {
            this.width = width;
            return;
        }
    }

    void setHeight(int height)
    {
        if(height < 0)
        {
            throw new IllegalArgumentException();
        } else
        {
            this.height = height;
            return;
        }
    }
}

⌨️ 快捷键说明

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