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

📄 screen.java~27~

📁 j2me源代码
💻 JAVA~27~
字号:
package pinball;import javax.microedition.lcdui.*;public class Screen extends Canvas {    private Font ftSmall;   //小字体    private Font ftMedium;  //中字体    private Font ftLarge;   //大字体    private Font font;    public static int width;  //宽度    public static int height; //高度    private static final int TL_ANCHOR = Graphics.TOP | Graphics.LEFT;    private static final int TH_ANCHOR = Graphics.TOP | Graphics.HCENTER;    private Image buf;    public static Graphics GRAPHICS;    public static int VDIVIDER;    public static final int BACKGROUND = ThreeDColor.gray.getRGB();    private int nLastState;    private int nLastScore;    private int nLastLives;    private Engine engine;    private EngineState state;    private long last;    private int fps;    private int nFontVoff;    private String strFPS;    private boolean bShowfps;    public Screen() {        int i;        width = getWidth();        height = getHeight();        ftSmall = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,                                  Font.SIZE_SMALL);        ftMedium = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,                                   Font.SIZE_MEDIUM);        ftLarge = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,                                  Font.SIZE_LARGE);        font = height < 150 ? ftSmall : ftMedium;        nFontVoff = font.getHeight();        buf = Image.createImage(width, height - (nFontVoff + 5));        VDIVIDER = buf.getHeight();        GRAPHICS = buf.getGraphics();        state = new EngineState();        nLastState = -1;        nLastScore = -1;        nLastLives = -1;        strFPS = "0";        bShowfps = false;    }    public void setEngine(Engine engine) {        this.engine = engine;    }    public void keyPressed(int keycode) {        engine.keyPressed(keycode, getGameAction(keycode));    }    public void keyReleased(int keycode) {        engine.keyReleased(keycode, getGameAction(keycode));    }    public boolean isShowFPS() {        return bShowfps;    }    public void setShowFPS(boolean x) {        bShowfps = x;    }    /**     * 绘制背景     */    private void paintBackground(Graphics g) {        int i;        g.setColor(BACKGROUND);        g.fillRect(0, 0, width, height);    }    /**     * 绘制标题     */    private void paintTitle(Graphics g) {        engine.getState(state);        if (nLastState != Engine.TITLE) {            paintBackground(GRAPHICS);            state.bricks.paintShadow(GRAPHICS);            state.bricks.paint(GRAPHICS);        }        g.drawImage(buf, 0, 0, TL_ANCHOR);        g.setColor(BACKGROUND);        g.fillRect(0, height - (nFontVoff + 5), width, nFontVoff + 5);        g.setFont(ftLarge);        g.setColor(ThreeDColor.black.getRGB());        g.drawString("PinBall", width / 2 + 1, height / 2 + 20, TH_ANCHOR);        g.setColor(ThreeDColor.red.getRGB());        g.drawString("PinBall", width / 2, height / 2 + 19, TH_ANCHOR);    }    /**     * 绘制游戏结束信息     */    private void paintOver(Graphics g) {        paintBackground(g);        g.setFont(ftLarge);        g.setColor(ThreeDColor.black.getRGB());        g.drawString("Game", width / 2 + 1, height / 2 - 10 + 1, TH_ANCHOR);        g.drawString("Over", width / 2 + 1, height / 2 + 10 + 1, TH_ANCHOR);        g.setColor(ThreeDColor.red.getRGB());        g.drawString("Game", width / 2, height / 2 - 10, TH_ANCHOR);        g.drawString("Over", width / 2, height / 2 + 10, TH_ANCHOR);    }    public void paint(Graphics g) {        boolean bFullRepaint = engine.levelStarted();        engine.getState(state);        g.setFont(font);        if (state.state == Engine.TITLE) {            paintTitle(g);        } else if (state.state == Engine.OVER) {            paintOver(g);        } else {            if (bFullRepaint) {                paintBackground(GRAPHICS);                state.bricks.paintShadow(GRAPHICS);                state.bricks.paint(GRAPHICS);            }            g.drawImage(buf, 0, 0, TL_ANCHOR);            if (state.state == Engine.PLAY) {                if (state.score != nLastScore || bFullRepaint) {                    g.setColor(BACKGROUND);                    g.fillRect(width / 3, height - (nFontVoff + 5),                               width * 2 / 3, nFontVoff + 5);                    g.setColor(ThreeDColor.black.getRGB());                    g.drawString("S: " + state.score, width * 1 / 3 + 1,                                height - (nFontVoff + 3), TL_ANCHOR);                    g.drawString("H: " + state.highscore, width * 2 / 3 + 1,                                 height - (nFontVoff + 3), TL_ANCHOR);                    g.setColor(ThreeDColor.orange.getRGB());                    g.drawString("S: " + state.score, width * 1 / 3,                                 height - (nFontVoff + 5), TL_ANCHOR);                    g.drawString("H: " + state.highscore, width * 2 / 3,                                 height - (nFontVoff + 5), TL_ANCHOR);                }                if (state.lives != nLastLives || bFullRepaint) {                    g.setColor(BACKGROUND);                    g.fillRect(0, height - (nFontVoff + 5), width / 3,                               nFontVoff + 5);                    for (int i = 0; i < state.lives; i++) {                        g.setColor(ThreeDColor.black.getRGB());                        g.fillArc(BrickList.XOFFSET + 1                                  + 3 * Ball.RADIUS * i,                                                         height                                                         - (nFontVoff - 1),                                                         Math.max(4, height / 50),                                                         Math.max(4, height / 50),                                                         0, 360);                        g.setColor(ThreeDColor.red.getRGB());                        g.fillArc(BrickList.XOFFSET + 3 * Ball.RADIUS * i,                                  height - nFontVoff,                                  Math.max(4, height / 50),                                  Math.max(4, height / 50), 0, 360);                    }                }            }            state.ball.paintShadow(g);            state.board.paintShadow(g);            state.ball.paint(g);            state.board.paint(g);        }        if (bShowfps) {            fps++;            long n = System.currentTimeMillis() / 1000;            if (n != last) {                strFPS = "" + fps;                fps = 0;                last = n;            }            g.setColor(0xffffff);            g.drawString(strFPS, 5, 3, TL_ANCHOR);        }        nLastState = state.state;        nLastScore = state.score;        nLastLives = state.lives;    }}

⌨️ 快捷键说明

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