j2me


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

public class Simple extends GameCanvas implements Runnable {

    private volatile boolean mTrucking;
    private long mFrameDelay;
    private int x,  y;
    private int mState;

    public Simple() {
        super(true);
        x = getWidth() / 2;
        y = getHeight() / 2;
        mState = 0;
        mFrameDelay = 20;
    }

    public void start() {
        mTrucking = true;
        Thread t = new Thread(this);
        t.start();
    }

    public void stop() {
        mTrucking = false;
    }

    public void run() {
        Graphics g = getGraphics();

        while (mTrucking == true) {
            tick();
            input();
            draw(g);
            try {
                Thread.sleep(mFrameDelay);
            } catch (InterruptedException ie) {
                stop();
            }
        }
    }

    private void draw(Graphics g) {
        g.setColor(0xffFEE);
        g.fillRect(0, 0, getWidth(), getHeight());

        g.setColor(0x000000);
        g.drawLine(x, y, x - 5 + mState, y - 5);
        g.drawLine(x, y, x + 5, y - 5 + mState);
        g.drawLine(x, y, x + 5 - mState, y + 5);
        g.drawLine(x, y, x - 5, y + 5 - mState);
        g.drawString("游戏",0, 0, Graphics.TOP|Graphics.LEFT);
        g.drawString("游戏",0, 15, Graphics.TOP|Graphics.LEFT);

        flushGraphics();
    }

    private void tick() {
        mState = (mState + 1) % 20;
    }

    private void input() {
        int keyStates = getKeyStates();
        if ((keyStates & LEFT_PRESSED) != 0) {
            x = Math.max(0, x - 2);
        }
        if ((keyStates & RIGHT_PRESSED) != 0) {
            x = Math.min(getWidth(), x + 2);
        }
        if ((keyStates & UP_PRESSED) != 0) {
            y = Math.max(0, y - 2);
        }
        if ((keyStates & DOWN_PRESSED) != 0) {
            y = Math.min(getHeight(), y + 2);
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
贪吃蛇.jar import java.io.IOException; import java.util.Hashtable; import java.util.Vector; import javax.microedition.lcdui.Font; import javax.microedition.lcdui.Graphics; public class DCSnake extends i { private h jdField_a_of_type_H; private h jdField_b_of_type_H; private h jdField_c_of_type_H; private boolean jdField_c_of_type_Boolean; private boolean d; private int jdField_a_of_type_Int; private int jdField_b_of_type_Int; private int jdField_c_of_type_Int; private boolean e; private f jdField_a_of_type_F; private f jdField_b_of_type_F; private f jdField_c_of_type_F; public final void a(int paramInt) { if (!this.jdField_c_of_type_Boolean) { paramInt = this; if (!this.d) { paramInt.jdField_a_of_type_Int = 6; paramInt.jdField_b_of_type_Int = 0; paramInt.d = true; return; } if (paramInt.jdField_b_of_type_Int < paramInt.jdField_a_of_type_Int) { Object localObject1; switch (paramInt.jdField_b_of_type_Int) { case 0: a.a(); break; case 1: this = paramInt; try { localObject1 = null; localObject1 = Font.getFont(32, 0, 8); Font localFont1 = Font.getFont(32, 1, 8); Font localFont2 = Font.getFont(32, 1, 0); this.jdField_a_of_type_F = new f((Font)localObject1, 0, -1); this.jdField_b_of_type_F = new f(localFont1, 16777215, 0); this.jdField_c_of_type_F = new f(localFont2, 16776960, 32768); t.a(this.jdField_c_of_type_F, this.jdField_a_of_type_F, this.jdField_b_of_type_F); } catch (IOException localIOException) { } case 2: localObject1 = a.a(new int[] { 1245188, 1245190, 1245189 }); v[] arrayOfv = a.a(new int[] { 1245191, 1245193, 1245192 }); t.a(new c(localObject1, true), new c(arrayOfv, true)); break;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值